i18n.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Internationalization support
  2. ============================
  3. General guidelines
  4. ------------------
  5. * All config mode packages must be fully translatable, with complete English and German texts.
  6. * All new expert mode packages must be fully translatable. English texts are required.
  7. * German translations are recommended. Other supported languages, especially French, are
  8. nice-to-have, but not required. If you don't know a language well, rather leave the translation
  9. blank, so it is obvious that there is no proper translation yet.
  10. * Existing expert mode packages should be made translatable as soon as possible.
  11. * The "message IDs" (which are the arguments to the *translate* function) should be the
  12. English texts.
  13. i18n support in Gluon
  14. ---------------------
  15. Internationalization support is available in all components (models, view and
  16. controllers) of *gluon-web*-based packages. Strings are translated using the *translate*,
  17. *_translate* and *translatef* functions (*translate* for static strings, *translatef*
  18. for printf-like formatted string; *_translate* works the same as *translate*, but
  19. will return *nil* instead of the original string when no translation is available).
  20. In views, the special tags ``<%:...%>`` can be used to translate the contained string.
  21. Example from the *gluon-config-mode-geo-location* package:
  22. .. code-block:: lua
  23. local share_location = s:option(Flag, "location", translate("Show node on the map"))
  24. Note that translations are *namespaced*: each package will only use its own
  25. translation strings by default. For this purpose, the package name must by
  26. specified in a package's controller. It is possible to access a different
  27. translation package using the *i18n* function from models and view, which is
  28. necessary when strings from the site configuration are used, or packages do not
  29. have their own controller (which is the case for config mode wizard components).
  30. .. code-block:: lua
  31. local site_i18n = i18n 'gluon-site'
  32. local msg = site_i18n._translate('gluon-config-mode:welcome')
  33. Adding translation templates to Gluon packages
  34. ----------------------------------------------
  35. The i18n support is based on the standard gettext system. For each translatable package,
  36. a translation template with extension ``.pot`` can be created using the *i18n-scan.pl*
  37. script in the ``contrib`` directory:
  38. .. code-block:: sh
  39. cd package/gluon-web-mesh-vpn-fastd
  40. mkdir i18n
  41. cd i18n
  42. ../../../contrib/i18n-scan.pl ../files ../luasrc > gluon-web-mesh-vpn-fastd.pot
  43. The same command can be run again to update the template.
  44. In addition, the Makefile must be adjusted. Instead of LEDE's default *package.mk*,
  45. the Gluon version (``../gluon.mk`` for core packages) must be used. The i18n files must be installed
  46. and PKG_CONFIG_DEPENDS must be added::
  47. ...
  48. include ../gluon.mk
  49. PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
  50. ...
  51. define Build/Compile
  52. $(call GluonBuildI18N,gluon-web-mesh-vpn-fastd,i18n)
  53. endef
  54. define Package/gluon-web-mesh-vpn-fastd/install
  55. ...
  56. $(call GluonInstallI18N,gluon-web-mesh-vpn-fastd,$(1))
  57. endef
  58. ...
  59. Adding translations
  60. -------------------
  61. A new translation file for a template can be added using the *msginit* command:
  62. .. code-block:: sh
  63. cd package/gluon-web-mesh-vpn-fastd/i18n
  64. msginit -l de
  65. This will create the file *de.po* in which the translations can be added.
  66. The translation file can be updated to a new template version using the *msgmerge* command:
  67. .. code-block:: sh
  68. msgmerge -U de.po gluon-web-mesh-vpn-fastd.pot
  69. After the merge, the translation file should be checked for "fuzzy matched" entries where
  70. the original English texts have changed. All entries from the translation file should be
  71. translated in the *.po* file (or removed from it, so the original English texts are displayed
  72. instead).
  73. Adding support for new languages
  74. --------------------------------
  75. A list of all languages supported by *gluon-web* can be found in ``package/gluon.mk``.
  76. New languages just need to be added to *GLUON_SUPPORTED_LANGS*, and a human-readable
  77. language name must be defined.