Skip to content

Internationalize an element with `lang`, `dir`, and `style.writingMode` as specified

License

Notifications You must be signed in to change notification settings

brettz9/i18nizeElement

Repository files navigation

npm Dependencies devDependencies

Actions Status Actions Status

Known Vulnerabilities Total Alerts Code Quality: Javascript

License

i18nizeElement

Internationalize an element with lang, dir, and style.writingMode as indicated by the supplied language and settings.

Installation

npm install i18nizeelement

Usage

import i18nizeElement from 'i18nizeelement';

i18nizeElement(document.querySelector('html'), {
  language: 'en-US',
  // Optional (Defaults shown below)
  avoidLangIfSet: true,
  avoidDirIfSet: true,
  avoidLTRByDefault: true
});

Usage (as a jamilih plugin)

import {jml, body} from 'jamilih';
import i18nizeElement from
  'i18nizeelement/dist/i18nizeelement-jamilih-plugin.js';

const options = {$plugins: [i18nizeElement]};
const j = jml.bind(null, options);

j('div', {id: 'myDiv', $_language: {
  language: 'en-US',
  // Optional (Defaults shown below)
  avoidLangIfSet: true,
  avoidDirIfSet: true,
  avoidLTRByDefault: true
}}, body);

// An alternative API is:
j('div', {id: 'myDiv', $_language: [
  'en-US' /* , optionalOptionsObjectHere */
]});

// If options are not needed you can use this format:
j('div', {id: 'myDiv', $_language: 'en-US'}, body);

Please note that this plugin suffers from one limitation: The $_language settings will only be visible on the element (e.g., lang and dir) after a Promise microtask. This is because Jamilih at present processes attributes and properties on elements before appending them to their parent, and i18nizeElement defines settings which depend on the element's intended ancestors being present.

See also

License

  • MIT

About

Internationalize an element with `lang`, `dir`, and `style.writingMode` as specified

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •