diff --git a/locales/en.json b/locales/en.json index ea6ae5b7d..9963ec60a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1,3 +1,23 @@ { - "home": "Home" + "common": { + "time": { + "unknown": "unknown", + "future": "future", + "just_now": "just now", + "seconds_ago": "{}s ago", + "minutes_ago": "{}m ago", + "hours_ago": "{}h ago", + "days_ago": "{}d ago", + "weeks_ago": "{}weeks ago", + "months_ago": "{}months ago", + "years_ago": "{}years ago" + } + }, + "desktop": { + "tags": { + "mk-ui-header-nav": { + "home": "Home" + } + } + } } diff --git a/locales/ja.json b/locales/ja.json index 7a7f3a2d0..c4bb930db 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -1,3 +1,23 @@ { - "home": "ホーム" + "common": { + "time": { + "unknown": "なぞのじかん", + "future": "未来", + "just_now": "たった今", + "seconds_ago": "{}秒前", + "minutes_ago": "{}分前", + "hours_ago": "{}時間前", + "days_ago": "{}日前", + "weeks_ago": "{}週間前", + "months_ago": "{}ヶ月前", + "years_ago": "{}年前" + } + }, + "desktop": { + "tags": { + "mk-ui-header-nav": { + "home": "ホーム" + } + } + } } diff --git a/src/web/app/common/tags/time.tag b/src/web/app/common/tags/time.tag index b4e6dcdbd..b0d7d2453 100644 --- a/src/web/app/common/tags/time.tag +++ b/src/web/app/common/tags/time.tag @@ -34,16 +34,16 @@ const now = new Date(); const ago = (now - this.time) / 1000/*ms*/; this.relative = - ago >= 31536000 ? ~~(ago / 31536000) + '年前' : - ago >= 2592000 ? ~~(ago / 2592000) + 'ヶ月前' : - ago >= 604800 ? ~~(ago / 604800) + '週間前' : - ago >= 86400 ? ~~(ago / 86400) + '日前' : - ago >= 3600 ? ~~(ago / 3600) + '時間前' : - ago >= 60 ? ~~(ago / 60) + '分前' : - ago >= 10 ? ~~(ago % 60) + '秒前' : - ago >= 0 ? 'たった今' : - ago < 0 ? '未来' : - 'なぞのじかん'; + ago >= 31536000 ? '%i18n:common.time.years_ago%' .replace('{}', ~~(ago / 31536000)) : + ago >= 2592000 ? '%i18n:common.time.months_ago%' .replace('{}', ~~(ago / 2592000)) : + ago >= 604800 ? '%i18n:common.time.weeks_ago%' .replace('{}', ~~(ago / 604800)) : + ago >= 86400 ? '%i18n:common.time.days_ago%' .replace('{}', ~~(ago / 86400)) : + ago >= 3600 ? '%i18n:common.time.hours_ago%' .replace('{}', ~~(ago / 3600)) : + ago >= 60 ? '%i18n:common.time.minutes_ago%'.replace('{}', ~~(ago / 60)) : + ago >= 10 ? '%i18n:common.time.seconds_ago%'.replace('{}', ~~(ago % 60)) : + ago >= 0 ? '%i18n:common.time.just_now%' : + ago < 0 ? '%i18n:common.time.future%' : + '%i18n:common.time.unknown%'; this.update(); }; diff --git a/src/web/app/desktop/tags/ui-header-nav.tag b/src/web/app/desktop/tags/ui-header-nav.tag index 5ffa392f5..2fb0f8c51 100644 --- a/src/web/app/desktop/tags/ui-header-nav.tag +++ b/src/web/app/desktop/tags/ui-header-nav.tag @@ -3,7 +3,7 @@
  • -

    'i18n:home'

    +

    %i18n:desktop.tags.mk-ui-header-nav.home%

  • diff --git a/webpack.config.ts b/webpack.config.ts index 2fc8ce8a1..1300d2c9e 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -30,11 +30,11 @@ module.exports = (Object as any).entries(languages).map(([lang, locale]) => { rules: [ { enforce: 'pre', - test: /\.*$/, + test: /\.(tag|js)$/, exclude: /node_modules/, loader: StringReplacePlugin.replace({ replacements: [ - { pattern: /'i18n:(.+?)'/g, replacement: (_, text) => locale[text] } + { pattern: /%i18n:(.+?)%/g, replacement: (_, text) => eval('locale' + text.split('.').map(x => `['${x}']`).join('')) } ] }) },