From 23dc1cd48307359b1b78b2f68ae7f398c3e5133d Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 19 Mar 2021 15:32:17 +0100 Subject: [PATCH] refactor(i18n): change locale files to yaml format, closes #96 (#97) --- locales/README.md | 2 +- locales/en.json | 17 ----------------- locales/en.yml | 13 +++++++++++++ locales/es.json | 17 ----------------- locales/es.yml | 13 +++++++++++++ locales/fr.json | 17 ----------------- locales/fr.yml | 13 +++++++++++++ locales/it.json | 17 ----------------- locales/it.yml | 13 +++++++++++++ locales/ja.json | 17 ----------------- locales/ja.yml | 13 +++++++++++++ locales/ko.json | 17 ----------------- locales/ko.yml | 14 ++++++++++++++ locales/pt-BR.json | 17 ----------------- locales/pt-BR.yml | 13 +++++++++++++ locales/tr.json | 17 ----------------- locales/tr.yml | 13 +++++++++++++ locales/vi.json | 13 ------------- locales/vi.yml | 13 +++++++++++++ locales/zh-CN.json | 17 ----------------- locales/zh-CN.yml | 13 +++++++++++++ src/modules/i18n.ts | 5 +++-- 22 files changed, 135 insertions(+), 169 deletions(-) delete mode 100644 locales/en.json create mode 100644 locales/en.yml delete mode 100644 locales/es.json create mode 100644 locales/es.yml delete mode 100644 locales/fr.json create mode 100644 locales/fr.yml delete mode 100644 locales/it.json create mode 100644 locales/it.yml delete mode 100644 locales/ja.json create mode 100644 locales/ja.yml delete mode 100644 locales/ko.json create mode 100644 locales/ko.yml delete mode 100644 locales/pt-BR.json create mode 100644 locales/pt-BR.yml delete mode 100644 locales/tr.json create mode 100644 locales/tr.yml delete mode 100644 locales/vi.json create mode 100644 locales/vi.yml delete mode 100644 locales/zh-CN.json create mode 100644 locales/zh-CN.yml diff --git a/locales/README.md b/locales/README.md index 2a11e87..4b24ec2 100644 --- a/locales/README.md +++ b/locales/README.md @@ -1,6 +1,6 @@ ## i18n -This directory is to serve your locale translation files. JSON under this folder would be loaded automatically and register with their filenames as locale code. +This directory is to serve your locale translation files. YAML under this folder would be loaded automatically and register with their filenames as locale code. Check out [`vue-i18n`](https://github.com/intlify/vue-i18n-next) for more details. diff --git a/locales/en.json b/locales/en.json deleted file mode 100644 index 5b0bcb4..0000000 --- a/locales/en.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "About", - "back": "Back", - "go": "GO", - "home": "Home", - "toggle_dark": "Toggle dark mode", - "toggle_langs": "Change languages" - }, - "intro": { - "desc": "Opinionated Vite Starter Template", - "dynamic-route": "Demo of dynamic route", - "hi": "Hi, {name}!", - "whats-your-name": "What's your name?" - }, - "not-found": "Not found" -} diff --git a/locales/en.yml b/locales/en.yml new file mode 100644 index 0000000..2af2f90 --- /dev/null +++ b/locales/en.yml @@ -0,0 +1,13 @@ +button: + about: About + back: Back + go: GO + home: Home + toggle_dark: Toggle dark mode + toggle_langs: Change languages +intro: + desc: Opinionated Vite Starter Template + dynamic-route: Demo of dynamic route + hi: Hi, {name}! + whats-your-name: What's your name? +not-found: Not found diff --git a/locales/es.json b/locales/es.json deleted file mode 100644 index b00bc5d..0000000 --- a/locales/es.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "Acerca de", - "back": "Atrás", - "go": "Ir", - "home": "Inicio", - "toggle_dark": "Alternar modo oscuro", - "toggle_langs": "Cambiar idiomas" - }, - "intro": { - "desc": "Plantilla de Inicio de Vite Dogmática", - "dynamic-route": "Demo de ruta dinámica", - "hi": "¡Hola, {name}!", - "whats-your-name": "¿Cómo te llamas?" - }, - "not-found": "No se ha encontrado" -} diff --git a/locales/es.yml b/locales/es.yml new file mode 100644 index 0000000..a41b3f9 --- /dev/null +++ b/locales/es.yml @@ -0,0 +1,13 @@ +button: + about: Acerca de + back: Atrás + go: Ir + home: Inicio + toggle_dark: Alternar modo oscuro + toggle_langs: Cambiar idiomas +intro: + desc: Plantilla de Inicio de Vite Dogmática + dynamic-route: Demo de ruta dinámica + hi: ¡Hola, {name}! + whats-your-name: ¿Cómo te llamas? +not-found: No se ha encontrado diff --git a/locales/fr.json b/locales/fr.json deleted file mode 100644 index 048cf1e..0000000 --- a/locales/fr.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "À propos de", - "back": "Retour", - "go": "Essayer", - "home": "Maison", - "toggle_dark": "Basculer en mode sombre", - "toggle_langs": "Changer de langue" - }, - "intro": { - "desc": "Example d'application Vite", - "dynamic-route": "Démo de route dynamique", - "hi": "Salut, {name} !", - "whats-your-name": "Comment t'appelles-tu ?" - }, - "not-found": "Page non trouvée" -} diff --git a/locales/fr.yml b/locales/fr.yml new file mode 100644 index 0000000..f90b667 --- /dev/null +++ b/locales/fr.yml @@ -0,0 +1,13 @@ +button: + about: À propos de + back: Retour + go: Essayer + home: Maison + toggle_dark: Basculer en mode sombre + toggle_langs: Changer de langue +intro: + desc: Example d'application Vite + dynamic-route: Démo de route dynamique + hi: Salut, {name}! + whats-your-name: Comment t'appelles-tu? +not-found: Page non trouvée diff --git a/locales/it.json b/locales/it.json deleted file mode 100644 index dc6d5bb..0000000 --- a/locales/it.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "Su di me", - "back": "Indietro", - "go": "Vai", - "home": "Home", - "toggle_dark": "Attiva/disattiva modalità scura", - "toggle_langs": "Cambia lingua" - }, - "intro": { - "desc": "Modello per una Applicazione Vite", - "dynamic-route": "Demo di rotta dinamica", - "hi": "Ciao, {name}!", - "whats-your-name": "Come ti chiami?" - }, - "not-found": "Non trovato" -} diff --git a/locales/it.yml b/locales/it.yml new file mode 100644 index 0000000..fa0d988 --- /dev/null +++ b/locales/it.yml @@ -0,0 +1,13 @@ +button: + about: Su di me + back: Indietro + go: Vai + home: Home + toggle_dark: Attiva/disattiva modalità scura + toggle_langs: Cambia lingua +intro: + desc: Modello per una Applicazione Vite + dynamic-route: Demo di rotta dinamica + hi: Ciao, {name}! + whats-your-name: Come ti chiami? +not-found: Non trovato diff --git a/locales/ja.json b/locales/ja.json deleted file mode 100644 index 8556da0..0000000 --- a/locales/ja.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "これは?", - "back": "戻る", - "go": "進む", - "home": "ホーム", - "toggle_dark": "ダークモード切り替え", - "toggle_langs": "言語切り替え" - }, - "intro": { - "desc": "固執された Vite スターターテンプレート", - "dynamic-route": "動的ルートのデモ", - "hi": "こんにちは、{name}!", - "whats-your-name": "あなたの名前は?" - }, - "not-found": "見つかりませんでした" -} diff --git a/locales/ja.yml b/locales/ja.yml new file mode 100644 index 0000000..127327b --- /dev/null +++ b/locales/ja.yml @@ -0,0 +1,13 @@ +button: + about: これは? + back: 戻る + go: 進む + home: ホーム + toggle_dark: ダークモード切り替え + toggle_langs: 言語切り替え +intro: + desc: 固執された Vite スターターテンプレート + dynamic-route: 動的ルートのデモ + hi: こんにちは、{name}! + whats-your-name: あなたの名前は? +not-found: 見つかりませんでした diff --git a/locales/ko.json b/locales/ko.json deleted file mode 100644 index 318c10d..0000000 --- a/locales/ko.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "소개", - "back": "뒤로가기", - "go": "이동", - "home": "홈", - "toggle_dark": "다크모드 토글", - "toggle_langs": "언어 변경" - }, - "intro": { - "desc": "Vite 애플리케이션 템플릿", - "dynamic-route": "다이나믹 라우트 데모", - "hi": "안녕, {name}!", - "whats-your-name": "이름이 뭐예요?" - }, - "not-found": "찾을 수 없습니다" -} diff --git a/locales/ko.yml b/locales/ko.yml new file mode 100644 index 0000000..b7a9042 --- /dev/null +++ b/locales/ko.yml @@ -0,0 +1,14 @@ +button: + about: 소개 + back: 뒤로가기 + go: 이동 + home: 홈 + toggle_dark: 다크모드 토글 + toggle_langs: 언어 변경 +intro: + desc: Vite 애플리케이션 템플릿 + dynamic-route: 다이나믹 라우트 데모 + hi: 안녕, {name}! + whats-your-name: 이름이 뭐예요? +not-found: 찾을 수 없습니다 + diff --git a/locales/pt-BR.json b/locales/pt-BR.json deleted file mode 100644 index d870c58..0000000 --- a/locales/pt-BR.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "Sobre", - "back": "Voltar", - "go": "Ir", - "home": "Início", - "toggle_dark": "Alternar modo escuro", - "toggle_langs": "Mudar de idioma" - }, - "intro": { - "desc": "Modelo Opinativo de Partida de Vite", - "dynamic-route": "Demonstração de rota dinâmica", - "hi": "Olá, {name}!", - "whats-your-name": "Qual é o seu nome?" - }, - "not-found": "Não encontrado" -} diff --git a/locales/pt-BR.yml b/locales/pt-BR.yml new file mode 100644 index 0000000..4c080cd --- /dev/null +++ b/locales/pt-BR.yml @@ -0,0 +1,13 @@ +button: + about: Sobre + back: Voltar + go: Ir + home: Início + toggle_dark: Alternar modo escuro + toggle_langs: Mudar de idioma +intro: + desc: Modelo Opinativo de Partida de Vite + dynamic-route: Demonstração de rota dinâmica + hi: Olá, {name}! + whats-your-name: Qual é o seu nome? +not-found: Não encontrado diff --git a/locales/tr.json b/locales/tr.json deleted file mode 100644 index c954660..0000000 --- a/locales/tr.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "Hakkımda", - "back": "Geri", - "go": "İLERİ", - "home": "Anasayfa", - "toggle_dark": "Karanlık modu değiştir", - "toggle_langs": "Dilleri değiştir" - }, - "intro": { - "desc": "Görüşlü Vite Başlangıç Şablonu", - "dynamic-route": "Dinamik rota demosu", - "hi": "Merhaba, {name}!", - "whats-your-name": "Adınız nedir ?" - }, - "not-found": "Bulunamadı" -} diff --git a/locales/tr.yml b/locales/tr.yml new file mode 100644 index 0000000..8787c6f --- /dev/null +++ b/locales/tr.yml @@ -0,0 +1,13 @@ +button: + about: Hakkımda + back: Geri + go: İLERİ + home: Anasayfa + toggle_dark: Karanlık modu değiştir + toggle_langs: Dilleri değiştir +intro: + desc: Görüşlü Vite Başlangıç Şablonu + dynamic-route: Dinamik rota demosu + hi: Merhaba, {name}! + whats-your-name: Adınız nedir? +not-found: Bulunamadı diff --git a/locales/vi.json b/locales/vi.json deleted file mode 100644 index 019abaf..0000000 --- a/locales/vi.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "button": { - "back": "Quay lại", - "go": "Đi" - }, - "intro": { - "desc": "Ý kiến cá nhân Vite Template để bắt đầu", - "dynamic-route": "Bản giới thiệu về dynamic route", - "hi": "Hi, {name}!", - "whats-your-name": "Tên bạn là gì?" - }, - "not-found": "Không tìm thấy" -} diff --git a/locales/vi.yml b/locales/vi.yml new file mode 100644 index 0000000..ba2322e --- /dev/null +++ b/locales/vi.yml @@ -0,0 +1,13 @@ +button: + about: Về + back: Quay lại + go: Đi + home: Khởi đầu + toggle_dark: Chuyển đổi chế độ tối + toggle_langs: Thay đổi ngôn ngữ +intro: + desc: Ý kiến cá nhân Vite Template để bắt đầu + dynamic-route: Bản giới thiệu về dynamic route + hi: Hi, {name}! + whats-your-name: Tên bạn là gì? +not-found: Không tìm thấy diff --git a/locales/zh-CN.json b/locales/zh-CN.json deleted file mode 100644 index a47d4c7..0000000 --- a/locales/zh-CN.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "button": { - "about": "关于", - "back": "返回", - "go": "确定", - "home": "首页", - "toggle_dark": "切换深色模式", - "toggle_langs": "切换语言" - }, - "intro": { - "desc": "固执己见的 Vite 项目模板", - "dynamic-route": "动态路由演示", - "hi": "你好,{name}!", - "whats-your-name": "输入你的名字" - }, - "not-found": "未找到页面" -} diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml new file mode 100644 index 0000000..14fe490 --- /dev/null +++ b/locales/zh-CN.yml @@ -0,0 +1,13 @@ +button: + about: 关于 + back: 返回 + go: 确定 + home: 首页 + toggle_dark: 切换深色模式 + toggle_langs: 切换语言 +intro: + desc: 固执己见的 Vite 项目模板 + dynamic-route: 动态路由演示 + hi: 你好,{name} + whats-your-name: 输入你的名字 +not-found: 未找到页面 diff --git a/src/modules/i18n.ts b/src/modules/i18n.ts index ef6f0b1..dfd2229 100644 --- a/src/modules/i18n.ts +++ b/src/modules/i18n.ts @@ -5,9 +5,10 @@ import { UserModule } from '~/types' // https://vitejs.dev/guide/features.html#glob-import const messages = Object.fromEntries( Object.entries( - import.meta.globEager('../../locales/*.json')) + import.meta.globEager('../../locales/*.y(a)?ml')) .map(([key, value]) => { - return [key.slice(14, -5), value.default] + const yaml = key.endsWith('.yaml') + return [key.slice(14, yaml ? -5 : -4), value.default] }), )