@siemens/element-translate-ng¶
Element Translate¶
element-translate-ng
is a translation abstraction layer. It can be used with
ngx-translate
- Angular localize
- Other frameworks in the future
See here for details how it works and how to use it.
Usage¶
Install the library as follows:
npm install --save @siemens/element-translate-ng
An important part of the library is the extraction of translatable keys as a TypeScript interface as well as extracting a JSON messages file with default translations. The extraction happens on compiled files. I.e. make sure to run the build first. Then, to run these extractions
npx update-translatable-keys
By default, this will pick of the configuration from a file element-translate.conf.json
. To use a different config file, pass as the only argument to the command.
The config file looks like this
{
"files": "dist/@simpl/**/fesm2022/**/*.mjs",
"configs": [
{
"name": "element",
"locationPrefix": "projects/element-ng",
"keysFile": "projects/element-ng/translate/si-translatable-keys.interface.ts",
"keysInterfaceName": "SiTranslatableKeys",
"messagesFile": "dist/@siemens/element-ng/template-i18n.json"
}
]
}
files
is a glob pattern for defining the files to scanconfigs
is an array of configs. For mono-repos building multiple libraries, they can be separated into different configs. All keys are required:name
is a unique namelocationsPrefix
defines the path prefix of the source files, important to distinguish between different libraries in a mono-repokeysFile
defines the path of the generated TypeScript interfaces filekeysInterfaceName
defines the name of the TypeScriptinterface
messagesFile
defines the path of the generated messages JSON file
Testing¶
Run npm run translate:test
to perform the unit tests via Karma. You can set a seed for running the tests in a specific using an environment variable: SEED=71384 npm run translate:test
License¶
The following applies for code and documentation of the git repository, unless explicitly mentioned.
Copyright (c) Siemens 2016 - 2025
MIT, see LICENSE.md.
Except where otherwise noted, content on this site is licensed under MIT License.