-
Notifications
You must be signed in to change notification settings - Fork 0
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 #20 from VecHK/language
Language
- Loading branch information
Showing
10 changed files
with
328 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import i18n from 'i18next' | ||
import { initReactI18next } from 'react-i18next' | ||
import LanguageDetector from 'i18next-browser-languagedetector' | ||
|
||
const resources = { | ||
en: { | ||
translation: { | ||
PlayingTips: 'Please click "<1></1>"', | ||
'胜败乃兵家常事,大侠请重新来过': 'YOU LOSE', | ||
无序连败早该管管了: '😥', | ||
'✌️你赢了': '✌️YOU WIN', | ||
'✌️赢麻了': 'WIN WIN WIN WIN WIN', | ||
'✌️四赢': '✌️WIN 4 times', | ||
'✌️三赢': '✌️WIN 3 times', | ||
'✌️双赢': '✌️WIN twice', | ||
再来一把: 'Replay', | ||
关于: 'About', | ||
宽度: 'Width', | ||
高度: 'Height', | ||
雷数: 'Bomb number', | ||
|
||
难度设定: 'Diffculty', | ||
简单: 'EASY', | ||
谁都能玩的程度: 'anyone', | ||
|
||
困难: 'HARD', | ||
需要点功夫: 'need patience', | ||
|
||
大佬: 'PROFESSIONAL', | ||
能玩完这关才好意思说自己会玩扫雷: 'Minesweeper expert', | ||
|
||
自定义: 'CUSTOM', | ||
骨灰级玩家最爱的: 'to Fanatic', | ||
|
||
其它的一些设定: 'Other setting', | ||
边缘不放置地雷: 'no mines on edge', | ||
可以避免这种情况: 'can skip this case', | ||
保存并返回: 'save & back', | ||
}, | ||
}, | ||
|
||
'zh-Hant': { | ||
translation: { | ||
PlayingTips: '點擊<1></1>就完事了', | ||
'胜败乃兵家常事,大侠请重新来过': '勝敗乃兵家常事,大俠請重新來過', | ||
无序连败早该管管了: '無序連敗早該管管了', | ||
'✌️你赢了': '✌️你贏了', | ||
'✌️赢麻了': '✌️贏麻了', | ||
'✌️四赢': '✌️四贏', | ||
'✌️三赢': '✌️三贏', | ||
'✌️双赢': '✌️雙贏', | ||
再来一把: '再來一局', | ||
关于: '關於', | ||
宽度: '寬度', | ||
高度: '高度', | ||
雷数: '雷數', | ||
|
||
难度设定: '難度設定', | ||
简单: '簡單', | ||
谁都能玩的程度: '誰都能玩的程度', | ||
|
||
困难: '困難', | ||
需要点功夫: '需要點功夫', | ||
|
||
大佬: '高手', | ||
能玩完这关才好意思说自己会玩扫雷: '能玩完這關才好意思說自己會玩掃雷', | ||
|
||
自定义: '自定義', | ||
骨灰级玩家最爱的: '骨灰級玩家最愛的', | ||
|
||
其它的一些设定: '其它的一些設定', | ||
边缘不放置地雷: '邊緣不放置地雷', | ||
可以避免这种情况: '可以避免這種情況', | ||
保存并返回: '保存並返回', | ||
}, | ||
}, | ||
|
||
ja: { | ||
translation: { | ||
PlayingTips: '<1></1>をクリックしてください', | ||
'胜败乃兵家常事,大侠请重新来过': '失敗した', | ||
无序连败早该管管了: '満身創痍', | ||
'✌️你赢了': '勝ちだ!', | ||
'✌️赢麻了': '凄い!連続勝利5回以上', | ||
'✌️四赢': '四回勝ち', | ||
'✌️三赢': '三回勝ち', | ||
'✌️双赢': '二回勝ち', | ||
再来一把: 'もう一回', | ||
关于: 'このゲームについて', | ||
宽度: '宽度', | ||
高度: '高度', | ||
雷数: '地雷数', | ||
|
||
难度设定: '難易度調整', | ||
简单: '簡単', | ||
谁都能玩的程度: '誰でも遊べるのレベル', | ||
|
||
困难: '困難', | ||
需要点功夫: 'ある努力が必要、ちょっと難しいのレベル', | ||
|
||
大佬: '達者', | ||
能玩完这关才好意思说自己会玩扫雷: | ||
'このレベルをクリアしたら、”マインスイーパ分かる”と言うのはできるでしょ', | ||
|
||
自定义: 'カスタム', | ||
骨灰级玩家最爱的: 'マインスイーパ マニアのあなたへ', | ||
|
||
其它的一些设定: '他の設定', | ||
边缘不放置地雷: '边缘のマスが地雷放置禁止', | ||
可以避免这种情况: 'こういう状況が回避できる', | ||
保存并返回: 'セーブして戻る', | ||
}, | ||
}, | ||
} | ||
|
||
export default i18n | ||
.use(initReactI18next) | ||
.use(LanguageDetector) | ||
.init({ | ||
resources, | ||
|
||
detection: { | ||
order: [ | ||
// 'querystring', | ||
// 'cookie', | ||
'localStorage', | ||
// 'sessionStorage', | ||
'navigator', | ||
// 'htmlTag', | ||
// 'path', | ||
// 'subdomain', | ||
], | ||
}, | ||
|
||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}) |
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,25 @@ | ||
.language-select { | ||
cursor: pointer; | ||
user-select: none; | ||
} | ||
|
||
.lang-icon:last-child { | ||
border-right: 0; | ||
} | ||
|
||
.lang-icon { | ||
display: inline-flex; | ||
justify-content: center; | ||
align-content: center; | ||
align-items: center; | ||
padding: 0 4px; | ||
border-right: solid 1px grey; | ||
width: 28px; | ||
font-size: 16px; | ||
height: 28px; | ||
} | ||
|
||
.lang-icon.current { | ||
color: hsl(185, 6%, 25%); | ||
font-weight: bolder; | ||
} |
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,55 @@ | ||
import { useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import './index.css' | ||
|
||
function initLangCode() { | ||
let currentLangCode: string = localStorage.i18nextLng || 'zh-CN' | ||
if (currentLangCode === 'dev') { | ||
currentLangCode = 'zh-cn' | ||
} | ||
return currentLangCode | ||
} | ||
|
||
export default () => { | ||
const [currentLangCode, setCurrentLangCode] = useState(initLangCode()) | ||
|
||
const langMap: Array<[string, RegExp, string]> = [ | ||
['汉', /(zh-hans)|(zh-cn)|(zh-sg)|(zh-my)/i, 'zh-hans'], | ||
['漢', /(zh-hant)|(zh-tw)|(zh-hk)|(zh-mo)/i, 'zh-hant'], | ||
['あ', /ja/i, 'ja'], | ||
['EN', /en/i, 'en'], | ||
] | ||
|
||
const { i18n } = useTranslation() | ||
|
||
const selectedIdx = langMap.findIndex(([langIcon, exp]) => { | ||
return exp.test(currentLangCode) | ||
}) | ||
|
||
const toggleLanguage = (currentIdx: number = selectedIdx) => { | ||
const nextLang = langMap[currentIdx + 1] | ||
if (nextLang) { | ||
setCurrentLangCode(nextLang[2]) | ||
i18n.changeLanguage(nextLang[2]) | ||
} else { | ||
toggleLanguage(-1) | ||
} | ||
} | ||
|
||
return ( | ||
<div className="language-select" onClick={() => toggleLanguage()}> | ||
{langMap.map(([langIcon], idx) => { | ||
const isCurrent = selectedIdx === idx | ||
|
||
return ( | ||
<span | ||
key={langIcon} | ||
className={`lang-icon ${isCurrent ? 'current' : ''}`} | ||
> | ||
{langIcon} | ||
</span> | ||
) | ||
})} | ||
</div> | ||
) | ||
} |
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.