@airtame/translation
v1.0.3
Published
A library to maintain and update translation in ARC projects.
Downloads
3
Readme
Translation
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 ⚠️
character to the placeholder strings ).
Installation
npm install --save-exact @airtame/translation
CLI
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.
Check translations:
translations check|c
Update translations:
translations update|u
Update translations placeholders:
translations placeholders|p
Using inside the application:
// "./src/i18n/i18n.ts"
import t, { setTranslations } from "@airtame/translation";
import en from "../some/path/to/a/file.json";
setTranslations(en);
export default t;
Development
Installation
nvm install
nvm use
npm ci;
Test
npm test;
Build
npm build;
Testing the project
Testing project exported library/contents:
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.
1. Install yalc
Install yalc globally with npm install -g yalc
so that you can use it from the command line.
2. Publish airtame/translation to yalc
In the Airtame UI folder run npm run build && yalc publish
to publish the library in its current state to the local repository.
3. Install airtame/translation from yalc
In your project's folder run yalc add @airtame/translation
to install translation Package
4. Make changes to 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.
5. Clean up after yourself
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.
Test the command line tool scripts
For testing the command line scripts, Yalc does not support this, so we will have to install it locally.
1. Build and pack by running the following command npm run build && npm pack
;
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.
4. In the project package.json file, under the scripts add an entry: "translation": "translation"
5. Run the command npm run translation -- c|u|p
to test the command line scripts.
Releasing a new version:
npm version minor