This package has two purposes:
- A CLI tool
translation check|update|placeholders
to check the current translations, run updates on existing translation or to update the placeholders with values from the translation file. - Expose for consumers two function. The first one is
setTranslations(translationObject)
used to populate the translations the package has access to. The second one is the default exported functiont(label, placeholder, parametersObject)
that is meant to match a label to a translation from provided translation object, or populate that translation with the placeholder or label provided by the function caller.
The exposed function for the consumer will take note of NODE_ENV used
and for any values other than production
it will "highlight" missing
translation directly into the application. ( It mainly prepends
npm install --save-exact @airtame/translation
translations check|update|placeholders
or
translation c|u|p
Following environment variables will be used with the CLI command tool:
-
TRANSLATION_API_KEY
(required) - Auth token value to call localise.biz api with. -
TRANSLATION_FILE
(required forupdate
command, optional for the others) - the location of the main english translation json file. It defaults to the location of the file in the arc project forcheck
andplaceholders
commands. -
TRANSLATION_PROJECT_FILES_GLOB
- the glob pattern to target project files where to run thecheck
andplaceholders
scripts against. It defaults to./src/**/*.{ts,tsx}
value. -
TRANSLATION_IGNORE_PROJECT_FILES_GLOB
- the glob pattern to ignore files matched by previous mentioned glob (TRANSLATION_PROJECT_FILES_GLOB
). It defaults to**/*.stories.tsx
value.
translations check|c
translations update|u
translations placeholders|p
// "./src/i18n/i18n.ts"
import t, { setTranslations } from "@airtame/translation";
import en from "../some/path/to/a/file.json";
setTranslations(en);
export default t;
nvm install
nvm use
npm ci;
npm test;
npm build;
For testing the exported functions in a project, in order to avoid having to publish new releases for every checked change to the library we can use Yalc to create a local repository.
Install yalc globally with npm install -g yalc
so that you can use it from the command line.
In the Airtame UI folder run npm run build && yalc publish
to publish the library in its current state to the local repository.
In your project's folder run yalc add @airtame/translation
to install translation Package
After making changes to the library, update the local repository with npm run build && yalc push
. The dependency will be automatically updated in the project.
When you're done, remove the package with yalc remove @airtame/translation
. This will remove the local dependency and restore the original from the internal package repository.
For testing the command line scripts, Yalc does not support this, so we will have to install it locally.
2. Copy the ABSOLUTE path of the newly created .tgz
file ( For exmaple, the absolute path is /Users/broscaru/airtame/translation/airtame-translation-0.0.0.tgz
; We copy this to clipboard ).
3. In the project you wish to test out the CLI tool, we go in and install the package by providing the absolute path npm install /Users/broscaru/airtame/translation/airtame-translation-0.0.0.tgz
to the npm install command.
npm version minor