Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkudo committed Sep 21, 2018
1 parent acd8955 commit 782b2ec
Show file tree
Hide file tree
Showing 11 changed files with 670 additions and 712 deletions.
9 changes: 4 additions & 5 deletions __mocks__/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default class SearchPage extends Component {
}
static get template() {
return '{{__('invalid''string')}} <div>{{__n('%d result', '%d results', 2)}}</div>';
return '{{__('invalid''string')}} {{__p('menuitem', 'Search')}} <div>{{__n('%d result', '%d results', 2)}}</div> {{__np('footer', '%d view', '%d views', 23)}}';
}
};
`.trim();
Expand All @@ -41,9 +40,9 @@ module.exports = {
'src/test.js': EmptyPage,
'src/index.js': Application,
'./locales/existing.json': JSON.stringify({
"Search": "検索",
"test unused key": "test value",
"Application": "アプリケーション",
"Search": {"default": "検索"},
"test unused key": {"default": "test value"},
"Application": {"default": "アプリケーション"},
}),
'src/pages/About/.locales/existing.json': JSON.stringify({}),
'src/pages/Search/.locales/existing.json': JSON.stringify({'Search': ''}),
Expand Down
41 changes: 0 additions & 41 deletions __mocks__/y18n.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"fs-extra": "^7.0.0",
"glob": "^7.1.2",
"json5": "^1.0.1",
"safe-eval": "^0.4.1",
"y18n": "^4.0.0"
"safe-eval": "^0.4.1"
},
"scripts": {
"build": "scripts/build.sh",
Expand Down
40 changes: 23 additions & 17 deletions src/hasTranslation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/**
* @private
*/
function singularHasTranslation(data) {
return Boolean(data.length);
}

/**
* @private
*/
function pluralHasTranslation(data) {
return Object.values(data || {}).some((v) => {
if (Object(v) === v) {
return pluralHasTranslation(v);
}

return singularHasTranslation(v);
});
}

/**
* Checks of a translation key-value pair has been created.
* @param {*} data - An object that is spidered looking for
Expand All @@ -6,23 +26,9 @@
* @private
*/
module.exports = function hasTranslation(data) {
if (Object(data) === data) {
const keys = Object.keys(data);

if (!keys.length) {
return false;
}

return keys.some((k) => {
if (typeof data[k] === 'string') {
return Boolean(data[k].length);
} else {
return hasTranslation(data[k]);
}
});
} else if (typeof data === 'string') {
return Boolean(data.length);
if (typeof data === 'string') {
return singularHasTranslation(data);
}

return false;
return pluralHasTranslation(data);
}
Loading

0 comments on commit 782b2ec

Please sign in to comment.