JSPM

tlabels

1.2.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q18413F
  • License ISC

Translate UI Labels

Package Exports

  • tlabels
  • tlabels/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tlabels) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Translated Labels (TLBS)

Get custom translations to your app easily!

Installation and Initialization

Use npm i tlabels to install.

Then, in your code, import the module.

import tLabels from 'tlabels';

Next, initialize the instance with the default language and the path to the labels file (If not exist, it will be created).

const labels = tLabels('en', 'path/to/save/files/json');

Now you can use the instance to get the labels.

Usage guide

  • To CREATE or EDIT a label, use the method setLabel passing the label name, the label value and the language to use (optional, default is the default language that you set in the initialization).
// Create a label in the default language
await labels.setLabel('hello_world', 'hello world');

// Create a label in a specific language
await labels.setLabel('hello_world', 'hello world', 'en');
  • To GET a specific label value, use the method getLabel passing the label name and the language to use (optional).
// Get the label value in the default language
let label = await labels.getLabel('hello_world');

// Get the label value in a specific language
let label = await labels.getLabel('hello_world', 'pt');
  • To DELETE one label use the method deleteLabel passing just the label name.
await labels.deleteLabel('hello_world');
  • To check if a label EXIST, use the method exist passing the label name.
let labelExist = await labels.exist('hello_world');
  • To get CURRENT LANGUAGE use the method getCurrentLanguage without parameters (is not async).
let language = labels.getCurrentLanguage();
  • To CHANGE LANGUAGE use the method setCurrentLanguage passing the language to use (is not async).
labels.getCurrentLanguage('es');

Notes

  • The name of the labels must be unique, if you try to create a label with the same name in the same language, the value will be updated.

  • The labels key must be in the format snake case. Ex: label_name. If you try to create a label with a key in another format, the key will be converted to snake case.

  • If you try to get a label that does not exist, the method getLabel will return the label name.

  • If you remoove a label, the label will be removed from all languages.