Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Chinese & Cantonese localization #7174

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lingui.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ module.exports = {
'tr',
'uk',
'vi',
'zh-CN',
'zh-HK',
'zh-TW',
'yue',
'zh-Hans-CN',
'zh-Hant-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
22 changes: 14 additions & 8 deletions src/locale/deviceLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ 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' ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure browser compatibility, as browsers still widely use RFC-1766.

locale.languageTag.startsWith('zh-Hans')
Copy link
Contributor Author

@auroursa auroursa Dec 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple zh-Hans / zh-Hant variants on iOS and Android, such as zh-Hans-SG. We want to match as many of these language variants as possible.

) {
// Simplified Chinese to zh-Hans
locale.languageTag = 'zh-Hans-CN'
}
if (locale.languageTag.startsWith('zh-Hant')) {
// Traditional Chinese to zh-TW
locale.languageTag = 'zh-TW'
if (
locale.languageTag === 'zh-TW' ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reason as above—browser compatibility.

locale.languageTag.startsWith('zh-Hant')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

) {
// Traditional Chinese to zh-Hant
locale.languageTag = 'zh-Hant-TW'
}
if (locale.languageTag.startsWith('yue')) {
// Cantonese (Yue) to zh-HK
locale.languageTag = 'zh-HK'
// Cantonese (Yue) to yue
locale.languageTag = 'yue'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the two variants on Android and iOS:
yue-Hans and yue-Hant.

Not using yue-Hant directly due to poor browser compatibility.

}
}

Expand Down
12 changes: 6 additions & 6 deletions src/locale/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ export function sanitizeAppLanguageSetting(appLanguage: string): AppLanguage {
return AppLanguage.uk
case 'vi':
return AppLanguage.vi
case 'zh-CN':
return AppLanguage.zh_CN
case 'zh-HK':
return AppLanguage.zh_HK
case 'zh-TW':
return AppLanguage.zh_TW
case 'yue':
return AppLanguage.yue
case 'zh-Hans-CN':
return AppLanguage.zh_Hans_CN
case 'zh-Hant-TW':
return AppLanguage.zh_Hant_TW
default:
continue
}
Expand Down
18 changes: 9 additions & 9 deletions src/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ 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 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 {messages as messagesYue} from '#/locale/locales/yue/messages'
import {messages as messagesZh_Hans_CN} from '#/locale/locales/zh-Hans-CN/messages'
import {messages as messagesZh_Hant_TW} from '#/locale/locales/zh-Hant-TW/messages'
import {useLanguagePrefs} from '#/state/preferences'

/**
Expand Down Expand Up @@ -261,24 +261,24 @@ 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_Hans_CN: {
i18n.loadAndActivate({locale, messages: messagesZh_Hans_CN})
await Promise.all([
import('@formatjs/intl-pluralrules/locale-data/zh'),
import('@formatjs/intl-numberformat/locale-data/zh'),
])
break
}
case AppLanguage.zh_TW: {
i18n.loadAndActivate({locale, messages: messagesZh_TW})
case AppLanguage.zh_Hant_TW: {
i18n.loadAndActivate({locale, messages: messagesZh_Hant_TW})
await Promise.all([
import('@formatjs/intl-pluralrules/locale-data/zh'),
import('@formatjs/intl-numberformat/locale-data/zh'),
Expand Down
12 changes: 6 additions & 6 deletions src/locale/i18n.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ 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_Hans_CN: {
mod = await import(`./locales/zh-Hans-CN/messages`)
break
}
case AppLanguage.zh_TW: {
mod = await import(`./locales/zh-TW/messages`)
case AppLanguage.zh_Hant_TW: {
mod = await import(`./locales/zh-Hant-TW/messages`)
break
}
default: {
Expand Down
12 changes: 6 additions & 6 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_Hans_CN = 'zh-Hans-CN',
zh_Hant_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.zh_CN, name: '简体中文Simplified Chinese'},
{code2: AppLanguage.zh_TW, name: '繁體中文Traditional Chinese'},
{code2: AppLanguage.zh_HK, name: '粵文Cantonese'},
{code2: AppLanguage.yue, name: '粵文Cantonese'},
{code2: AppLanguage.zh_Hans_CN, name: '简体中文Simplified Chinese'},
{code2: AppLanguage.zh_Hant_TW, name: '繁體中文Traditional Chinese'},
]

export const LANGUAGES: Language[] = [
Expand Down
Loading