@airtame/translation
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Translation

This package has two purposes:

  1. 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.
  2. 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 function t(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 for update 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 for check and placeholders commands.
  • TRANSLATION_PROJECT_FILES_GLOB - the glob pattern to target project files where to run the check and placeholders 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

Readme

Keywords

Package Sidebar

Install

npm i @airtame/translation

Weekly Downloads

46

Version

1.0.3

License

none

Unpacked Size

21.4 kB

Total Files

17

Last publish

Collaborators

  • rene-airtame
  • airtame-ops