forked from ashkanm04/it-tools
-
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.
chore(i18n): tool scoped locales (CorentinTh#471)
- Loading branch information
1 parent
ec4c533
commit 1b038c7
Showing
6 changed files
with
35 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
home: | ||
categories: | ||
newestTools: "Newest tools" | ||
newestTools: Newest tools | ||
|
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,50 +1,15 @@ | ||
import type { App } from 'vue'; | ||
import { createI18n } from 'vue-i18n'; | ||
import type { Locale } from 'vue-i18n'; | ||
import messages from '@intlify/unplugin-vue-i18n/messages'; | ||
|
||
const i18n = createI18n({ | ||
legacy: false, | ||
locale: '', | ||
messages: {}, | ||
locale: 'en', | ||
messages, | ||
}); | ||
|
||
const localesMap = Object.fromEntries( | ||
Object.entries(import.meta.glob('../../locales/*.yml')) | ||
.map(([path, loadLocale]) => [path.match(/([\w-]*)\.yml$/)?.[1], loadLocale]), | ||
) as Record<Locale, () => Promise<{ default: Record<string, string> }>>; | ||
|
||
export const availableLocales = Object.keys(localesMap); | ||
|
||
const loadedLanguages: string[] = []; | ||
|
||
function setI18nLanguage(lang: Locale) { | ||
i18n.global.locale.value = lang as any; | ||
if (typeof document !== 'undefined') { | ||
document.querySelector('html')?.setAttribute('lang', lang); | ||
} | ||
return lang; | ||
} | ||
|
||
export async function loadLanguageAsync(lang: string): Promise<Locale> { | ||
if (i18n.global.locale.value === lang) { | ||
return setI18nLanguage(lang); | ||
} | ||
|
||
if (loadedLanguages.includes(lang)) { | ||
return setI18nLanguage(lang); | ||
} | ||
|
||
const messages = await localesMap[lang](); | ||
|
||
i18n.global.setLocaleMessage(lang, messages.default); | ||
loadedLanguages.push(lang); | ||
|
||
return setI18nLanguage(lang); | ||
} | ||
|
||
export const i18nPlugin = { | ||
install: (app: App) => { | ||
app.use(i18n); | ||
loadLanguageAsync('en'); | ||
}, | ||
}; |
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,9 @@ | ||
tools: | ||
token-generator: | ||
title: Token generator | ||
description: Generate random string with the chars you want, uppercase or lowercase letters, numbers and/or symbols. | ||
|
||
uppercase: Uppercase (ABC...) | ||
lowercase: Lowercase (abc...) | ||
numbers: Numbers (123...) | ||
symbols: Symbols (!-;...) |
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,9 @@ | ||
tools: | ||
token-generator: | ||
title: Générateur de token | ||
description: Génère une chaîne aléatoire avec les caractères que vous voulez, lettres majuscules ou minuscules, chiffres et/ou symboles. | ||
|
||
uppercase: Majuscules (ABC...) | ||
lowercase: Minuscules (abc...) | ||
numbers: Chiffres (123...) | ||
symbols: Symboles (!-;...) |
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