@intl-schematic/plugin-locale
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.7 • Public • Published

@intl-schematic/plugin-locale

A provider-plugin, doesn't affect the translation process directly, but allows other plugins to use a user-provided Intl.Locale instance, using the plugins API.

npm i -s @intl-schematic/plugin-locale

import { createTranslator } from 'intl-schematic';
import { LocaleProviderPlugin } from '@intl-schematic/plugin-locale';

const getUserLocale = () => new Intl.Locale(navigator.language);

// Notice the plugins array parameter
const t = createTranslator(getDocument, [
  LocaleProviderPlugin(getUserLocale),
  // ... all plugins supplied here
  // can now use `this.plugins.Locale.info()`
  // to access the user locale
]);

Then, in another plugin:

import { createPlugin } from 'intl-schematic/plugins';

// This import tells typescript that your plugin requires
// the locale plugin to work properly
import type {} from '@intl-schematic/plugin-locale';

const MyPlugin = createPlugin('MyPlugin', () => false, {
  translate() {
    const locale = this.plugins.Locale.info();

    // use the Intl.Locale
    console.log(locale.baseName);

    return 'my plugin translation';
  }
})

Package Sidebar

Install

npm i @intl-schematic/plugin-locale

Weekly Downloads

19

Version

1.0.0-rc.7

License

MIT

Unpacked Size

6.97 kB

Total Files

9

Last publish

Collaborators

  • raiondesu