diff options
author | Eric Bailey <git@esb.lol> | 2024-09-20 10:50:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 10:50:33 -0500 |
commit | fa6f6f9e473a0dd731ea95210fbd66e0b8c0c283 (patch) | |
tree | 1c5166f9b31d3b4967fcf8cd8cdb969d2efa92cb /src/locale/helpers.ts | |
parent | cd88cbeab83169410fff3245505b53122dfe28aa (diff) | |
download | voidsky-fa6f6f9e473a0dd731ea95210fbd66e0b8c0c283.tar.zst |
Language fixes (#5384)
* Add some comments * Decouple language settings * Normalize on read/write * Refactor * Support device locale on app startup * Cleanup, port to web * Clean up comments * Comment * Try not to mutate * Protect util handling, update test * Dedupe array values
Diffstat (limited to 'src/locale/helpers.ts')
-rw-r--r-- | src/locale/helpers.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/locale/helpers.ts b/src/locale/helpers.ts index 3bae45214..a7517eae9 100644 --- a/src/locale/helpers.ts +++ b/src/locale/helpers.ts @@ -160,8 +160,13 @@ export function sanitizeAppLanguageSetting(appLanguage: string): AppLanguage { return AppLanguage.en } +/** + * Handles legacy migration for Java devices. + * + * {@link https://github.com/bluesky-social/social-app/pull/4461} + * {@link https://xml.coverpages.org/iso639a.html} + */ export function fixLegacyLanguageCode(code: string | null): string | null { - // handle some legacy code conversions, see https://xml.coverpages.org/iso639a.html if (code === 'in') { // indonesian return 'id' @@ -176,3 +181,20 @@ export function fixLegacyLanguageCode(code: string | null): string | null { } return code } + +/** + * Find the first language supported by our translation infra. Values should be + * in order of preference, and match the values of {@link AppLanguage}. + * + * If no match, returns `en`. + */ +export function findSupportedAppLanguage(languageTags: (string | undefined)[]) { + const supported = new Set(Object.values(AppLanguage)) + for (const tag of languageTags) { + if (!tag) continue + if (supported.has(tag as AppLanguage)) { + return tag + } + } + return AppLanguage.en +} |