-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add i18n support * chore: typo in favourite i18n message * chore: remove async * chore: refactor i18n conf and plugin * chore: remove `vueI18n` from nuxt i18n entry * chore: include single and multiple locale files * chore: single es-* json files with wrong content * chore(docs): add i18n support section * chore(docs): add emoji to i18n support section * chore: update `createProvideFunction` * chore: cleanup
- Loading branch information
Showing
27 changed files
with
790 additions
and
31 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,2 @@ | ||
dist | ||
node_modules | ||
templates |
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 +1,2 @@ | ||
shamefully-hoist=true | ||
shamefully-hoist=true | ||
shell-emulator=true |
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,13 @@ | ||
diff --git a/dist/runtime/utils.mjs b/dist/runtime/utils.mjs | ||
index 21f7780ac104abddfd5c8038e1574bc0e3212cf6..b2e7584912c9eede4d152f0ddaeb70ac917ec828 100644 | ||
--- a/dist/runtime/utils.mjs | ||
+++ b/dist/runtime/utils.mjs | ||
@@ -77,7 +77,7 @@ export async function loadInitialMessages(context, messages, options) { | ||
const fallbackLocales = makeFallbackLocaleCodes(fallbackLocale, [defaultLocale, initialLocale]); | ||
await Promise.all(fallbackLocales.map((locale) => loadLocale(context, locale, setter))); | ||
} | ||
- const locales = lazy ? [...(/* @__PURE__ */ new Set()).add(defaultLocale).add(initialLocale)] : localeCodes; | ||
+ const locales = lazy ? localeCodes : [...(/* @__PURE__ */ new Set()).add(defaultLocale).add(initialLocale)]; | ||
await Promise.all(locales.map((locale) => loadLocale(context, locale, setter))); | ||
} | ||
return messages; |
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,12 @@ | ||
import { availableLocales } from './i18n' | ||
|
||
export default defineI18nConfig(() => { | ||
return { | ||
legacy: false, | ||
availableLocales: availableLocales.map(l => l.code), | ||
fallbackLocale: 'en-US', | ||
fallbackWarn: true, | ||
// eslint-disable-next-line @typescript-eslint/comma-dangle | ||
missingWarn: true | ||
} | ||
}) |
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,89 @@ | ||
import type { LocaleObject } from '#i18n' | ||
|
||
const multipleJson = process.env.MULTIPLE_LANG_FILES === 'true' | ||
|
||
const countryLocaleVariants: Record<string, LocaleObject[]> = { | ||
en: [ | ||
// en.json contains en-US translations | ||
{ code: 'en-US', name: 'English (US)' }, | ||
{ code: 'en-GB', name: 'English (UK)' }, | ||
], | ||
es: [ | ||
// es.json contains es-ES translations | ||
// { code: 'es-AR', name: 'Español (Argentina)' }, | ||
// { code: 'es-BO', name: 'Español (Bolivia)' }, | ||
// { code: 'es-CL', name: 'Español (Chile)' }, | ||
// { code: 'es-CO', name: 'Español (Colombia)' }, | ||
// { code: 'es-CR', name: 'Español (Costa Rica)' }, | ||
// { code: 'es-DO', name: 'Español (República Dominicana)' }, | ||
// { code: 'es-EC', name: 'Español (Ecuador)' }, | ||
{ code: 'es-ES', name: 'Español (España)' }, | ||
// TODO: Support es-419, if we include spanish country variants remove also fix on utils/language.ts module | ||
{ code: 'es-419', name: 'Español (Latinoamérica)' }, | ||
// { code: 'es-GT', name: 'Español (Guatemala)' }, | ||
// { code: 'es-HN', name: 'Español (Honduras)' }, | ||
// { code: 'es-MX', name: 'Español (México)' }, | ||
// { code: 'es-NI', name: 'Español (Nicaragua)' }, | ||
// { code: 'es-PA', name: 'Español (Panamá)' }, | ||
// { code: 'es-PE', name: 'Español (Perú)' }, | ||
// { code: 'es-PR', name: 'Español (Puerto Rico)' }, | ||
// { code: 'es-SV', name: 'Español (El Salvador)' }, | ||
// { code: 'es-US', name: 'Español (Estados Unidos)' }, | ||
// { code: 'es-UY', name: 'Español (Uruguay)' }, | ||
// { code: 'es-VE', name: 'Español (Venezuela)' }, | ||
], | ||
} | ||
|
||
const locales: LocaleObject[] = [ | ||
{ | ||
code: 'en', | ||
file: 'en.json', | ||
name: 'English', | ||
}, | ||
{ | ||
code: 'es', | ||
file: 'es.json', | ||
name: 'Español', | ||
}, | ||
] | ||
|
||
function buildLocales() { | ||
const useLocales = Object.values(locales).reduce((acc, data) => { | ||
const locales = countryLocaleVariants[data.code] | ||
if (locales) { | ||
locales.forEach((l) => { | ||
let entry: LocaleObject | ||
if (multipleJson) { | ||
entry = { | ||
...data, | ||
code: l.code, | ||
name: l.name, | ||
files: [data.file!, `${l.code}.json`], | ||
} | ||
delete entry.file | ||
} | ||
else { | ||
entry = { | ||
...data, | ||
code: l.code, | ||
name: l.name, | ||
file: `${l.code}.json`, | ||
} | ||
} | ||
|
||
acc.push(entry) | ||
}) | ||
} | ||
else { | ||
acc.push(data) | ||
} | ||
|
||
return acc | ||
}, <LocaleObject[]>[]) | ||
|
||
return useLocales.sort((a, b) => a.code.localeCompare(b.code)) | ||
} | ||
|
||
export const availableLocales = buildLocales() | ||
|
||
export const langDir = multipleJson ? 'locales/multiple' : 'locales/single' |
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,3 @@ | ||
{ | ||
"xxx": "Favourite" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favorite" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favorite" | ||
} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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,3 @@ | ||
{ | ||
"xxx": "Favorito" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favourite" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favorite" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favorito (es-419)" | ||
} |
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,3 @@ | ||
{ | ||
"xxx": "Favorito (es-ES)" | ||
} |
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.