Skip to content

Commit

Permalink
refactor: Align the i18n mapping & update the guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 20, 2023
1 parent b53355a commit 2dbe7a0
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 56 deletions.
42 changes: 19 additions & 23 deletions CONTRIBUTING.i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,34 @@ This should start the launcher. You can switch to your language in setting page
### Adding new language

**Optional**.
If you are adding a new language, you need to also go to the `xmcl-keystone-ui\src\util\localeMappings.ts` and add the new language key value there.

Suppose you want to add `French` (`fr`), you can open the file `xmcl-keystone-ui\src\util\localeMappings.ts`

```ts
export const localeMappings: Record<string, string> = {
'zh-CN': '简体中文',
'zh-TW': '繁體中文',
en: 'English',
'en-US': 'English (The United State)',
'en-UK': 'English (The United Kindom)',
ru: 'Русский язык',
If you are adding a new language, you need to also go to the `assets\locales.json` and add the new language key value there.

Suppose you want to add `French` (`fr`), you can open the file `assets\locales.json`

```json
{
"zh-CN": "简体中文",
"zh-TW": "繁體中文",
"en": "English",
"ru": "Русский язык",
"es-ES": "Español"
}
```

adding a new line at the end

```ts
export const localeMappings: Record<string, string> = {
'zh-CN': '简体中文',
'zh-TW': '繁體中文',
en: 'English',
'en-US': 'English (The United State)',
'en-UK': 'English (The United Kindom)',
ru: 'Русский язык',
'fr': 'French',
```json
{
"zh-CN": "简体中文",
"zh-TW": "繁體中文",
"en": "English",
"ru": "Русский язык",
"es-ES": "Español",
'fr': 'French'
}
```

### Send Pull Request

Please follow the [github guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) about how to send pull request.



8 changes: 8 additions & 0 deletions assets/locales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"zh-CN": "简体中文",
"zh-TW": "繁體中文",
"en": "English",
"ru": "Русский язык",
"es-ES": "Español",
"fr": "French"
}
10 changes: 1 addition & 9 deletions xmcl-electron-app/main/controllers/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import Controller from '@/Controller'
import { BaseService } from '@xmcl/runtime'
import { ControllerPlugin } from './plugin'

export const localeMappings: Record<string, string> = {
'zh-CN': '简体中文',
'zh-TW': '繁體中文',
en: 'English',
ru: 'Русский язык',
'es-ES': 'Español',
fr: 'French',
}
import localeMappings from '../../../assets/locales.json'

export const i18n: ControllerPlugin = function (this: Controller) {
this.app.once('engine-ready', () => {
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ openUrl:
trust: Trust this site and don't show next time
'yes': 'Yes'
quit: Quit
setup:
title: X Minecraft Launcher 主页
showDiagnosis: Show Diagnose
showLauncher: Show Launcher
showLogsFolder: Show Logs Folder
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ openUrl:
trust: Confiar en este sitio y no volver a preguntar
'yes':
quit: Salir
setup:
title: Bienvenido a X Minecraft Launcher. Antes de comenzar, necesitamos que
showDiagnosis: Mostrar diagnostico
showLogsFolder: Mostrar carpeta de registros
task:
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ openUrl:
trust: Faire confiance au site et ne plus afficher
"yes": "Oui"
quit: Quitter
setup:
title: X Minecraft Launcher
showDiagnosis: Afficher le Diagnostic
showLauncher: Afficher le Launcher
showLogsFolder: Afficher le Dossier de Logs
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ openUrl:
trust: Доверять этому сайту и не показывать это в следующий раз
'yes': 'Да'
quit: Выход
setup:
title: Главная X Minecraft Launcher
showDiagnosis: Показать диагностику
showLauncher: Показать лаунчер
showLogsFolder: Открыть папку с логами
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ openUrl:
trust: 信任此网站,下次不再显示
'yes': 允许
quit: 退出
setup:
title: XMCL
showDiagnosis: 显示 Debug 信息
showLauncher: 显示启动器
showLogsFolder: 显示日志文件夹
Expand Down
2 changes: 0 additions & 2 deletions xmcl-electron-app/main/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ openUrl:
trust: 信任此網站,下次不再顯示
'yes': 允許
quit: 退出
setup:
title: XMCL
showDiagnosis: 顯示 Debug 信息
showLogsFolder: 顯示日誌文件夾
task:
Expand Down
6 changes: 0 additions & 6 deletions xmcl-keystone-ui/src/assets/localeMapping.json

This file was deleted.

11 changes: 5 additions & 6 deletions xmcl-keystone-ui/src/views/SetupLocale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@
</v-list>
</template>
<script lang=ts setup>
import localMapping from '@/assets/localeMapping.json'
import localMapping from '../../../assets/locales.json'
defineProps<{ value: string }>()
const emit = defineEmits(['input'])
const { t } = useI18n()
const locales = [
'en',
'zh-CN',
'ru',
].map(l => ({ text: (localMapping as any)[l] ?? l, value: l }))
const locales = Object.entries(localMapping).forEach(([key, value]) => ({
text: value,
value: key,
}))
</script>

0 comments on commit 2dbe7a0

Please sign in to comment.