2
0

translations.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .. raw:: html
  2. <div id="banner"><a href="https://github.com/jcbrand/converse.js/blob/master/docs/source/translations.rst">Edit me on GitHub</a></div>
  3. ============
  4. Translations
  5. ============
  6. Converse supports localization of its user interface and date formats. As
  7. of writing, 46 languages are supported.
  8. The translations of Converse can be found in the `src/i18n <https://github.com/conversejs/converse.js/tree/master/src/i18n/>`_ directory.
  9. Translations of Converse are very welcome. You can add translations either
  10. manually by editing the ``.po`` files in the ``src/i18n/locales``
  11. directory, or through the web at `weblate <https://hosted.weblate.org/projects/conversejs/#languages>`_.
  12. As of version 3.3.0, Converse no longer automatically bundles translations
  13. in its source file and instead fetches only the relevant locale for the current
  14. session from a URL as specified by the :ref:`assets_path` setting.
  15. There are three configuration settings relevant to translations and
  16. localisation. You're encouraged to read the documentation for each of them.
  17. * :ref:`i18n`
  18. * :ref:`locales`
  19. * :ref:`assets_path`
  20. Manually updating translations
  21. ==============================
  22. If you simply want to add a few missing translations, then consider doing it
  23. through the web at `weblate <https://hosted.weblate.org/projects/conversejs/#languages>`_.
  24. Some things however cannot be done via weblate and instead have to be done
  25. manually in a checkout of the Converse source repository.
  26. These tasks are documented below.
  27. Updating the global translations template (.pot file)
  28. -----------------------------------------------------
  29. The gettext `.pot` file located in
  30. `./locale/converse.pot <https://github.com/conversejs/converse.js/blob/master/src/i18n/converse.pot>`_
  31. is the template containing all translations and from which for each language an individual PO
  32. file is generated.
  33. The `.pot` file contains all translateable strings extracted from Converse.
  34. To make a user-facing string is translateable, wrap it in the double underscore helper
  35. function like so:
  36. .. code-block:: javascript
  37. const { __ } = _converse.i18n.env;
  38. const str = __('This string will be translated at runtime');
  39. After adding the string, you'll need to regenerate the POT file:
  40. ::
  41. make pot
  42. Making translations file for a new language
  43. -------------------------------------------
  44. To create a new translations file for a language in which Converse is not yet
  45. translated into, do the following
  46. .. note:: In this example we use Polish (pl), you need to substitute 'pl' to your own language's code.
  47. ::
  48. mkdir -p ./src/i18n/locales/pl/LC_MESSAGES
  49. msginit -i ./src/i18n/converse.pot -o ./src/i18n/locales/pl/LC_MESSAGES/converse.po -l pl
  50. Please make sure to add the following attributes at the top of the file (under
  51. *Content-Transfer-Encoding*). They are required as configuration settings for Jed,
  52. the JavaScript translations library that we're using.
  53. .. code-block:: po
  54. "domain: converse\n"
  55. "lang: pl\n"
  56. "Content-Type: text/plain; charset=UTF-8\n"
  57. "plural_forms: nplurals=2; plural=(n != 1);\n"
  58. Updating an existing translations file
  59. --------------------------------------
  60. You can update the `.po` file for a specific language by doing the following:
  61. .. note:: In this example we use German (de), you need to substitute 'de' to your own language's code.
  62. ::
  63. msgmerge ./src/i18n/locales/de/LC_MESSAGES/converse.po ./src/i18n/converse.pot -U
  64. To do this for ALL languages, run:
  65. ::
  66. make po
  67. The resulting `.po` file is then what gets translated.