Adding New Text and Updating the Translations - IsraelHikingMap/Site GitHub Wiki
Add a new language
In order to add a new language the following changes need to be made:
- Add the language to the list of languages in
planet-search
- Update the languages array on the server side -
strings.cs
- Update the languages array on the client side -
initial-state.ts
- Upload a
lang.json
file for the relevant language - Add the relevant language and translation to Google and Apple stores
Example PR can be found here: https://github.com/IsraelHikingMap/Site/pull/2120
Adding new text to the site
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);
Translate in Cowdin or locally
- Open command prompt and change to the
IsraelHiking.Web
folder. - Run
npm install
- Run
npm run extract
to extract the required translations to en-US.json file - You can manually edit the other language files by adding the newly created key and the relevant translation and commit everything to github.
- Pushing the changes to github without locally translating will allow to edit the translation in the Crowdin editor.
- Once the translation is complete Crowdin will open a PR with the required changed straight to the repo.