Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #933 from kubosho/i18n
Introduce i18n
- Loading branch information
Showing
19 changed files
with
256 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import React from 'react'; | ||
import { retrieveTranslation } from '../../locales/i18n'; | ||
|
||
// https://github.com/FortAwesome/Font-Awesome/blob/master/js-packages/@fortawesome/fontawesome-free/svgs/brands/facebook-f.svg | ||
// License: https://fontawesome.com/license/free | ||
export const FacebookSvg = (): JSX.Element => ( | ||
<svg viewBox="0 0 320 512" aria-label="Facebook でシェア" role="img"> | ||
<svg viewBox="0 0 320 512" aria-label={retrieveTranslation('components.icon.facebook')} role="img"> | ||
<path d="M279.14 288l14.22-92.66h-88.91v-60.13c0-25.35 12.42-50.06 52.24-50.06h40.42V6.26S260.43 0 225.36 0c-73.22 0-121.08 44.38-121.08 124.72v70.62H22.89V288h81.39v224h100.17V288z" /> | ||
</svg> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React from 'react'; | ||
import { retrieveTranslation } from '../../locales/i18n'; | ||
// https://github.com/FortAwesome/Font-Awesome/blob/master/js-packages/@fortawesome/fontawesome-free/svgs/brands/twitter.svg | ||
// License: https://fontawesome.com/license/free | ||
export const TwitterSvg = (): JSX.Element => ( | ||
<svg viewBox="0 0 512 512" aria-label="Twitter でシェア" role="img"> | ||
<svg viewBox="0 0 512 512" aria-label={retrieveTranslation('components.icon.twitter')} role="img"> | ||
<path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" /> | ||
</svg> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect, test } from 'vitest'; | ||
import { activateI18n, retrieveTranslation, setLocale } from '../i18n'; | ||
|
||
test('i18n', () => { | ||
activateI18n(); | ||
setLocale('ja'); | ||
|
||
const actual = retrieveTranslation('website.title'); | ||
|
||
expect(actual).toBe('学ぶ、考える、書き出す。'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import rosetta, { Rosetta } from 'rosetta'; | ||
|
||
import { localeJa } from './ja'; | ||
|
||
export type SupportedLanguage = 'ja'; | ||
|
||
let i18n: Rosetta<unknown> | null = null; | ||
let currentLanguage: SupportedLanguage | null = null; | ||
|
||
export function activateI18n(): void { | ||
if (i18n !== null) { | ||
return; | ||
} | ||
|
||
i18n = rosetta({ ja: { ...localeJa } }); | ||
} | ||
|
||
export function setLocale(lang: SupportedLanguage): void { | ||
if (i18n === null) { | ||
throw new Error('i18n is not activated'); | ||
} | ||
|
||
if (currentLanguage === lang) { | ||
return; | ||
} | ||
|
||
currentLanguage = lang; | ||
i18n.locale(currentLanguage); | ||
} | ||
|
||
export function retrieveTranslation( | ||
key: string | (string | number)[], | ||
params?: unknown[] | Record<string, unknown>, | ||
lang?: string, | ||
): string { | ||
if (i18n === null) { | ||
throw new Error('i18n is not activated'); | ||
} | ||
|
||
const r = i18n.t(key, params, lang); | ||
|
||
if (r === '') { | ||
throw new Error(`Translate text is not retrieved: ${key}`); | ||
} | ||
|
||
return r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
export const localeJa = { | ||
website: { | ||
title: '学ぶ、考える、書き出す。', | ||
description: '学習し、自分なりに噛み砕いて、書き出すブログ。', | ||
author: 'kubosho', | ||
}, | ||
navigation: { | ||
feed: 'フィード', | ||
policy: 'ポリシー', | ||
}, | ||
optout: { | ||
actions: { | ||
enabled: 'オプトアウトの有効化', | ||
disabled: 'オプトアウトの無効化', | ||
}, | ||
status: { | ||
enabled: 'オプトアウトが有効になっています。Googleアナリティクスによるアクセス解析はおこなわれません。', | ||
disabled: 'オプトアウトが無効になっています。Googleアナリティクスによるアクセス解析がおこなわれます。', | ||
}, | ||
}, | ||
components: { | ||
entryList: { | ||
notFound: '記事はありません。', | ||
}, | ||
icon: { | ||
facebook: 'Facebookでシェア', | ||
twitter: 'Twitterでシェア', | ||
}, | ||
}, | ||
top: { | ||
headings: { | ||
entryList: '記事一覧', | ||
}, | ||
}, | ||
draft: { | ||
notAvailable: 'プレビューは利用できません。', | ||
}, | ||
entry: { | ||
share: '記事を共有する', | ||
headings: { | ||
related: '関連記事', | ||
}, | ||
}, | ||
categories: { | ||
description: '{{webSiteTitle}}の「{{category}}」に関連した記事の一覧です。', | ||
headings: { | ||
entryList: 'カテゴリー「{{category}}」の記事一覧', | ||
}, | ||
}, | ||
tags: { | ||
description: '{{webSiteTitle}}の「{{tag}}」に関連した記事の一覧です。', | ||
headings: { | ||
entryList: 'タグ「{{tag}}」の記事一覧', | ||
}, | ||
}, | ||
policy: { | ||
title: 'ポリシー', | ||
headings: { | ||
affiliate: 'アフィリエイト', | ||
disclaimer: '免責事項', | ||
optout: 'Googleアナリティクスによる解析のオプトアウト', | ||
privacy: 'プライバシー', | ||
}, | ||
intro: { | ||
text: 'このページでは当ブログ『{{webSiteTitle}}』内で適用されるポリシーについて書きます。', | ||
}, | ||
text: { | ||
privacy: { | ||
1: '当ブログでは内容の改善を目的として、Googleアナリティクスによるアクセス分析をおこなっています。', | ||
2: 'Googleアナリティクスは、Cookie(クッキー)により、匿名のトラフィックデータを収集しています。', | ||
3: 'Cookieに含まれるデータは利用者の個人情報を特定しません。利用者はCookieを無効にした状態で当ブログにアクセスできます。', | ||
4: '詳しくはGoogleが公開している', | ||
5: 'Google のサービスを使用するサイトやアプリから収集した情報の Google による使用', | ||
6: 'のページを参照してください。', | ||
}, | ||
optout: { | ||
1: '以下のボタンからGoogleアナリティクスによる解析のオプトアウトの有効化・無効化がおこなえます。', | ||
}, | ||
affiliate: { | ||
1: '『{{webSiteTitle}}』は、Amazon.co.jpを宣伝しリンクすることによってサイトが紹介料を獲得できる手段を提供することを目的に設定されたアフィリエイトプログラムである、Amazonアソシエイト・プログラムの参加者です。', | ||
}, | ||
disclaimer: { | ||
1: '当ブログではコンテンツ・情報について、できる限り正確な情報を提供するように努めています。', | ||
2: 'しかし、完全な正確性や安全性は保障いたしません。情報が古くなったり間違っていたりすることがあります。', | ||
3: 'また、当ブログに掲載した内容によって生じた損害などの一切の責任は負いません。ご了承ください。', | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f4fcb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
im-kubosho – ./
im-kubosho-git-master-kubosho.vercel.app
blog.kubosho.com
im-kubosho-kubosho.vercel.app