Socket
Socket
Sign inDemoInstall

@bity/i18n

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bity/i18n

This i18n package was written because all other i18n solutions seem to be overly complicated. `@bity/i18n` is a single function, that uses `window.i18n` to store and access all translations, in a simple key-value manner.


Version published
Maintainers
3
Created
Source

@bity/i18n - Internationalization

This i18n package was written because all other i18n solutions seem to be overly complicated. @bity/i18n is a single function, that uses window.i18n to store and access all translations, in a simple key-value manner.

This allows the JavaScript execution environment to always have access to your translations.

Usage

npm install @bity/i18n

import { t } from '@bity/i18n';

function t(stringToTranslate, alternativeTranslationMap) {
  /* Returns the original string or a translated string */
}

Self-explanatory :)

If you want to use this package with nodejs, simply define a bare window object: global.window = { i18n: { } };

Examples

Single language translations

import { t } from '@bity/i18n';

window.i18n = {
  'Hello': 'Bonjour',
  'Good morning': 'Bon matin',
  'You\'re welcome': 'Bienvenue'
};

console.log(`${t('Hello')} Tim`);

In the case where there is no translation, it'll use the original text passed.

Multiple language translations

In the instance you need to translate to many different languages on the same page, you can do the following:

import { t } from '@bity/i18n';

window.i18n = {
  fr: {
    'Hello': 'Boujor'
  },
  de: {
    'Hello': 'Guten morgen'
  }
};

console.log(`${t('Hello', window.i18n.de)} Tim`);

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc