fix: return empty if the key-value is empty value
PR-URL: https://github.com/koajs/locales/pull/17 Reviewed-By: fengmk2 <fengmk2@gmail.com> Reviewed-By: dead-horse <heyiyu.deadhorse@gmail.com>
This commit is contained in:
10
index.js
10
index.js
@@ -1,6 +1,4 @@
|
||||
/**!
|
||||
* koa-locales - index.js
|
||||
*
|
||||
/**
|
||||
* Copyright(c) koajs and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
@@ -87,7 +85,11 @@ module.exports = function (app, options) {
|
||||
const locale = this.__getLocale();
|
||||
const resource = resources[locale] || {};
|
||||
|
||||
const text = resource[key] || key;
|
||||
let text = resource[key];
|
||||
if (text === undefined) {
|
||||
text = key;
|
||||
}
|
||||
|
||||
debug('%s: %j => %j', locale, key, text);
|
||||
if (!text) {
|
||||
return '';
|
||||
|
||||
@@ -36,6 +36,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -76,6 +77,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -101,6 +103,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -125,6 +128,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -150,6 +154,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -174,6 +179,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -201,6 +207,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -232,6 +239,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -255,6 +263,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -278,6 +287,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -303,6 +313,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -328,6 +339,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -355,6 +367,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: '',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -382,6 +395,7 @@ describe('koa-locales.test.js', function () {
|
||||
empty: '',
|
||||
notexists_key: 'key not exists',
|
||||
empty_string: '',
|
||||
empty_value: 'emptyValue',
|
||||
novalue: 'key %s ok',
|
||||
arguments3: '1 2 3',
|
||||
arguments4: '1 2 3 4',
|
||||
@@ -423,6 +437,7 @@ function createApp(options) {
|
||||
empty: this[fname](),
|
||||
notexists_key: this[fname]('key not exists'),
|
||||
empty_string: this[fname](''),
|
||||
empty_value: this[fname]('emptyValue'),
|
||||
novalue: this[fname]('key %s ok'),
|
||||
arguments3: this[fname]('%s %s %s', 1, 2, 3),
|
||||
arguments4: this[fname]('%s %s %s %s', 1, 2, 3, 4),
|
||||
@@ -435,3 +450,4 @@ function createApp(options) {
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
module.exports = {
|
||||
Email: '邮箱',
|
||||
emptyValue: '',
|
||||
'Hello %s, how are you today?': '%s,今天过得如何?',
|
||||
model: {
|
||||
user: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"Email": "郵箱",
|
||||
"emptyValue": "",
|
||||
"Hello %s, how are you today?": "%s,今天過得如何?",
|
||||
"model": {
|
||||
"user": {
|
||||
|
||||
Reference in New Issue
Block a user