1.0.3 • Published 4 years ago

@kabeleced/webext-i18n v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Build Status

webext-i18n

Encapsulates the access to i18n localised text resources for WebExtensions.

Installation

npm install @kabeleced/webext-i18n

Usage

Assume you have following message.jsonfile in your WebExtension folder _locales/en/messages.json:

{
  "text": {
    "message": "Hello!"
  },
  "text_substitution": {
    "message": "Hello $substitution$!",
    "placeholders": {
      "substitution": { "content": "$1" }
    }
  }
}

Javascript

const I18Text = require('@kabeleced/webext-i18n').I18nText;

const text = new I18nText('text').value();
const textWithSubstitution = new I18nText('text_substitution').value("World");

console.log('Text: ' + text);
console.log('Text with substituion: ' + textWithSubstitution);

The output should be

Text: Hello!
Text with substitution: Hello World!

TypeScript

With TypeScript the usage of the interface II18nText is possible:

import { II18nText, I18nText } from '@kabeleced/webext-i18n';

function printText(text: II18nText, textWithSubstitution: II18nText) {
  console.log('Text: ' + text.value());
  console.log('Text with substituion: ' + textWithSubstitution.value("World"));    
}

printText(new I18nText('text'), new I18nText('text_substitution'));

Output should be

Text: Hello!
Text with substitution: Hello World!

Test

npm run test
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago