translations.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ============
  2. Translations
  3. ============
  4. .. contents:: Table of Contents
  5. :depth: 2
  6. :local:
  7. .. note::
  8. Translations take up a lot of space and will bloat your minified file.
  9. At the time of writing, all the translations add about 50KB of extra data to
  10. the minified javascript file. Therefore, make sure to only
  11. include those languages which you intend to support and remove from
  12. ./src/locales.js those which you don't need. Remember to rebuild the
  13. minified file afterwards, by running `make build`.
  14. ----------------------------------------------
  15. Updating the translations template (.pot file)
  16. ----------------------------------------------
  17. The gettext `.pot` file located in
  18. `./locale/converse.pot <https://github.com/jcbrand/converse.js/blob/master/locale/converse.pot>`_
  19. is the template containing all translations and from which for each language an individual PO
  20. file is generated.
  21. The `.pot` file contains all translateable strings extracted from converse.js.
  22. To make a user-facing string translateable, wrap it in the double underscore helper
  23. function like so:
  24. .. code-block:: javascript
  25. __('This string will be translated at runtime');
  26. After adding the string, you'll need to regenerate the POT file:
  27. ::
  28. make pot
  29. -------------------------------------------
  30. Making translations file for a new language
  31. -------------------------------------------
  32. To create a new translations file for a language in which converse.js is not yet
  33. translated into, do the following
  34. .. note:: In this example we use Polish (pl), you need to substitute 'pl' to your own language's code.
  35. ::
  36. mkdir -p ./locale/pl/LC_MESSAGES
  37. msginit -i ./locale/converse.pot -o ./locale/pl/LC_MESSAGES/converse.po -l pl
  38. Please make sure to add the following attributes at the top of the file (under
  39. *Content-Transfer-Encoding*). They are required as configuration settings for Jed,
  40. the Javascript translations library that we're using.
  41. .. code-block:: po
  42. "domain: converse\n"
  43. "lang: pl\n"
  44. "Content-Type: text/plain; charset=UTF-8\n"
  45. "plural_forms: nplurals=2; plural=(n != 1);\n"
  46. --------------------------------------
  47. Updating an existing translations file
  48. --------------------------------------
  49. You can update the `.po` file for a specific language by doing the following:
  50. .. note:: In this example we use German (de), you need to substitute 'de' to your own language's code.
  51. ::
  52. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  53. To do this for ALL languages, run:
  54. ::
  55. make po
  56. The resulting `.po` file is then what gets translated.
  57. -----------------------------------------------------
  58. Generating a Javascript file from a translations file
  59. -----------------------------------------------------
  60. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_, which we use for
  61. translations in converse.js cannot use the `.po` files directly. We have
  62. to generate from it a file in JSON format and then put that in a `.js` file
  63. for the specific language.
  64. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  65. following command to install it (npm being the node.js package manager):
  66. ::
  67. npm install po2json
  68. You can then convert the translations into JSON format:
  69. ::
  70. po2json -p -f jed -d converse locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  71. To do this for ALL languages, run:
  72. ::
  73. make po2json
  74. .. note::
  75. If you are adding translations for a new language that is not already supported,
  76. you'll have to add the language path in main.js and make one more edit in ./src/locales.js
  77. to make sure the language is loaded by require.js.