diff --git a/docs/app/components/content/SupportedLanguages.vue b/docs/app/components/content/SupportedLanguages.vue index 2d3bd61c5d..c5261bf4b5 100644 --- a/docs/app/components/content/SupportedLanguages.vue +++ b/docs/app/components/content/SupportedLanguages.vue @@ -16,7 +16,7 @@ function getEmojiFlag(locale: string): string { cs: 'cz', // Czech -> Czech Republic (note: modern country code is actually 'cz') da: 'dk', // Danish -> Denmark el: 'gr', // Greek -> Greece - en: 'gb', // English -> Great Britain + en: 'us', // English -> United States (default) et: 'ee', // Estonian -> Estonia gl: 'es', // Galician -> Spain he: 'il', // Hebrew -> Israel @@ -40,8 +40,20 @@ function getEmojiFlag(locale: string): string { vi: 'vn' // Vietnamese -> Vietnam } + // If locale has a country code (e.g., en-GB), extract and use it + if (locale.includes('-')) { + const countryCode = locale.split('-')[1]?.toLowerCase() + if (countryCode) { + return countryCode.toUpperCase() + .split('') + .map(char => String.fromCodePoint(0x1F1A5 + char.charCodeAt(0))) + .join('') + } + } + + // Otherwise, use the language-to-country mapping const baseLanguage = locale.split('-')[0]?.toLowerCase() || locale - const countryCode = languageToCountry[baseLanguage] || locale.replace(/^.*-/, '').slice(0, 2) + const countryCode = languageToCountry[baseLanguage] || locale.slice(0, 2) return countryCode.toUpperCase() .split('') diff --git a/src/runtime/components/locale/LocaleSelect.vue b/src/runtime/components/locale/LocaleSelect.vue index 550360c368..1cadb3af02 100644 --- a/src/runtime/components/locale/LocaleSelect.vue +++ b/src/runtime/components/locale/LocaleSelect.vue @@ -33,7 +33,7 @@ function getEmojiFlag(locale: string): string { cs: 'cz', // Czech -> Czech Republic (note: modern country code is actually 'cz') da: 'dk', // Danish -> Denmark el: 'gr', // Greek -> Greece - en: 'gb', // English -> Great Britain + en: 'us', // English -> United States (default) et: 'ee', // Estonian -> Estonia gl: 'es', // Galician -> Spain he: 'il', // Hebrew -> Israel @@ -56,8 +56,20 @@ function getEmojiFlag(locale: string): string { vi: 'vn' // Vietnamese -> Vietnam } + // If locale has a country code (e.g., en-GB), extract and use it + if (locale.includes('-')) { + const countryCode = locale.split('-')[1]?.toLowerCase() + if (countryCode) { + return countryCode.toUpperCase() + .split('') + .map(char => String.fromCodePoint(0x1F1A5 + char.charCodeAt(0))) + .join('') + } + } + + // Otherwise, use the language-to-country mapping const baseLanguage = locale.split('-')[0]?.toLowerCase() || locale - const countryCode = languageToCountry[baseLanguage] || locale.replace(/^.*-/, '').slice(0, 2) + const countryCode = languageToCountry[baseLanguage] || locale.slice(0, 2) return countryCode.toUpperCase() .split('') diff --git a/src/runtime/locale/en_gb.ts b/src/runtime/locale/en_gb.ts new file mode 100644 index 0000000000..4298c0a9e5 --- /dev/null +++ b/src/runtime/locale/en_gb.ts @@ -0,0 +1,9 @@ +import type { Messages } from '../types' +import { defineLocale } from '../composables/defineLocale' +import en from './en' + +export default defineLocale({ + name: 'English (United Kingdom)', + code: 'en-GB', + messages: en.messages +}) diff --git a/src/runtime/locale/index.ts b/src/runtime/locale/index.ts index 94b80fccf2..e60a19ac6d 100644 --- a/src/runtime/locale/index.ts +++ b/src/runtime/locale/index.ts @@ -10,6 +10,7 @@ export { default as de } from './de' export { default as de_ch } from './de_ch' export { default as el } from './el' export { default as en } from './en' +export { default as en_gb } from './en_gb' export { default as es } from './es' export { default as et } from './et' export { default as fa_ir } from './fa_ir'