JSPM

  • Created
  • Published
  • Downloads 426
  • Score
    100M100P100Q92352F
  • License MIT

Tree shakable dictionary for e-commerce JS apps

Package Exports

  • @ecomplus/i18n

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ecomplus/i18n) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

i18n

npm version license mit

Tree shakable dictionary for e-commerce JS apps

Getting started

npm i --save @ecomplus/i18n

Usage

import { Hello, Visitor } from '@ecomplus/i18n'
console.log(`${Hello.en_us} ${Visitor.pt_br}`)
// Hello Visitor
console.log(`${Hello.pt_br} ${Visitor.pt_br}`)
// Olá Visitante

We recommend using it with ecomUtils.i18n:

import { i18n } from '@ecomplus/utils'
import { Hello, Visitor } from '@ecomplus/i18n'
console.log(`${i18n(Hello)} ${i18n(Visitor)}`)
// Hello Visitor

Change current language with ecomUtils._config:

import { _config, i18n } from '@ecomplus/utils'
import { Hello, Visitor } from '@ecomplus/i18n'
_config.set('lang', 'pt_br')
console.log(`${i18n(Hello)} ${i18n(Visitor)}`)
// Olá Visitante

Import entire dictionary object

It'll output large size bundle, not good for frontend apps.

import dictionary from '@ecomplus/i18n'
console.log(`${dictionary.Hello.en_us} ${dictionary.Visitor.en_us}`)
// Hello Visitor

Webpack alias

You can import only one language variation using Webpack resolve.alias as following:

// webpack.config.js
module.exports = {
  //...
  resolve: {
    alias: {
      '@ecomplus/i18n$': `@ecomplus/i18n/dist/i18n.${lang}.min.js`
    }
  }
}

By this way you'll import only strings instead of objects:

import { Hello, Visitor } from '@ecomplus/i18n'
console.log(`${Hello} ${Visitor}`)
// Hello Visitor

You can still use ecomUtils.i18n the same way:

import { i18n } from '@ecomplus/utils'
import { Hello, Visitor } from '@ecomplus/i18n'
console.log(`${i18n(Hello)} ${i18n(Visitor)}`)
// Hello Visitor