Make customized translations more maintainable
This commit is contained in:
@@ -6,11 +6,11 @@ If you don't have Cryptpad installed locally, start by following the steps in th
|
||||
|
||||
## Getting started
|
||||
|
||||
Once everything is working, copy the default (English) source file (`/customize.dist/translations/messages.js`) to a file named according to your language's [ISO 639-1 Code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes), like `/customize.dist/translations/messages.fr.js`.
|
||||
Once everything is working, copy the default (English) source file (`/www/common/translations/messages.js`) to a file named according to your language's [ISO 639-1 Code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes), like `/www/common/translations/messages.fr.js`.
|
||||
There is no ISO 639-1 language code for _English-pirate_, so we'll just call it `messages.pirate.js`.
|
||||
|
||||
```Bash
|
||||
cd /customize.dist/translations/
|
||||
cd www/common/translations/
|
||||
cp messages.js messages.pirate.js
|
||||
```
|
||||
|
||||
@@ -21,21 +21,17 @@ There are comments indicating what to modify in three places:
|
||||
|
||||
```javascript
|
||||
(function () {
|
||||
var LS_LANG = "CRYPTPAD_LANG";
|
||||
|
||||
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
|
||||
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
|
||||
var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
|
||||
var language = getLanguage();
|
||||
|
||||
// add your module to this map so it gets used
|
||||
// please use the translated name of your language ("Français" and not "French"
|
||||
// please use the translated name of your language ("Français" and not "French")
|
||||
var map = {
|
||||
'fr': 'Français',
|
||||
'es': 'Español',
|
||||
'pl': 'Polski',
|
||||
'de': 'Deutsch',
|
||||
'pt-br': 'Português do Brasil'
|
||||
'pt-br': 'Português do Brasil',
|
||||
'ro': 'Română',
|
||||
'zh': '繁體中文',
|
||||
'el': 'Ελληνικά',
|
||||
};
|
||||
```
|
||||
|
||||
@@ -43,31 +39,45 @@ We need to modify that map to include our translation:
|
||||
|
||||
```javascript
|
||||
(function () {
|
||||
var LS_LANG = "CRYPTPAD_LANG";
|
||||
|
||||
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
|
||||
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
|
||||
var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
|
||||
var language = getLanguage();
|
||||
|
||||
// add your module to this map so it gets used
|
||||
// please use the translated name of your language ("Français" and not "French"
|
||||
// please use the translated name of your language ("Français" and not "French")
|
||||
var map = {
|
||||
'fr': 'Français',
|
||||
'es': 'Español',
|
||||
'pl': 'Polski',
|
||||
'de': 'Deutsch',
|
||||
'pt-br': 'Português do Brasil'
|
||||
'pt-br': 'Português do Brasil',
|
||||
'ro': 'Română',
|
||||
'zh': '繁體中文',
|
||||
'el': 'Ελληνικά',
|
||||
'pirate': 'English Pirate', // add our module to the map of languages
|
||||
};
|
||||
```
|
||||
|
||||
Just add your module in a similar fashion to the existing translations, save your changes, and close `/customize.dist/messages.js`.
|
||||
|
||||
|
||||
You also need to add a customizable version of you translation. To do so, make a copy of the file `/customize.dist/translations/messages.js` with your translation name (`messages.pirate.js` in our case), and change its content to load the correct language file:
|
||||
|
||||
```javascript
|
||||
/*
|
||||
* You can override the translation text using this file.
|
||||
* The recommended method is to make a copy of this file (/customize.dist/translations/messages.{LANG}.js)
|
||||
in a 'customize' directory (/customize/translations/messages.{LANG}.js).
|
||||
* If you want to check all the existing translation keys, you can open the internal language file
|
||||
but you should not change it directly (/common/translations/messages.{LANG}.js)
|
||||
*/
|
||||
define(['/common/translations/messages.pirate.js'], function (Messages) { // Change the file name here
|
||||
// Replace the existing keys (in your copied file) here:
|
||||
// Messages.button_newpad = "New Rich Text Document";
|
||||
return Messages;
|
||||
});
|
||||
```
|
||||
|
||||
That's all!
|
||||
|
||||
## Actually translating content
|
||||
|
||||
Now we can go back to our file, `/customize.dist/translations/messages.pirate.js` and start to add our Pirate-language customizations.
|
||||
Now we can go back to our file, `/www/common/translations/messages.pirate.js` and start to add our Pirate-language customizations.
|
||||
|
||||
Open the translation file you created in `/customize.dist/translations/`.
|
||||
You should see something like:
|
||||
@@ -115,5 +125,5 @@ We're happy to help.
|
||||
When a key is nolonger used (such as presentSuccess) you can delete it using this bash one-liner.
|
||||
|
||||
```shell
|
||||
( export KEY=presentSuccess && grep -nr "$KEY" ./customize.dist/translations/ | sed 's/:.*$//' | while read x; do sed -i -e "/out\.$KEY =/d" $x; done )
|
||||
```
|
||||
( export KEY=presentSuccess && grep -nr "$KEY" ./www/common/translations/ | sed 's/:.*$//' | while read x; do sed -i -e "/out\.$KEY =/d" $x; done )
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user