You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.4 KiB

4 years ago
  1. # Localization
  2. Etherpad provides a multi-language user interface, that's apart from your users' content, so users from different countries can collaborate on a single document, while still having the user interface displayed in their mother tongue.
  3. ## Translating
  4. We rely on https://translatewiki.net to handle the translation process for us, so if you'd like to help...
  5. 1. Sign up at https://translatewiki.net
  6. 2. Visit our [TWN project page](https://translatewiki.net/wiki/Translating:Etherpad_lite)
  7. 3. Click on `Translate Etherpad lite interface`
  8. 4. Choose a target language, you'd like to translate our interface to, and hit `Fetch`
  9. 5. Start translating!
  10. Translations will be send back to us regularly and will eventually appear in the next release.
  11. ## Implementation
  12. ### Server-side
  13. `/src/locales` contains files for all supported languages which contain the translated strings. Translation files are simple `*.json` files and look like this:
  14. ```json
  15. { "pad.modals.connected": "Connecté."
  16. , "pad.modals.uderdup": "Ouvrir dans une nouvelle fenêtre."
  17. , "pad.toolbar.unindent.title": "Dèsindenter"
  18. , "pad.toolbar.undo.title": "Annuler (Ctrl-Z)"
  19. , "timeslider.pageTitle": "{{appTitle}} Curseur temporel"
  20. , ...
  21. }
  22. ```
  23. Each translation consists of a key (the id of the string that is to be translated) and the translated string. Terms in curly braces must not be touched but left as they are, since they represent a dynamically changing part of the string like a variable. Imagine a message welcoming a user: `Welcome, {{userName}}!` would be translated as `Ahoy, {{userName}}!` in pirate.
  24. ### Client-side
  25. We use a `language` cookie to save your language settings if you change them. If you don't, we autodetect your locale using information from your browser. Then, the preferred language is fed into a library called [html10n.js](https://github.com/marcelklehr/html10n.js), which loads the appropriate translations and applies them to our templates. Its features include translation params, pluralization, include rules and a nice javascript API.
  26. ## Localizing plugins
  27. ### 1. Mark the strings to translate
  28. In the template files of your plugin, change all hardcoded messages/strings...
  29. from:
  30. ```html
  31. <option value="0">Heading 1</option>
  32. ```
  33. to:
  34. ```html
  35. <option data-l10n-id="ep_heading.h1" value="0"></option>
  36. ```
  37. In the javascript files of your plugin, change all hardcoded messages/strings...
  38. from:
  39. ```js
  40. alert ('Chat');
  41. ```
  42. to:
  43. ```js
  44. alert(window._('pad.chat'));
  45. ```
  46. ### 2. Create translate files in the locales directory of your plugin
  47. * The name of the file must be the language code of the language it contains translations for (see [supported lang codes](https://joker-x.github.com/languages4translatewiki/test/); e.g. en ? English, es ? Spanish...)
  48. * The extension of the file must be `.json`
  49. * The default language is English, so your plugin should always provide `en.json`
  50. * In order to avoid naming conflicts, your message keys should start with the name of your plugin followed by a dot (see below)
  51. *ep_your-plugin/locales/en.json*
  52. ```
  53. { "ep_your-plugin.h1": "Heading 1"
  54. }
  55. ```
  56. *ep_your-plugin/locales/es.json*
  57. ```
  58. { "ep_your-plugin.h1": "Título 1"
  59. }
  60. ```
  61. Every time the http server is started, it will auto-detect your messages and merge them automatically with the core messages.
  62. ### Overwrite core messages
  63. You can overwrite Etherpad's core messages in your plugin's locale files.
  64. For example, if you want to replace `Chat` with `Notes`, simply add...
  65. *ep_your-plugin/locales/en.json*
  66. ```
  67. { "ep_your-plugin.h1": "Heading 1"
  68. , "pad.chat": "Notes"
  69. }
  70. ```
  71. ## Customization for Administrators
  72. As an Etherpad administrator, it is possible to overwrite core mesages as well as messages in plugins. These include error messages, labels, and user instructions. Whereas the localization in the source code is in separate files separated by locale, an administrator's custom localizations are in `settings.json` under the `customLocaleStrings` key, with each locale separated by a sub-key underneath.
  73. For example, let's say you want to change the text on the "New Pad" button on Etherpad's home page. If you look in `locales/en.json` (or `locales/en-gb.json`) you'll see the key for this text is `"index.newPad"`. You could add the following to `settings.json`:
  74. ```
  75. "customLocaleStrings": {
  76. "fr": {
  77. "index.newPad": "Créer un document"
  78. },
  79. "en-gb": {
  80. "index.newPad": "Create a document"
  81. },
  82. "en": {
  83. "index.newPad": "Create a document"
  84. }
  85. }
  86. ```