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
🇧🇷 🇺🇸
Tree shakable dictionary for e-commerce JS apps
i18n~i19~ Internationalization
Getting started
npm i --save @ecomplus/i18nUsage
import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i19hello.en_us} ${i19visitor.pt_br}`)
// Hello Visitor
console.log(`${i19hello.pt_br} ${i19visitor.pt_br}`)
// Olá VisitanteWe recommend using it with
ecomUtils.i18n:
import { i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Hello VisitorChange current language with ecomUtils._config:
import { _config, i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
_config.set('lang', 'pt_br')
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Olá VisitanteImport entire dictionary object
It'll output large size bundle, not good for frontend apps.
import dictionary from '@ecomplus/i18n'
console.log(`${dictionary.i19hello.en_us} ${dictionary.i19visitor.en_us}`)
// Hello VisitorWebpack 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 { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i19hello} ${i19visitor}`)
// Hello VisitorYou can still use
ecomUtils.i18n
the same way:
import { i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Hello VisitorConventions
- String values always with uppercased first letter (eg.:
'Hello'); - Variable (
const) names always in English; - Prefix
i19for all variable names; - String variables must be camelCased (eg.:
i19helloWorld); - Object (enums) variables must be PascalCased (eg.:
i19OrderStatus); - All language options must have same variables;
- For long messages: variable name should be suffixed with
Msg; - For questions: variable name should be suffixed with
Qn;
Code style
- Exported constants must be alphabetically ordered;
- Additional line break before objects (not for strings);