i18n.rst 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 LuCI
  14. --------------------
  15. Internationalization support can be found in the ``luci.i18n`` package.
  16. Strings are translated using the ``i18n.translate`` and ``i18n.translatef`` functions
  17. (``translate`` for static strings, ``translatef`` for printf-like formatted string).
  18. Example from the ``gluon-config-mode-geo-location`` package::
  19. local i18n = require "luci.i18n"
  20. o = s:option(cbi.Flag, "_location", i18n.translate("Show node on the map"))
  21. Adding translation templates to Gluon packages
  22. ----------------------------------------------
  23. The i18n support is based on the standard gettext system. For each translatable package,
  24. a translation template with extension ``.pot`` can be created using the ``i18n-scan.pl``
  25. script from the LuCI repository::
  26. cd package/gluon-config-mode-geo-location
  27. mkdir i18n
  28. cd i18n
  29. ../../../packages/luci/build/i18n-scan.pl ../files > gluon-config-mode-geo-location.pot
  30. The entries in the template can be reordered after the generation if desirable. Lots of standard
  31. translations like "Cancel" are already available in the LuCI base translation file (see
  32. ``packages/luci/po/templates/base.pot``) and can be removed from the template.
  33. In addition, some additions to the Makefile must be made. Instead of OpenWrt's default ``package.mk``,
  34. the Gluon version ``$(GLUONDIR)/include/package.mk`` must be used. The i18n files must be installed
  35. and PKG_CONFIG_DEPENDS must be added::
  36. ...
  37. include $(GLUONDIR)/include/package.mk
  38. PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
  39. ...
  40. define Build/Compile
  41. $(call GluonBuildI18N,gluon-config-mode-geo-location,i18n)
  42. endef
  43. define Package/gluon-config-mode-geo-location/install
  44. ...
  45. $(call GluonInstallI18N,gluon-config-mode-geo-location,$(1))
  46. endef
  47. ...
  48. Adding translations
  49. -------------------
  50. A new translation file for a template can be added using the ``msginit`` command::
  51. cd package/gluon-config-mode-geo-location/i18n
  52. msginit -l de
  53. This will create the file ``de.po`` in which the translations can be added.
  54. The translation file can be updated to a new template version using the ``msgmerge`` command::
  55. msgmerge -U de.po gluon-config-mode-geo-location.pot
  56. After the merge, the translation file should be checked for "fuzzy matched" entries where
  57. the original English texts have changed. All entries from the translation file should be
  58. translated in the ``.po`` file (or removed from it, so the original English texts are displayed
  59. instead).
  60. Adding support for new languages
  61. --------------------------------
  62. A list of all languages supported by LuCI can be found in the ``packages/luci/luci.mk`` file after
  63. Gluon's dependencies have been downloaded using ``make update``. Adding translations for these
  64. languages is straightforward using the ``msginit`` command.
  65. For other languages, support must be added to LuCI first, which constitutes completely translating
  66. the ``base.pot``. Please contact the upstream LuCI maintainers at https://github.com/openwrt/luci/
  67. if you'd like to do this.