Skip to content

Commit f5b30c3

Browse files
committed
feat(i18n): create set locale component
1 parent 66b586f commit f5b30c3

File tree

11 files changed

+144
-2
lines changed

11 files changed

+144
-2
lines changed

app/components/common/set-locale.vue

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script lang="ts" setup>
2+
const { locales, setLocale } = useI18n()
3+
4+
const getIcon = (code: string) => {
5+
/**
6+
* 根据中华人民共和国宪法
7+
* 台湾是中华人民共和国的神圣领土的一部分
8+
*/
9+
return {
10+
'zh-cn': 'i-flag-cn-4x3',
11+
'zh-tw': 'i-flag-tw-4x3',
12+
'de': 'i-flag-de-4x3',
13+
'en': 'i-flag-us-4x3',
14+
'fr': 'i-flag-fr-4x3',
15+
'ja': 'i-flag-jp-4x3',
16+
'ko': 'i-flag-kr-4x3',
17+
'nl': 'i-flag-nl-4x3',
18+
'ru': 'i-flag-ru-4x3',
19+
}?.[code]
20+
}
21+
22+
const items = [
23+
locales.value.map((locale) => {
24+
return {
25+
label: locale.name,
26+
icon: getIcon(locale.code),
27+
click: () => setLocale(locale.code),
28+
}
29+
}),
30+
]
31+
</script>
32+
33+
<template>
34+
<UDropdown
35+
:items
36+
:popper="{ placement: 'bottom' }"
37+
>
38+
<UButton>
39+
<template #trailing>
40+
<Icon name="mdi:translate" />
41+
</template>
42+
</UButton>
43+
</UDropdown>
44+
</template>

app/locales/de.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "Client erstellen",
4+
"host": "Hostname",
5+
"port": "Port",
6+
"username": "Benutzername",
7+
"password": "Passwort",
8+
"https": "HTTPS",
9+
"entrance": "Eingangsadresse"
10+
}
11+
}

app/locales/fr.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "Créer un client",
4+
"host": "Nom d'hôte",
5+
"port": "Port",
6+
"username": "Nom d'utilisateur",
7+
"password": "Mot de passe",
8+
"https": "HTTPS",
9+
"entrance": "Adresse d'entrée"
10+
}
11+
}

app/locales/ja.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "クライアントを作成",
4+
"host": "ホスト名",
5+
"port": "ポート",
6+
"username": "ユーザー名",
7+
"password": "パスワード",
8+
"https": "HTTPS",
9+
"entrance": "入口アドレス"
10+
}
11+
}

app/locales/ko.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "클라이언트 생성",
4+
"host": "호스트 이름",
5+
"port": "포트",
6+
"username": "사용자 이름",
7+
"password": "비밀번호",
8+
"https": "HTTPS",
9+
"entrance": "입구 주소"
10+
}
11+
}

app/locales/nl.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "Klant maken",
4+
"host": "Hostnaam",
5+
"port": "Poort",
6+
"username": "Gebruikersnaam",
7+
"password": "Wachtwoord",
8+
"https": "HTTPS",
9+
"entrance": "Toegangsadres"
10+
}
11+
}

app/locales/ru.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "Создать клиента",
4+
"host": "Имя хоста",
5+
"port": "Порт",
6+
"username": "Имя пользователя",
7+
"password": "Пароль",
8+
"https": "HTTPS",
9+
"entrance": "Адрес входа"
10+
}
11+
}

app/locales/zh-tw.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"label": {
3+
"create-client": "創建客戶端",
4+
"host": "主機名",
5+
"port": "端口",
6+
"username": "用戶名",
7+
"password": "密碼",
8+
"https": "HTTPS",
9+
"entrance": "入口地址"
10+
}
11+
}

nuxt.config.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export default defineNuxtConfig({
2929
},
3030
},
3131
},
32+
ui: {
33+
icons: ['flag'],
34+
},
3235
eslint: {
3336
config: {
3437
stylistic: {
@@ -39,11 +42,18 @@ export default defineNuxtConfig({
3942
},
4043
},
4144
i18n: {
42-
defaultLocale: 'en',
45+
defaultLocale: 'zh-cn',
4346
langDir: 'locales',
4447
locales: [
45-
{ code: 'en', file: 'en.json', name: 'English' },
4648
{ code: 'zh-cn', file: 'zh-cn.json', name: '简体中文' },
49+
{ code: 'zh-tw', file: 'zh-tw.json', name: '繁體中文' },
50+
{ code: 'de', file: 'de.json', name: 'Deutsch' },
51+
{ code: 'en', file: 'en.json', name: 'English' },
52+
{ code: 'fr', file: 'fr.json', name: 'Français' },
53+
{ code: 'ja', file: 'ja.json', name: '日本語' },
54+
{ code: 'ko', file: 'ko.json', name: '한국어' },
55+
{ code: 'nl', file: 'nl.json', name: 'Nederlands' },
56+
{ code: 'ru', file: 'ru.json', name: 'Русский' },
4757
],
4858
strategy: 'no_prefix',
4959
},

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"postinstall": "nuxt prepare"
1515
},
1616
"dependencies": {
17+
"@iconify-json/flag": "^1.1.53",
1718
"@nuxt/eslint": "^0.3.13",
1819
"@nuxt/ui-pro": "^1.3.1",
1920
"@nuxtjs/i18n": "^8.3.1",

pnpm-lock.yaml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)