i18n.rst 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. contrllers) of *gluon-web*-based packages. Strings are translated using the *translate*
  17. and *translatef* functions (*translate* for static strings, *translatef*
  18. for printf-like formatted string); in views, the special tags ``<%:...%>`` can
  19. be used to translate the contained string.
  20. Example from the *gluon-config-mode-geo-location* package:
  21. .. code-block:: lua
  22. local share_location = s:option(Flag, "location", translate("Show node on the map"))
  23. Adding translation templates to Gluon packages
  24. ----------------------------------------------
  25. The i18n support is based on the standard gettext system. For each translatable package,
  26. a translation template with extension ``.pot`` can be created using the *i18n-scan.pl*
  27. script in the ``contrib`` directory:
  28. .. code-block:: sh
  29. cd package/gluon-web-mesh-vpn-fastd
  30. mkdir i18n
  31. cd i18n
  32. ../../../contrib/i18n-scan.pl ../files ../luasrc > gluon-web-mesh-vpn-fastd.pot
  33. The same command can be run again to update the template.
  34. In addition, some additions to the Makefile must be made. Instead of LEDE's default *package.mk*,
  35. the Gluon version (``../gluon.mk`` for core packages) must be used. The i18n files must be installed
  36. and PKG_CONFIG_DEPENDS must be added::
  37. ...
  38. include ../gluon.mk
  39. PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
  40. ...
  41. define Build/Compile
  42. $(call GluonBuildI18N,gluon-web-mesh-vpn-fastd,i18n)
  43. endef
  44. define Package/gluon-web-mesh-vpn-fastd/install
  45. ...
  46. $(call GluonInstallI18N,gluon-web-mesh-vpn-fastd,$(1))
  47. endef
  48. ...
  49. Adding translations
  50. -------------------
  51. A new translation file for a template can be added using the *msginit* command:
  52. .. code-block:: sh
  53. cd package/gluon-web-mesh-vpn-fastd/i18n
  54. msginit -l de
  55. This will create the file *de.po* in which the translations can be added.
  56. The translation file can be updated to a new template version using the *msgmerge* command:
  57. .. code-block:: sh
  58. msgmerge -U de.po gluon-web-mesh-vpn-fastd.pot
  59. After the merge, the translation file should be checked for "fuzzy matched" entries where
  60. the original English texts have changed. All entries from the translation file should be
  61. translated in the *.po* file (or removed from it, so the original English texts are displayed
  62. instead).
  63. Adding support for new languages
  64. --------------------------------
  65. A list of all languages supported by *gluon-web* can be found in ``package/gluon.mk``.
  66. New languages just need to be added to *GLUON_SUPPORTED_LANGS*, after a human-readable
  67. language name has been defined in the same file.