Skip to content

Commit

Permalink
Convert language codes from RFC-1766 to RFC-4646
Browse files Browse the repository at this point in the history
  • Loading branch information
auroursa committed Dec 21, 2024
1 parent b2f3b62 commit 5cb2fd7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lingui.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module.exports = {
'tr',
'uk',
'vi',
'yue',
'zh-CN',
'zh-HK',
'zh-TW',
],
catalogs: [
Expand Down
6 changes: 3 additions & 3 deletions src/components/hooks/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const locales: Record<AppLanguage, Locale | undefined> = {
tr,
uk,
vi,
['zh-CN']: zhCN,
['zh-HK']: zhHK,
['zh-TW']: zhTW,
['yue']: zhHK,
['zh-Hans-CN']: zhCN,
['zh-Hant-TW']: zhTW,
}

/**
Expand Down
24 changes: 13 additions & 11 deletions src/locale/deviceLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type LocalWithLanguageCode = Locale & {
* {@link https://github.com/bluesky-social/social-app/pull/4461}
* {@link https://xml.coverpages.org/iso639a.html}
*
* Convert Chinese language tags for Native.
* Convert Chinese language tags for Web (RFC 1766 to RFC 4646).
*
* {@link https://datatracker.ietf.org/doc/html/rfc5646#appendix-A}
* {@link https://developer.apple.com/documentation/packagedescription/languagetag}
Expand All @@ -41,17 +41,19 @@ export function getLocales() {
}

if (typeof locale.languageTag === 'string') {
if (locale.languageTag.startsWith('zh-Hans')) {
// Simplified Chinese to zh-CN
locale.languageTag = 'zh-CN'
if (
locale.languageTag === 'zh-CN' ||
locale.languageTag.startsWith('zh-Hans')
) {
// Simplified Chinese to zh-Hans-CN
locale.languageTag = 'zh-Hans-CN'
}
if (locale.languageTag.startsWith('zh-Hant')) {
// Traditional Chinese to zh-TW
locale.languageTag = 'zh-TW'
}
if (locale.languageTag.startsWith('yue')) {
// Cantonese (Yue) to zh-HK
locale.languageTag = 'zh-HK'
if (
locale.languageTag === 'zh-TW' ||
locale.languageTag.startsWith('zh-Hant')
) {
// Traditional Chinese to zh-Hant-TW
locale.languageTag = 'zh-Hant-TW'
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/locale/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ export function sanitizeAppLanguageSetting(appLanguage: string): AppLanguage {
return AppLanguage.uk
case 'vi':
return AppLanguage.vi
case 'zh-CN':
case 'yue':
return AppLanguage.yue
case 'zh-Hans-CN':
return AppLanguage.zh_CN
case 'zh-HK':
return AppLanguage.zh_HK
case 'zh-TW':
case 'zh-Hant-TW':
return AppLanguage.zh_TW
default:
continue
Expand Down
10 changes: 5 additions & 5 deletions src/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {messages as messagesTh} from '#/locale/locales/th/messages'
import {messages as messagesTr} from '#/locale/locales/tr/messages'
import {messages as messagesUk} from '#/locale/locales/uk/messages'
import {messages as messagesVi} from '#/locale/locales/vi/messages'
import {messages as messagesYue} from '#/locale/locales/yue/messages'
import {messages as messagesZh_CN} from '#/locale/locales/zh-CN/messages'
import {messages as messagesZh_HK} from '#/locale/locales/zh-HK/messages'
import {messages as messagesZh_TW} from '#/locale/locales/zh-TW/messages'
import {useLanguagePrefs} from '#/state/preferences'

Expand Down Expand Up @@ -261,16 +261,16 @@ export async function dynamicActivate(locale: AppLanguage) {
])
break
}
case AppLanguage.zh_CN: {
i18n.loadAndActivate({locale, messages: messagesZh_CN})
case AppLanguage.yue: {
i18n.loadAndActivate({locale, messages: messagesYue})
await Promise.all([
import('@formatjs/intl-pluralrules/locale-data/zh'),
import('@formatjs/intl-numberformat/locale-data/zh'),
])
break
}
case AppLanguage.zh_HK: {
i18n.loadAndActivate({locale, messages: messagesZh_HK})
case AppLanguage.zh_CN: {
i18n.loadAndActivate({locale, messages: messagesZh_CN})
await Promise.all([
import('@formatjs/intl-pluralrules/locale-data/zh'),
import('@formatjs/intl-numberformat/locale-data/zh'),
Expand Down
8 changes: 4 additions & 4 deletions src/locale/i18n.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ export async function dynamicActivate(locale: AppLanguage) {
mod = await import(`./locales/vi/messages`)
break
}
case AppLanguage.zh_CN: {
mod = await import(`./locales/zh-CN/messages`)
case AppLanguage.yue: {
mod = await import(`./locales/yue/messages`)
break
}
case AppLanguage.zh_HK: {
mod = await import(`./locales/zh-HK/messages`)
case AppLanguage.zh_CN: {
mod = await import(`./locales/zh-CN/messages`)
break
}
case AppLanguage.zh_TW: {
Expand Down
8 changes: 4 additions & 4 deletions src/locale/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export enum AppLanguage {
tr = 'tr',
uk = 'uk',
vi = 'vi',
zh_CN = 'zh-CN',
zh_HK = 'zh-HK',
zh_TW = 'zh-TW',
yue = 'yue',
zh_CN = 'zh-Hans-CN',
zh_TW = 'zh-Hant-TW',
}

interface AppLanguageConfig {
Expand Down Expand Up @@ -72,9 +72,9 @@ export const APP_LANGUAGES: AppLanguageConfig[] = [
{code2: AppLanguage.tr, name: 'Türkçe – Turkish'},
{code2: AppLanguage.uk, name: 'Українська – Ukrainian'},
{code2: AppLanguage.vi, name: 'Tiếng Việt – Vietnamese'},
{code2: AppLanguage.yue, name: '粵文 – Cantonese'},
{code2: AppLanguage.zh_CN, name: '简体中文 – Simplified Chinese'},
{code2: AppLanguage.zh_TW, name: '繁體中文 – Traditional Chinese'},
{code2: AppLanguage.zh_HK, name: '粵文 – Cantonese'},
]

export const LANGUAGES: Language[] = [
Expand Down
File renamed without changes.

0 comments on commit 5cb2fd7

Please sign in to comment.