-
Notifications
You must be signed in to change notification settings - Fork 33
Adding New Text and Updating the Translations
In order to enable translation of the site to different languages, text that appears on the screen should never be hard coded.
The following steps are required for every new text:
-
Add a new variable to the
ResourcesService
class inIsraelHiking.Web\sources\application\services\resources.service.ts
. Try adding it to the closest related group.
For example:public about: string;
-
Add an assignment of text to the new variable in the
setLanguage
method inResourcesService
. UsegettextCatalog
with a representative English text to get the language-dependent value for this variable.
For example:this.about = this.gettextCatalog.getString("About");
-
Use this variable rather than the text itself in the code.
For example, using angular in an HTML file:{{resources.about}}
or in TypeScript:
toastService.error(this.resources.about);
Important Note: Make sure you have a secrets.json file that contains the following fields (See the readme on how to find/open the file):
{
...
"zanataUserName": "your-zanata-user-name",
"zanataApiKey": "api-key-from-zanata"
}
-
Open command prompt and change to the
IsraelHiking.Web
folder. -
Run
npm install
-
Run
npm run 1-upload
. After extracting the translations and uploading an updated pot file to the IsraelHiking Zanata project. -
Your browser will show two new tabs containing the untranslated words in Hebrew and English.
-
Translate the remaining phrases in both languages and save each one with Ctrl-Enter.
-
You may also improve the existing translations by clearing the "Incomplete" checkbox. Specific phrases can be found using the search box.
-
When translation is complete type
npm run 2-download
- this will download the needed files and convert them to JSON. -
Commit the translation files to Github (
IsraelHiking.pot
,he.json
, anden-US.json
in tehIsraelHiking.Web\sources\translations
folder).
This is mainly for documentation or in case the upload of the pot file fails for some reason. It shouldn't be done when everything is working as expected.
-
Go to the project Setting page on Zanata, login if needed, open the "Documents" list,
-
Add the updated
IsraelHiking.Web\translations\IsraelHiking.pot
file,and upload it.
-
The new texts can now be translated using Zanata UI. You may want to select the Incomplete checkbox to view just that texts that were not translated yet.
-
Follow the instructions above to complete the translation and updates.