Comparing version 1.1.1 to 1.2.0
25
app.js
'use strict'; | ||
const locales = require('koa-locales'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -14,6 +15,6 @@ const debug = require('debug')('egg:plugin:i18n'); | ||
* | ||
* 统一存放在 `config/locales/*.js` 下,如包含英文,简体中文,繁体中文的语言文件: | ||
* 统一存放在 `config/locale/*.js` 下( 兼容`config/locales/*.js` ),如包含英文,简体中文,繁体中文的语言文件: | ||
* | ||
* ``` | ||
* - config/locales/ | ||
* - config/locale/ | ||
* - en-US.js | ||
@@ -30,3 +31,3 @@ * - zh-CN.js | ||
* ```js | ||
* // config/locales/zh-CN.js | ||
* // config/locale/zh-CN.js | ||
* module.exports = { | ||
@@ -40,3 +41,3 @@ * "Email": "邮箱", | ||
* ```js | ||
* // config/locales/en-US.js | ||
* // config/locale/en-US.js | ||
* module.exports = { | ||
@@ -49,3 +50,3 @@ * "Email": "Email", | ||
* ```js | ||
* // config/locales/zh-CN.json | ||
* // config/locale/zh-CN.json | ||
* { | ||
@@ -113,5 +114,15 @@ * "email": "邮箱", | ||
app.config.i18n.dirs = Array.isArray(app.config.i18n.dirs) ? app.config.i18n.dirs : []; | ||
// 按 egg > 插件 > 框架 > 应用的顺序遍历 config/locales 目录,加载所有配置文件 | ||
// 按 egg > 插件 > 框架 > 应用的顺序遍历 config/locale(config/locales) 目录,加载所有配置文件 | ||
for (const unit of app.loader.getLoadUnits()) { | ||
app.config.i18n.dirs.push(path.join(unit.path, 'config/locales')); | ||
const localePath = path.join(unit.path, 'config/locale'); | ||
/** | ||
* 优先选择 `config/locale` 目录下的多语言文件 | ||
* 避免 2 个目录同时存在时可能导致的冲突 | ||
*/ | ||
if (fs.existsSync(localePath)) { | ||
app.config.i18n.dirs.push(localePath); | ||
} else { | ||
app.config.i18n.dirs.push(path.join(unit.path, 'config/locales')); | ||
} | ||
} | ||
@@ -118,0 +129,0 @@ |
1.2.0 / 2017-09-13 | ||
================== | ||
**features** | ||
* [[`1117129`](http://github.com/eggjs/egg-i18n/commit/1117129ce0153d317d376a2692b3de14b94a6717)] - feat: use config/locale/*.js as default I18N folder (#7) (tudou527 <<tudou527@users.noreply.github.com>>) | ||
1.1.1 / 2017-04-19 | ||
@@ -3,0 +9,0 @@ ================== |
{ | ||
"name": "egg-i18n", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"eggPlugin": { | ||
@@ -56,2 +56,2 @@ "name": "i18n" | ||
} | ||
} | ||
} |
@@ -27,3 +27,3 @@ # egg-i18n | ||
- 支持多种语言独立配置,统一存放在 config/locales/*.js 下; | ||
- 支持多种语言独立配置,统一存放在 config/locale/*.js 下( 兼容`config/locales/*.js` ); | ||
- 提供 Middleware 为 View 提供 `__`, `gettext` 函数获取多语言文案; | ||
@@ -65,3 +65,3 @@ - 基于 URL 参数 `locale` 修改语言显示,同时会记录到 Cookie,下次请求会用 Cookie 里面的语言方案。 | ||
```js | ||
// config/locales/zh-CN.js | ||
// config/locale/zh-CN.js | ||
module.exports = { | ||
@@ -75,3 +75,3 @@ "Email": "邮箱", | ||
```js | ||
// config/locales/en-US.js | ||
// config/locale/en-US.js | ||
module.exports = { | ||
@@ -85,3 +85,3 @@ "Email": "Email", | ||
```json | ||
// config/locales/zh-CN.json | ||
// config/locale/zh-CN.json | ||
{ | ||
@@ -96,3 +96,3 @@ "email": "邮箱", | ||
I18n 为你提供 `__` (Alias: `gettext`) 函数,让你可以轻松获得 locales 文件夹下面的多语言文本。 | ||
I18n 为你提供 `__` (Alias: `gettext`) 函数,让你可以轻松获得 locale 文件夹下面的多语言文本。 | ||
@@ -99,0 +99,0 @@ > NOTE: __ 是两个下划线哦! |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11983
179
0
1