1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-04 17:45:51 +02:00
This commit is contained in:
syuilo
2018-07-06 12:17:38 +09:00
parent 9b41023c43
commit 029b92935c
10 changed files with 49 additions and 312 deletions

View File

@@ -2,7 +2,7 @@
* Replace i18n texts
*/
import locale, { isAvailableLanguage, LocaleObject } from '../../locales';
const locale = require('../../locales');
export default class Replacer {
private lang: string;
@@ -16,8 +16,8 @@ export default class Replacer {
this.replacement = this.replacement.bind(this);
}
private get(path: string, key: string): string {
if (!isAvailableLanguage(this.lang)) {
public get(path: string, key: string): string {
if (!(this.lang in locale)) {
console.warn(`lang '${this.lang}' is not supported`);
return key; // Fallback
}
@@ -28,7 +28,7 @@ export default class Replacer {
if (path) {
if (text.hasOwnProperty(path)) {
text = text[path] as LocaleObject;
text = text[path];
} else {
console.warn(`path '${path}' not found in '${this.lang}'`);
return key; // Fallback
@@ -38,7 +38,7 @@ export default class Replacer {
// Check the key existance
const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) {
text = (text as LocaleObject)[k];
text = text[k];
return false;
} else {
return true;