Skip to content

Commit b0139f0

Browse files
hywaxbenjamincanac
andauthored
feat(locale): add English (United Kingdom) language (#5561)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent b09e6bc commit b0139f0

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

docs/app/components/content/SupportedLanguages.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getEmojiFlag(locale: string): string {
1616
cs: 'cz', // Czech -> Czech Republic (note: modern country code is actually 'cz')
1717
da: 'dk', // Danish -> Denmark
1818
el: 'gr', // Greek -> Greece
19-
en: 'gb', // English -> Great Britain
19+
en: 'us', // English -> United States (default)
2020
et: 'ee', // Estonian -> Estonia
2121
gl: 'es', // Galician -> Spain
2222
he: 'il', // Hebrew -> Israel
@@ -40,8 +40,20 @@ function getEmojiFlag(locale: string): string {
4040
vi: 'vn' // Vietnamese -> Vietnam
4141
}
4242
43+
// If locale has a country code (e.g., en-GB), extract and use it
44+
if (locale.includes('-')) {
45+
const countryCode = locale.split('-')[1]?.toLowerCase()
46+
if (countryCode) {
47+
return countryCode.toUpperCase()
48+
.split('')
49+
.map(char => String.fromCodePoint(0x1F1A5 + char.charCodeAt(0)))
50+
.join('')
51+
}
52+
}
53+
54+
// Otherwise, use the language-to-country mapping
4355
const baseLanguage = locale.split('-')[0]?.toLowerCase() || locale
44-
const countryCode = languageToCountry[baseLanguage] || locale.replace(/^.*-/, '').slice(0, 2)
56+
const countryCode = languageToCountry[baseLanguage] || locale.slice(0, 2)
4557
4658
return countryCode.toUpperCase()
4759
.split('')

src/runtime/components/locale/LocaleSelect.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function getEmojiFlag(locale: string): string {
3333
cs: 'cz', // Czech -> Czech Republic (note: modern country code is actually 'cz')
3434
da: 'dk', // Danish -> Denmark
3535
el: 'gr', // Greek -> Greece
36-
en: 'gb', // English -> Great Britain
36+
en: 'us', // English -> United States (default)
3737
et: 'ee', // Estonian -> Estonia
3838
gl: 'es', // Galician -> Spain
3939
he: 'il', // Hebrew -> Israel
@@ -56,8 +56,20 @@ function getEmojiFlag(locale: string): string {
5656
vi: 'vn' // Vietnamese -> Vietnam
5757
}
5858
59+
// If locale has a country code (e.g., en-GB), extract and use it
60+
if (locale.includes('-')) {
61+
const countryCode = locale.split('-')[1]?.toLowerCase()
62+
if (countryCode) {
63+
return countryCode.toUpperCase()
64+
.split('')
65+
.map(char => String.fromCodePoint(0x1F1A5 + char.charCodeAt(0)))
66+
.join('')
67+
}
68+
}
69+
70+
// Otherwise, use the language-to-country mapping
5971
const baseLanguage = locale.split('-')[0]?.toLowerCase() || locale
60-
const countryCode = languageToCountry[baseLanguage] || locale.replace(/^.*-/, '').slice(0, 2)
72+
const countryCode = languageToCountry[baseLanguage] || locale.slice(0, 2)
6173
6274
return countryCode.toUpperCase()
6375
.split('')

src/runtime/locale/en_gb.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Messages } from '../types'
2+
import { defineLocale } from '../composables/defineLocale'
3+
import en from './en'
4+
5+
export default defineLocale<Messages>({
6+
name: 'English (United Kingdom)',
7+
code: 'en-GB',
8+
messages: en.messages
9+
})

src/runtime/locale/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { default as de } from './de'
1010
export { default as de_ch } from './de_ch'
1111
export { default as el } from './el'
1212
export { default as en } from './en'
13+
export { default as en_gb } from './en_gb'
1314
export { default as es } from './es'
1415
export { default as et } from './et'
1516
export { default as fa_ir } from './fa_ir'

0 commit comments

Comments
 (0)