Skip to content

Adding New Text and Updating the Translations

Harel M edited this page Apr 4, 2024 · 16 revisions

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:

  1. Add a new variable to the ResourcesService class in IsraelHiking.Web\sources\application\services\resources.service.ts. Try adding it to the closest related group.
    For example:

    public about: string;
  2. Add an assignment of text to the new variable in the setLanguage method in ResourcesService. Use gettextCatalog with a representative English text to get the language-dependent value for this variable.
    For example:

    this.about = this.gettextCatalog.getString("About");
  3. 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

  1. Open command prompt and change to the IsraelHiking.Web folder.
  2. Run npm install
  3. Run npm run extract to extract the required translations to en-US.json file
  4. You can manually edit the other language files by adding the newly created key and the relevant translation and commit everything to github.
  5. Pushing the changes to github without locally translating will allow to edit the translation in the Crowdin editor.
  6. Once the translation is complete Crowdin will open a PR with the required changed straight to the repo.