lion/packages/localize
github-actions[bot] c03ebde5b5 Version Packages
2020-09-30 23:04:53 +02:00
..
_docs feat(form-core): form-core types 2020-09-02 09:02:47 +02:00
docs feat(localize): support google translate 2020-06-08 14:46:33 +02:00
src chore: remove not needed index.d.ts files, minor type improvements 2020-09-15 10:48:34 +02:00
test feat(form-core): form-core types 2020-09-02 09:02:47 +02:00
test-helpers feat(localize): add types to localize 2020-08-03 17:00:26 +02:00
types fix(localize): align on common Intl type and reduce duplicates 2020-09-15 10:48:34 +02:00
CHANGELOG.md Version Packages 2020-09-30 23:04:53 +02:00
index.js fix(input-amount): normalize added for currency label (#618) 2020-03-04 17:33:09 +01:00
package.json Version Packages 2020-09-30 23:04:53 +02:00
README.md chore(localize): add example to readme 2020-06-04 13:41:57 +02:00
test-helpers.js fix: public test-helpers 2019-07-30 15:50:53 +02:00

Localize

export default {
  title: 'Localize/Intro',
};

Is meant to translate text into multiple languages. In it's simplest form it is a function that returns the translated text for a namespace + key.

Features

  • Uses es modules
  • Formatting of numbers, amounts
  • Formatting of dates

Further examples can be seen at Features Overview Demo and a more in depth description can be found at Localize System Overview.

Content

Feature Description
Translate Text Load and translate text in multiple languages
Format Numbers Format numbers in multiple languages
Format Dates Format dates in multiple languages

How to use

Installation

npm i --save @lion/localize
import { localize } from '@lion/localize';

Example

The locale which will be loaded by default is accessed via the localize.locale.

The single source of truth for page's locale is <html lang="my-LOCALE">. At the same time the interaction should happen via localize.locale getter/setter to be able to notify and react to the change.

import { localize } from '@lion/localize.js';

localize.addEventListener('localeChanged', () => {
  // do smth when data is loaded for a new locale
});

// changes locale, syncs to `<html lang="es-ES">` and fires the event above
localize.locale = 'es-ES';