diff options
Diffstat (limited to 'src/state/persisted/schema.ts')
-rw-r--r-- | src/state/persisted/schema.ts | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 331a111a2..804017949 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -1,7 +1,8 @@ import {z} from 'zod' +import {deviceLanguageCodes, deviceLocales} from '#/locale/deviceLocales' +import {findSupportedAppLanguage} from '#/locale/helpers' import {logger} from '#/logger' -import {deviceLocales} from '#/platform/detection' import {PlatformInfo} from '../../../modules/expo-bluesky-swiss-army' const externalEmbedOptions = ['show', 'hide'] as const @@ -55,10 +56,39 @@ const schema = z.object({ lastEmailConfirm: z.string().optional(), }), languagePrefs: z.object({ - primaryLanguage: z.string(), // should move to server - contentLanguages: z.array(z.string()), // should move to server - postLanguage: z.string(), // should move to server + /** + * The target language for translating posts. + * + * BCP-47 2-letter language code without region. + */ + primaryLanguage: z.string(), + /** + * The languages the user can read, passed to feeds. + * + * BCP-47 2-letter language codes without region. + */ + contentLanguages: z.array(z.string()), + /** + * The language(s) the user is currently posting in, configured within the + * composer. Multiple languages are psearate by commas. + * + * BCP-47 2-letter language code without region. + */ + postLanguage: z.string(), + /** + * The user's post language history, used to pre-populate the post language + * selector in the composer. Within each value, multiple languages are + * separated by values. + * + * BCP-47 2-letter language codes without region. + */ postLanguageHistory: z.array(z.string()), + /** + * The language for UI translations in the app. + * + * BCP-47 2-letter language code with or without region, + * to match with {@link AppLanguage}. + */ appLanguage: z.string(), }), requireAltTextEnabled: z.boolean(), // should move to server @@ -108,13 +138,17 @@ export const defaults: Schema = { lastEmailConfirm: undefined, }, languagePrefs: { - primaryLanguage: deviceLocales[0] || 'en', - contentLanguages: deviceLocales || [], - postLanguage: deviceLocales[0] || 'en', - postLanguageHistory: (deviceLocales || []) + primaryLanguage: deviceLanguageCodes[0] || 'en', + contentLanguages: deviceLanguageCodes || [], + postLanguage: deviceLanguageCodes[0] || 'en', + postLanguageHistory: (deviceLanguageCodes || []) .concat(['en', 'ja', 'pt', 'de']) .slice(0, 6), - appLanguage: deviceLocales[0] || 'en', + // try full language tag first, then fallback to language code + appLanguage: findSupportedAppLanguage([ + deviceLocales.at(0)?.languageTag, + deviceLanguageCodes[0], + ]), }, requireAltTextEnabled: false, largeAltBadgeEnabled: false, |