diff --git a/src/i18n/formatters.ts b/src/i18n/formatters.ts index bee7dc1..9d01aa8 100644 --- a/src/i18n/formatters.ts +++ b/src/i18n/formatters.ts @@ -6,5 +6,7 @@ export const initFormatters: FormattersInitializer = (local // add your formatter functions here } + console.log(locale) + return formatters } diff --git a/src/i18n/i18n-svelte.ts b/src/i18n/i18n-svelte.ts index 6cdffb3..f0067b8 100644 --- a/src/i18n/i18n-svelte.ts +++ b/src/i18n/i18n-svelte.ts @@ -5,7 +5,12 @@ import { initI18nSvelte } from 'typesafe-i18n/svelte' import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types' import { loadedFormatters, loadedLocales } from './i18n-util' -const { locale, LL, setLocale } = initI18nSvelte(loadedLocales, loadedFormatters) +const { locale, LL, setLocale } = initI18nSvelte< + Locales, + Translations, + TranslationFunctions, + Formatters +>(loadedLocales, loadedFormatters) export { locale, LL, setLocale } diff --git a/src/i18n/i18n-types.ts b/src/i18n/i18n-types.ts index 371784b..8e8cb0a 100644 --- a/src/i18n/i18n-types.ts +++ b/src/i18n/i18n-types.ts @@ -5,371 +5,368 @@ import type { BaseTranslation as BaseTranslationType, LocalizedString } from 'ty export type BaseTranslation = BaseTranslationType export type BaseLocale = 'en' -export type Locales = - | 'de' - | 'en' - | 'zh' +export type Locales = 'de' | 'en' | 'zh' export type Translation = RootTranslation export type Translations = RootTranslation type RootTranslation = { - /** - * A​b​o​u​t - */ - about: string - /** - * A​d​v​a​n​c​e​d - */ - advanced: string - /** - * B​a​s​i​c - */ - basic: string - /** - * C​a​n​c​e​l - */ - cancel: string - /** - * C​h​o​o​s​e​ ​a​ ​c​o​l​o​r - */ - choose_a_color: string - /** - * C​o​d​e​ ​o​f​ ​c​o​n​d​u​c​t - */ - code_of_conduct: string - /** - * C​o​l​o​r - */ - color: string - /** - * C​o​n​n​e​c​t - */ - connect: string - /** - * C​o​n​n​e​c​t​i​o​n​ ​e​s​t​a​b​l​i​s​h​e​d - */ - connection_established: string - /** - * C​o​p​y​ ​m​y​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g - */ - copy_my_connection_string: string - /** - * D​i​s​c​o​n​n​e​c​t - */ - disconnect: string - /** - * F​u​l​l​s​c​r​e​e​n - */ - fullscreen: string - /** - * H​o​s​t​ ​a​ ​s​e​s​s​i​o​n - */ - host_a_session: string - /** - * H​o​s​t​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g - */ - host_connection_string: string - /** - * H​o​s​t​i​n​g​ ​a​ ​s​e​s​s​i​o​n - */ - hosting_a_session: string - /** - * I​s​ ​m​i​c​r​o​p​h​o​n​e​ ​a​c​t​i​v​e​ ​o​n​ ​c​o​n​n​e​c​t - */ - is_microphone_active_on_connect: string - /** - * J​o​i​n​ ​a​ ​s​e​s​s​i​o​n - */ - join_a_session: string - /** - * J​o​i​n​e​d​ ​a​ ​s​e​s​s​i​o​n - */ - joined_a_session: string - /** - * L​a​n​g​u​a​g​e - */ - language: string - /** - * C​h​o​o​s​e​ ​y​o​u​r​ ​p​r​e​f​e​r​r​e​d​ ​l​a​n​g​u​a​g​e​ ​(​a​f​t​e​r​ ​c​h​a​n​g​i​n​g​ ​t​h​e​ ​l​a​n​g​u​a​g​e​,​ ​y​o​u​ ​n​e​e​d​ ​t​o​ ​r​e​s​t​a​r​t​ ​t​h​e​ ​a​p​p​) - */ - language_description: string - /** - * M​e​d​i​a - */ - media: string - /** - * M​i​c​r​o​p​h​o​n​e​ ​a​c​t​i​v​e - */ - microphone_active: string - /** - * M​i​c​r​o​p​h​o​n​e​ ​i​n​a​c​t​i​v​e - */ - microphone_inactive: string - /** - * N​o​t​ ​s​t​r​e​a​m​i​n​g​ ​y​o​u​r​ ​d​i​s​p​l​a​y - */ - not_streaming_your_display: string - /** - * P​a​r​t​i​c​i​p​a​n​t​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g - */ - participant_connection_string: string - /** - * P​r​i​v​a​c​y​ ​p​o​l​i​c​y - */ - privacty_policy: string - /** - * R​e​m​o​t​e​ ​c​u​r​s​o​r​s​ ​d​i​s​a​b​l​e​d - */ - remote_cursors_disabled: string - /** - * R​e​m​o​t​e​ ​c​u​r​s​o​r​s​ ​e​n​a​b​l​e​d - */ - remote_cursors_enabled: string - /** - * R​e​m​o​t​e​ ​s​c​r​e​e​n - */ - remote_screen: string - /** - * R​e​p​o​r​t​ ​a​ ​b​u​g - */ - report_a_bug: string - /** - * S​a​v​e - */ - save: string - /** - * S​e​e​ ​t​h​e​ ​c​o​d​e - */ - see_the_code: string - /** - * S​e​s​s​i​o​n​ ​s​t​a​r​t​e​d - */ - session_started: string - /** - * S​e​t​t​i​n​g​s - */ - settings: string - /** - * S​h​o​u​l​d​e​r​s​ ​o​f​ ​g​i​a​n​t​s - */ - shoulders_of_giants: string - /** - * B​a​n​a​n​a​s​ ​S​c​r​e​e​n​ ​S​h​a​r​i​n​g​ ​i​s​ ​b​u​i​l​t​ ​o​n​ ​t​o​p​ ​o​f​ ​t​h​e​ ​f​o​l​l​o​w​i​n​g​ ​o​p​e​n​-​s​o​u​r​c​e​ ​p​r​o​j​e​c​t​s​ ​(​i​n​ ​n​o​ ​p​a​r​t​i​c​u​l​a​r​ ​o​r​d​e​r​) - */ - shoulders_of_giants_description: string - /** - * S​t​a​r​t​ ​a​ ​n​e​w​ ​s​e​s​s​i​o​n - */ - start_a_new_session: string - /** - * S​t​r​e​a​m​i​n​g​ ​y​o​u​r​ ​d​i​s​p​l​a​y - */ - streaming_your_display: string - /** - * S​T​U​N​/​T​U​R​N​ ​S​e​r​v​e​r​ ​O​b​j​e​c​t​s​ ​(​s​e​p​a​r​a​t​e​d​ ​b​y​ ​n​e​w​ ​l​i​n​e​s​) - */ - stun_turn_server_objects: string - /** - * T​e​r​m​s​ ​o​f​ ​s​e​r​v​i​c​e - */ - terms_of_service: string - /** - * U​s​e​r​n​a​m​e - */ - username: string - /** - * W​e​b​s​i​t​e - */ - website: string - /** - * Z​o​o​m​ ​i​n - */ - zoom_in: string - /** - * Z​o​o​m​ ​o​u​t - */ - zoom_out: string + /** + * A​b​o​u​t + */ + about: string + /** + * A​d​v​a​n​c​e​d + */ + advanced: string + /** + * B​a​s​i​c + */ + basic: string + /** + * C​a​n​c​e​l + */ + cancel: string + /** + * C​h​o​o​s​e​ ​a​ ​c​o​l​o​r + */ + choose_a_color: string + /** + * C​o​d​e​ ​o​f​ ​c​o​n​d​u​c​t + */ + code_of_conduct: string + /** + * C​o​l​o​r + */ + color: string + /** + * C​o​n​n​e​c​t + */ + connect: string + /** + * C​o​n​n​e​c​t​i​o​n​ ​e​s​t​a​b​l​i​s​h​e​d + */ + connection_established: string + /** + * C​o​p​y​ ​m​y​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g + */ + copy_my_connection_string: string + /** + * D​i​s​c​o​n​n​e​c​t + */ + disconnect: string + /** + * F​u​l​l​s​c​r​e​e​n + */ + fullscreen: string + /** + * H​o​s​t​ ​a​ ​s​e​s​s​i​o​n + */ + host_a_session: string + /** + * H​o​s​t​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g + */ + host_connection_string: string + /** + * H​o​s​t​i​n​g​ ​a​ ​s​e​s​s​i​o​n + */ + hosting_a_session: string + /** + * I​s​ ​m​i​c​r​o​p​h​o​n​e​ ​a​c​t​i​v​e​ ​o​n​ ​c​o​n​n​e​c​t + */ + is_microphone_active_on_connect: string + /** + * J​o​i​n​ ​a​ ​s​e​s​s​i​o​n + */ + join_a_session: string + /** + * J​o​i​n​e​d​ ​a​ ​s​e​s​s​i​o​n + */ + joined_a_session: string + /** + * L​a​n​g​u​a​g​e + */ + language: string + /** + * C​h​o​o​s​e​ ​y​o​u​r​ ​p​r​e​f​e​r​r​e​d​ ​l​a​n​g​u​a​g​e​ ​(​a​f​t​e​r​ ​c​h​a​n​g​i​n​g​ ​t​h​e​ ​l​a​n​g​u​a​g​e​,​ ​y​o​u​ ​n​e​e​d​ ​t​o​ ​r​e​s​t​a​r​t​ ​t​h​e​ ​a​p​p​) + */ + language_description: string + /** + * M​e​d​i​a + */ + media: string + /** + * M​i​c​r​o​p​h​o​n​e​ ​a​c​t​i​v​e + */ + microphone_active: string + /** + * M​i​c​r​o​p​h​o​n​e​ ​i​n​a​c​t​i​v​e + */ + microphone_inactive: string + /** + * N​o​t​ ​s​t​r​e​a​m​i​n​g​ ​y​o​u​r​ ​d​i​s​p​l​a​y + */ + not_streaming_your_display: string + /** + * P​a​r​t​i​c​i​p​a​n​t​ ​c​o​n​n​e​c​t​i​o​n​ ​s​t​r​i​n​g + */ + participant_connection_string: string + /** + * P​r​i​v​a​c​y​ ​p​o​l​i​c​y + */ + privacty_policy: string + /** + * R​e​m​o​t​e​ ​c​u​r​s​o​r​s​ ​d​i​s​a​b​l​e​d + */ + remote_cursors_disabled: string + /** + * R​e​m​o​t​e​ ​c​u​r​s​o​r​s​ ​e​n​a​b​l​e​d + */ + remote_cursors_enabled: string + /** + * R​e​m​o​t​e​ ​s​c​r​e​e​n + */ + remote_screen: string + /** + * R​e​p​o​r​t​ ​a​ ​b​u​g + */ + report_a_bug: string + /** + * S​a​v​e + */ + save: string + /** + * S​e​e​ ​t​h​e​ ​c​o​d​e + */ + see_the_code: string + /** + * S​e​s​s​i​o​n​ ​s​t​a​r​t​e​d + */ + session_started: string + /** + * S​e​t​t​i​n​g​s + */ + settings: string + /** + * S​h​o​u​l​d​e​r​s​ ​o​f​ ​g​i​a​n​t​s + */ + shoulders_of_giants: string + /** + * B​a​n​a​n​a​s​ ​S​c​r​e​e​n​ ​S​h​a​r​i​n​g​ ​i​s​ ​b​u​i​l​t​ ​o​n​ ​t​o​p​ ​o​f​ ​t​h​e​ ​f​o​l​l​o​w​i​n​g​ ​o​p​e​n​-​s​o​u​r​c​e​ ​p​r​o​j​e​c​t​s​ ​(​i​n​ ​n​o​ ​p​a​r​t​i​c​u​l​a​r​ ​o​r​d​e​r​) + */ + shoulders_of_giants_description: string + /** + * S​t​a​r​t​ ​a​ ​n​e​w​ ​s​e​s​s​i​o​n + */ + start_a_new_session: string + /** + * S​t​r​e​a​m​i​n​g​ ​y​o​u​r​ ​d​i​s​p​l​a​y + */ + streaming_your_display: string + /** + * S​T​U​N​/​T​U​R​N​ ​S​e​r​v​e​r​ ​O​b​j​e​c​t​s​ ​(​s​e​p​a​r​a​t​e​d​ ​b​y​ ​n​e​w​ ​l​i​n​e​s​) + */ + stun_turn_server_objects: string + /** + * T​e​r​m​s​ ​o​f​ ​s​e​r​v​i​c​e + */ + terms_of_service: string + /** + * U​s​e​r​n​a​m​e + */ + username: string + /** + * W​e​b​s​i​t​e + */ + website: string + /** + * Z​o​o​m​ ​i​n + */ + zoom_in: string + /** + * Z​o​o​m​ ​o​u​t + */ + zoom_out: string } export type TranslationFunctions = { - /** - * About - */ - about: () => LocalizedString - /** - * Advanced - */ - advanced: () => LocalizedString - /** - * Basic - */ - basic: () => LocalizedString - /** - * Cancel - */ - cancel: () => LocalizedString - /** - * Choose a color - */ - choose_a_color: () => LocalizedString - /** - * Code of conduct - */ - code_of_conduct: () => LocalizedString - /** - * Color - */ - color: () => LocalizedString - /** - * Connect - */ - connect: () => LocalizedString - /** - * Connection established - */ - connection_established: () => LocalizedString - /** - * Copy my connection string - */ - copy_my_connection_string: () => LocalizedString - /** - * Disconnect - */ - disconnect: () => LocalizedString - /** - * Fullscreen - */ - fullscreen: () => LocalizedString - /** - * Host a session - */ - host_a_session: () => LocalizedString - /** - * Host connection string - */ - host_connection_string: () => LocalizedString - /** - * Hosting a session - */ - hosting_a_session: () => LocalizedString - /** - * Is microphone active on connect - */ - is_microphone_active_on_connect: () => LocalizedString - /** - * Join a session - */ - join_a_session: () => LocalizedString - /** - * Joined a session - */ - joined_a_session: () => LocalizedString - /** - * Language - */ - language: () => LocalizedString - /** - * Choose your preferred language (after changing the language, you need to restart the app) - */ - language_description: () => LocalizedString - /** - * Media - */ - media: () => LocalizedString - /** - * Microphone active - */ - microphone_active: () => LocalizedString - /** - * Microphone inactive - */ - microphone_inactive: () => LocalizedString - /** - * Not streaming your display - */ - not_streaming_your_display: () => LocalizedString - /** - * Participant connection string - */ - participant_connection_string: () => LocalizedString - /** - * Privacy policy - */ - privacty_policy: () => LocalizedString - /** - * Remote cursors disabled - */ - remote_cursors_disabled: () => LocalizedString - /** - * Remote cursors enabled - */ - remote_cursors_enabled: () => LocalizedString - /** - * Remote screen - */ - remote_screen: () => LocalizedString - /** - * Report a bug - */ - report_a_bug: () => LocalizedString - /** - * Save - */ - save: () => LocalizedString - /** - * See the code - */ - see_the_code: () => LocalizedString - /** - * Session started - */ - session_started: () => LocalizedString - /** - * Settings - */ - settings: () => LocalizedString - /** - * Shoulders of giants - */ - shoulders_of_giants: () => LocalizedString - /** - * Bananas Screen Sharing is built on top of the following open-source projects (in no particular order) - */ - shoulders_of_giants_description: () => LocalizedString - /** - * Start a new session - */ - start_a_new_session: () => LocalizedString - /** - * Streaming your display - */ - streaming_your_display: () => LocalizedString - /** - * STUN/TURN Server Objects (separated by new lines) - */ - stun_turn_server_objects: () => LocalizedString - /** - * Terms of service - */ - terms_of_service: () => LocalizedString - /** - * Username - */ - username: () => LocalizedString - /** - * Website - */ - website: () => LocalizedString - /** - * Zoom in - */ - zoom_in: () => LocalizedString - /** - * Zoom out - */ - zoom_out: () => LocalizedString + /** + * About + */ + about: () => LocalizedString + /** + * Advanced + */ + advanced: () => LocalizedString + /** + * Basic + */ + basic: () => LocalizedString + /** + * Cancel + */ + cancel: () => LocalizedString + /** + * Choose a color + */ + choose_a_color: () => LocalizedString + /** + * Code of conduct + */ + code_of_conduct: () => LocalizedString + /** + * Color + */ + color: () => LocalizedString + /** + * Connect + */ + connect: () => LocalizedString + /** + * Connection established + */ + connection_established: () => LocalizedString + /** + * Copy my connection string + */ + copy_my_connection_string: () => LocalizedString + /** + * Disconnect + */ + disconnect: () => LocalizedString + /** + * Fullscreen + */ + fullscreen: () => LocalizedString + /** + * Host a session + */ + host_a_session: () => LocalizedString + /** + * Host connection string + */ + host_connection_string: () => LocalizedString + /** + * Hosting a session + */ + hosting_a_session: () => LocalizedString + /** + * Is microphone active on connect + */ + is_microphone_active_on_connect: () => LocalizedString + /** + * Join a session + */ + join_a_session: () => LocalizedString + /** + * Joined a session + */ + joined_a_session: () => LocalizedString + /** + * Language + */ + language: () => LocalizedString + /** + * Choose your preferred language (after changing the language, you need to restart the app) + */ + language_description: () => LocalizedString + /** + * Media + */ + media: () => LocalizedString + /** + * Microphone active + */ + microphone_active: () => LocalizedString + /** + * Microphone inactive + */ + microphone_inactive: () => LocalizedString + /** + * Not streaming your display + */ + not_streaming_your_display: () => LocalizedString + /** + * Participant connection string + */ + participant_connection_string: () => LocalizedString + /** + * Privacy policy + */ + privacty_policy: () => LocalizedString + /** + * Remote cursors disabled + */ + remote_cursors_disabled: () => LocalizedString + /** + * Remote cursors enabled + */ + remote_cursors_enabled: () => LocalizedString + /** + * Remote screen + */ + remote_screen: () => LocalizedString + /** + * Report a bug + */ + report_a_bug: () => LocalizedString + /** + * Save + */ + save: () => LocalizedString + /** + * See the code + */ + see_the_code: () => LocalizedString + /** + * Session started + */ + session_started: () => LocalizedString + /** + * Settings + */ + settings: () => LocalizedString + /** + * Shoulders of giants + */ + shoulders_of_giants: () => LocalizedString + /** + * Bananas Screen Sharing is built on top of the following open-source projects (in no particular order) + */ + shoulders_of_giants_description: () => LocalizedString + /** + * Start a new session + */ + start_a_new_session: () => LocalizedString + /** + * Streaming your display + */ + streaming_your_display: () => LocalizedString + /** + * STUN/TURN Server Objects (separated by new lines) + */ + stun_turn_server_objects: () => LocalizedString + /** + * Terms of service + */ + terms_of_service: () => LocalizedString + /** + * Username + */ + username: () => LocalizedString + /** + * Website + */ + website: () => LocalizedString + /** + * Zoom in + */ + zoom_in: () => LocalizedString + /** + * Zoom out + */ + zoom_out: () => LocalizedString } export type Formatters = {} diff --git a/src/i18n/i18n-util.async.ts b/src/i18n/i18n-util.async.ts index 9f39b02..6c12e4f 100644 --- a/src/i18n/i18n-util.async.ts +++ b/src/i18n/i18n-util.async.ts @@ -6,23 +6,23 @@ import type { Locales, Translations } from './i18n-types' import { loadedFormatters, loadedLocales, locales } from './i18n-util' const localeTranslationLoaders = { - de: () => import('./de'), - en: () => import('./en'), - zh: () => import('./zh'), + de: () => import('./de'), + en: () => import('./en'), + zh: () => import('./zh') } const updateDictionary = (locale: Locales, dictionary: Partial): Translations => - loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary } + (loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }) export const importLocaleAsync = async (locale: Locales): Promise => - (await localeTranslationLoaders[locale]()).default as unknown as Translations + (await localeTranslationLoaders[locale]()).default as unknown as Translations export const loadLocaleAsync = async (locale: Locales): Promise => { - updateDictionary(locale, await importLocaleAsync(locale)) - loadFormatters(locale) + updateDictionary(locale, await importLocaleAsync(locale)) + loadFormatters(locale) } export const loadAllLocalesAsync = (): Promise => Promise.all(locales.map(loadLocaleAsync)) export const loadFormatters = (locale: Locales): void => - void (loadedFormatters[locale] = initFormatters(locale)) + void (loadedFormatters[locale] = initFormatters(locale)) diff --git a/src/i18n/i18n-util.sync.ts b/src/i18n/i18n-util.sync.ts index c0e2055..78ce385 100644 --- a/src/i18n/i18n-util.sync.ts +++ b/src/i18n/i18n-util.sync.ts @@ -10,19 +10,19 @@ import en from './en' import zh from './zh' const localeTranslations = { - de, - en, - zh, + de, + en, + zh } export const loadLocale = (locale: Locales): void => { - if (loadedLocales[locale]) return + if (loadedLocales[locale]) return - loadedLocales[locale] = localeTranslations[locale] as unknown as Translations - loadFormatters(locale) + loadedLocales[locale] = localeTranslations[locale] as unknown as Translations + loadFormatters(locale) } export const loadAllLocales = (): void => locales.forEach(loadLocale) export const loadFormatters = (locale: Locales): void => - void (loadedFormatters[locale] = initFormatters(locale)) + void (loadedFormatters[locale] = initFormatters(locale)) diff --git a/src/i18n/i18n-util.ts b/src/i18n/i18n-util.ts index 766261f..32a388f 100644 --- a/src/i18n/i18n-util.ts +++ b/src/i18n/i18n-util.ts @@ -1,7 +1,11 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { i18n as initI18n, i18nObject as initI18nObject, i18nString as initI18nString } from 'typesafe-i18n' +import { + i18n as initI18n, + i18nObject as initI18nObject, + i18nString as initI18nString +} from 'typesafe-i18n' import type { LocaleDetector } from 'typesafe-i18n/detectors' import type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n' import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors' @@ -10,11 +14,7 @@ import type { Formatters, Locales, Translations, TranslationFunctions } from './ export const baseLocale: Locales = 'en' -export const locales: Locales[] = [ - 'de', - 'en', - 'zh' -] +export const locales: Locales[] = ['de', 'en', 'zh'] export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales) @@ -24,16 +24,18 @@ export const loadedFormatters: Record = {} as Record() -export const i18nString = (locale: Locales): TranslateByString => initI18nString(locale, loadedFormatters[locale]) +export const i18nString = (locale: Locales): TranslateByString => + initI18nString(locale, loadedFormatters[locale]) export const i18nObject = (locale: Locales): TranslationFunctions => - initI18nObject( - locale, - loadedLocales[locale], - loadedFormatters[locale] - ) + initI18nObject( + locale, + loadedLocales[locale], + loadedFormatters[locale] + ) export const i18n = (): LocaleTranslationFunctions => - initI18n(loadedLocales, loadedFormatters) + initI18n(loadedLocales, loadedFormatters) -export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn(baseLocale, locales, ...detectors) +export const detectLocale = (...detectors: LocaleDetector[]): Locales => + detectLocaleFn(baseLocale, locales, ...detectors)