From 6a29d8aa8aae8088ceda0f07cec0a4a9a86ee290 Mon Sep 17 00:00:00 2001 From: qa46hx Date: Thu, 4 Jun 2020 13:41:57 +0200 Subject: [PATCH] chore(localize): add example to readme --- packages/localize/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/localize/README.md b/packages/localize/README.md index a254d5d99..eda3fb44e 100644 --- a/packages/localize/README.md +++ b/packages/localize/README.md @@ -38,3 +38,21 @@ npm i --save @lion/localize ```js 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 ``. +At the same time the interaction should happen via `localize.locale` getter/setter to be able to notify and react to the change. + +```js +import { localize } from '@lion/localize.js'; + +localize.addEventListener('localeChanged', () => { + // do smth when data is loaded for a new locale +}); + +// changes locale, syncs to `` and fires the event above +localize.locale = 'es-ES'; +```