@ecomplus/i18n

中文文档
1.32.2发布于 2022/09/27MITESM + CJS零依赖近 30 天下载 4182

Tree shakable dictionary for e-commerce JS apps

原始使用文档
文档目录5 节
  1. Getting started
  2. Usage
  3. Webpack alias
  4. Conventions
  5. Code style

i18n

Publish npm version License MIT

:brazil: :us:

Tree shakable dictionary focused on eCommerce JS applications.

i18n ~ i19 ~ Internationalization

Getting started

npm i --save @ecomplus/i18n

Usage

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á Visitante

We recommend using it with ecomUtils.i18n:

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

Change 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á Visitante

Import 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 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/src/${lang}/`
    }
  }
}

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

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

You 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 Visitor

Conventions

  1. String values always with uppercased first letter (eg.: 'Hello');
  2. Variable (const) names always in English;
  3. Prefix i19 for all variable names;
  4. String variables must be camelCased (eg.: i19helloWorld);
  5. Object (enums) variables must be PascalCased (eg.: i19OrderStatus);
  6. All language options must have same variables;
  7. For long messages: variable name should be suffixed with Msg;
  8. For questions: variable name should be suffixed with Qn;

Code style

  1. Exported constants must be alphabetically ordered;
  2. Additional line break before objects (not for strings);

版本与发布记录

@ecomplus/i18n 共发布 43 个版本,首次发布于 2019/11/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.32.2latest2022/09/274 年前
1.32.12022/09/274 年前
1.32.02022/09/274 年前
1.31.02022/08/114 年前
1.30.02022/08/064 年前
1.29.02022/03/264 年前

关于 @ecomplus/i18n 的常见问题

@ecomplus/i18n 是什么?

Tree shakable dictionary for e-commerce JS apps

如何安装 @ecomplus/i18n?

在项目目录运行 npm install @ecomplus/i18n,或使用 pnpm add / yarn add / bun add。

@ecomplus/i18n 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ecomplus__i18n 是否存在。

@ecomplus/i18n 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ecomplus/i18n 可以商用吗?

@ecomplus/i18n 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ecomplus/i18n 的下载量有多少?

根据 npm 官方下载统计,@ecomplus/i18n 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,182 次,日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ecomplus/i18n 还在维护吗?

最新版本 1.32.2 发布于 2022/09/27(4 年前);至今共发布 43 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/11/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。