From 9ff32824211b39b89e398ab603e5270e13f737ac Mon Sep 17 00:00:00 2001 From: Christopher Yovanovitch Date: Sun, 2 Oct 2022 12:54:33 +0200 Subject: [PATCH] format --- packages/translate/src/i18n/i18n-react.tsx | 32 ++- packages/translate/src/i18n/i18n-types.ts | 196 +++++++++--------- .../translate/src/i18n/i18n-util.async.ts | 66 +++--- packages/translate/src/i18n/i18n-util.sync.ts | 52 ++--- packages/translate/src/i18n/i18n-util.ts | 65 +++--- 5 files changed, 222 insertions(+), 189 deletions(-) diff --git a/packages/translate/src/i18n/i18n-react.tsx b/packages/translate/src/i18n/i18n-react.tsx index f113051..7ac1c01 100644 --- a/packages/translate/src/i18n/i18n-react.tsx +++ b/packages/translate/src/i18n/i18n-react.tsx @@ -1,16 +1,30 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { useContext } from 'react' -import { initI18nReact } from 'typesafe-i18n/react' -import type { I18nContextType } from 'typesafe-i18n/react' -import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types' -import { loadedFormatters, loadedLocales } from './i18n-util' +import { useContext } from 'react'; +import { initI18nReact } from 'typesafe-i18n/react'; +import type { I18nContextType } from 'typesafe-i18n/react'; +import type { + Formatters, + Locales, + TranslationFunctions, + Translations, +} from './i18n-types'; +import { loadedFormatters, loadedLocales } from './i18n-util'; -const { component: TypesafeI18n, context: I18nContext } = initI18nReact(loadedLocales, loadedFormatters) +const { component: TypesafeI18n, context: I18nContext } = initI18nReact< + Locales, + Translations, + TranslationFunctions, + Formatters +>(loadedLocales, loadedFormatters); -const useI18nContext = (): I18nContextType => useContext(I18nContext) +const useI18nContext = (): I18nContextType< + Locales, + Translations, + TranslationFunctions +> => useContext(I18nContext); -export { I18nContext, useI18nContext } +export { I18nContext, useI18nContext }; -export default TypesafeI18n +export default TypesafeI18n; diff --git a/packages/translate/src/i18n/i18n-types.ts b/packages/translate/src/i18n/i18n-types.ts index 6d897cd..07d5484 100644 --- a/packages/translate/src/i18n/i18n-types.ts +++ b/packages/translate/src/i18n/i18n-types.ts @@ -1,117 +1,115 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import type { BaseTranslation as BaseTranslationType, LocalizedString } from 'typesafe-i18n' +import type { + BaseTranslation as BaseTranslationType, + LocalizedString, +} from 'typesafe-i18n'; -export type BaseTranslation = BaseTranslationType & DisallowNamespaces -export type BaseLocale = 'en' +export type BaseTranslation = BaseTranslationType & DisallowNamespaces; +export type BaseLocale = 'en'; -export type Locales = - | 'en' - | 'fr' +export type Locales = 'en' | 'fr'; -export type Translation = RootTranslation & DisallowNamespaces +export type Translation = RootTranslation & DisallowNamespaces; -export type Translations = RootTranslation & -{ - app_signIn: NamespaceAppSignInTranslation, - common: NamespaceCommonTranslation -} +export type Translations = RootTranslation & { + app_signIn: NamespaceAppSignInTranslation; + common: NamespaceCommonTranslation; +}; -type RootTranslation = {} +type RootTranslation = {}; export type NamespaceAppSignInTranslation = { - email: { - /** - * E​m​a​i​l​ ​a​d​d​r​e​s​s - */ - label: string - /** - * e​m​a​i​l​@​e​x​a​m​p​l​e​.​c​o​m - */ - placeholder: string - /** - * S​i​g​n​ ​i​n​ ​w​i​t​h​ ​e​m​a​i​l - */ - button: string - } - /** - * o​r - */ - or: string - /** - * M​o​r​e​ ​c​h​o​i​c​e​s​.​.​. - */ - more: string - /** - * B​a​c​k​ ​t​o​ ​w​e​b​s​i​t​e - */ - 'back-to-website': string -} + email: { + /** + * E​m​a​i​l​ ​a​d​d​r​e​s​s + */ + label: string; + /** + * e​m​a​i​l​@​e​x​a​m​p​l​e​.​c​o​m + */ + placeholder: string; + /** + * S​i​g​n​ ​i​n​ ​w​i​t​h​ ​e​m​a​i​l + */ + button: string; + }; + /** + * o​r + */ + or: string; + /** + * M​o​r​e​ ​c​h​o​i​c​e​s​.​.​. + */ + more: string; + /** + * B​a​c​k​ ​t​o​ ​w​e​b​s​i​t​e + */ + 'back-to-website': string; +}; export type NamespaceCommonTranslation = { - seo: { - /** - * P​i​k​a​s​ ​T​e​m​p​l​a​t​e​ ​i​s​ ​a​ ​w​e​b​s​i​t​e​ ​t​h​a​t​ ​a​l​l​o​w​s​ ​y​o​u​ ​t​o​ ​s​t​a​r​t​ ​d​e​v​e​l​o​p​i​n​g​ ​y​o​u​r​ ​w​e​b​s​i​t​e​ ​i​n​ ​m​i​n​u​t​e​s​. - */ - description: string - } -} + seo: { + /** + * P​i​k​a​s​ ​T​e​m​p​l​a​t​e​ ​i​s​ ​a​ ​w​e​b​s​i​t​e​ ​t​h​a​t​ ​a​l​l​o​w​s​ ​y​o​u​ ​t​o​ ​s​t​a​r​t​ ​d​e​v​e​l​o​p​i​n​g​ ​y​o​u​r​ ​w​e​b​s​i​t​e​ ​i​n​ ​m​i​n​u​t​e​s​. + */ + description: string; + }; +}; -export type Namespaces = - | 'app_signIn' - | 'common' +export type Namespaces = 'app_signIn' | 'common'; type DisallowNamespaces = { - /** - * reserved for 'app_signIn'-namespace\ - * you need to use the `./app_signIn/index.ts` file instead - */ - app_signIn?: "[typesafe-i18n] reserved for 'app_signIn'-namespace. You need to use the `./app_signIn/index.ts` file instead." + /** + * reserved for 'app_signIn'-namespace\ + * you need to use the `./app_signIn/index.ts` file instead + */ + app_signIn?: "[typesafe-i18n] reserved for 'app_signIn'-namespace. You need to use the `./app_signIn/index.ts` file instead."; - /** - * reserved for 'common'-namespace\ - * you need to use the `./common/index.ts` file instead - */ - common?: "[typesafe-i18n] reserved for 'common'-namespace. You need to use the `./common/index.ts` file instead." -} + /** + * reserved for 'common'-namespace\ + * you need to use the `./common/index.ts` file instead + */ + common?: "[typesafe-i18n] reserved for 'common'-namespace. You need to use the `./common/index.ts` file instead."; +}; export type TranslationFunctions = { - app_signIn: { - email: { - /** - * Email address - */ - label: () => LocalizedString - /** - * email@example.com - */ - placeholder: () => LocalizedString - /** - * Sign in with email - */ - button: () => LocalizedString - } - /** - * or - */ - or: () => LocalizedString - /** - * More choices... - */ - more: () => LocalizedString - /** - * Back to website - */ - 'back-to-website': () => LocalizedString - } - common: { - seo: { - /** - * Pikas Template is a website that allows you to start developing your website in minutes. - */ - description: () => LocalizedString - } - } -} + app_signIn: { + email: { + /** + * Email address + */ + label: () => LocalizedString; + /** + * email@example.com + */ + placeholder: () => LocalizedString; + /** + * Sign in with email + */ + button: () => LocalizedString; + }; + /** + * or + */ + or: () => LocalizedString; + /** + * More choices... + */ + more: () => LocalizedString; + /** + * Back to website + */ + 'back-to-website': () => LocalizedString; + }; + common: { + seo: { + /** + * Pikas Template is a website that allows you to start developing your website in minutes. + */ + description: () => LocalizedString; + }; + }; +}; -export type Formatters = {} +export type Formatters = {}; diff --git a/packages/translate/src/i18n/i18n-util.async.ts b/packages/translate/src/i18n/i18n-util.async.ts index 28aabc8..86814e8 100644 --- a/packages/translate/src/i18n/i18n-util.async.ts +++ b/packages/translate/src/i18n/i18n-util.async.ts @@ -1,44 +1,54 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { initFormatters } from './formatters' -import type { Locales, Namespaces, Translations } from './i18n-types' -import { loadedFormatters, loadedLocales, locales } from './i18n-util' +import { initFormatters } from './formatters'; +import type { Locales, Namespaces, Translations } from './i18n-types'; +import { loadedFormatters, loadedLocales, locales } from './i18n-util'; const localeTranslationLoaders = { - en: () => import('./en'), - fr: () => import('./fr'), -} + en: () => import('./en'), + fr: () => import('./fr'), +}; const localeNamespaceLoaders = { - en: { - app_signIn: () => import('./en/app_signIn'), - common: () => import('./en/common') - }, - fr: { - app_signIn: () => import('./fr/app_signIn'), - common: () => import('./fr/common') - } -} + en: { + app_signIn: () => import('./en/app_signIn'), + common: () => import('./en/common'), + }, + fr: { + app_signIn: () => import('./fr/app_signIn'), + common: () => import('./fr/common'), + }, +}; const updateDictionary = (locale: Locales, dictionary: Partial) => - loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary } + (loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }); export const importLocaleAsync = async (locale: Locales) => - (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 loadAllLocalesAsync = (): Promise => + Promise.all(locales.map(loadLocaleAsync)); export const loadFormatters = (locale: Locales): void => - void (loadedFormatters[locale] = initFormatters(locale)) - -export const importNamespaceAsync = async(locale: Locales, namespace: Namespace) => - (await localeNamespaceLoaders[locale][namespace]()).default as unknown as Translations[Namespace] - -export const loadNamespaceAsync = async (locale: Locales, namespace: Namespace): Promise => - void updateDictionary(locale, { [namespace]: await importNamespaceAsync(locale, namespace )}) + void (loadedFormatters[locale] = initFormatters(locale)); + +export const importNamespaceAsync = async ( + locale: Locales, + namespace: Namespace +) => + (await localeNamespaceLoaders[locale][namespace]()) + .default as unknown as Translations[Namespace]; + +export const loadNamespaceAsync = async ( + locale: Locales, + namespace: Namespace +): Promise => + void updateDictionary(locale, { + [namespace]: await importNamespaceAsync(locale, namespace), + }); diff --git a/packages/translate/src/i18n/i18n-util.sync.ts b/packages/translate/src/i18n/i18n-util.sync.ts index dc5833b..89e026b 100644 --- a/packages/translate/src/i18n/i18n-util.sync.ts +++ b/packages/translate/src/i18n/i18n-util.sync.ts @@ -1,39 +1,39 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { initFormatters } from './formatters' -import type { Locales, Translations } from './i18n-types' -import { loadedFormatters, loadedLocales, locales } from './i18n-util' +import { initFormatters } from './formatters'; +import type { Locales, Translations } from './i18n-types'; +import { loadedFormatters, loadedLocales, locales } from './i18n-util'; -import en from './en' -import fr from './fr' +import en from './en'; +import fr from './fr'; -import en_app_signIn from './en/app_signIn' -import en_common from './en/common' -import fr_app_signIn from './fr/app_signIn' -import fr_common from './fr/common' +import en_app_signIn from './en/app_signIn'; +import en_common from './en/common'; +import fr_app_signIn from './fr/app_signIn'; +import fr_common from './fr/common'; const localeTranslations = { - en: { - ...en, - app_signIn: en_app_signIn, - common: en_common - }, - fr: { - ...fr, - app_signIn: fr_app_signIn, - common: fr_common - }, -} + en: { + ...en, + app_signIn: en_app_signIn, + common: en_common, + }, + fr: { + ...fr, + app_signIn: fr_app_signIn, + common: fr_common, + }, +}; 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 loadAllLocales = (): void => locales.forEach(loadLocale); export const loadFormatters = (locale: Locales): void => - void (loadedFormatters[locale] = initFormatters(locale)) + void (loadedFormatters[locale] = initFormatters(locale)); diff --git a/packages/translate/src/i18n/i18n-util.ts b/packages/translate/src/i18n/i18n-util.ts index 3382412..37bbc92 100644 --- a/packages/translate/src/i18n/i18n-util.ts +++ b/packages/translate/src/i18n/i18n-util.ts @@ -1,40 +1,51 @@ // 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 type { LocaleDetector } from 'typesafe-i18n/detectors' -import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors' -import type { Formatters, Locales, Namespaces, Translations, TranslationFunctions } from './i18n-types' +import { + i18n as initI18n, + i18nObject as initI18nObject, + i18nString as initI18nString, +} from 'typesafe-i18n'; +import type { LocaleDetector } from 'typesafe-i18n/detectors'; +import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'; +import type { + Formatters, + Locales, + Namespaces, + Translations, + TranslationFunctions, +} from './i18n-types'; -export const baseLocale: Locales = 'en' +export const baseLocale: Locales = 'en'; -export const locales: Locales[] = [ - 'en', - 'fr' -] +export const locales: Locales[] = ['en', 'fr']; -export const namespaces: Namespaces[] = [ - 'app_signIn', - 'common' -] +export const namespaces: Namespaces[] = ['app_signIn', 'common']; -export const isLocale = (locale: string) => locales.includes(locale as Locales) +export const isLocale = (locale: string) => locales.includes(locale as Locales); -export const isNamespace = (namespace: string) => namespaces.includes(namespace as Namespaces) +export const isNamespace = (namespace: string) => + namespaces.includes(namespace as Namespaces); -export const loadedLocales = {} as Record +export const loadedLocales = {} as Record; -export const loadedFormatters = {} as Record +export const loadedFormatters = {} as Record; -export const i18nString = (locale: Locales) => initI18nString(locale, loadedFormatters[locale]) +export const i18nString = (locale: Locales) => + initI18nString(locale, loadedFormatters[locale]); export const i18nObject = (locale: Locales) => - initI18nObject( - locale, - loadedLocales[locale], - loadedFormatters[locale] - ) - -export const i18n = () => initI18n(loadedLocales, loadedFormatters) - -export const detectLocale = (...detectors: LocaleDetector[]) => detectLocaleFn(baseLocale, locales, ...detectors) + initI18nObject( + locale, + loadedLocales[locale], + loadedFormatters[locale] + ); + +export const i18n = () => + initI18n( + loadedLocales, + loadedFormatters + ); + +export const detectLocale = (...detectors: LocaleDetector[]) => + detectLocaleFn(baseLocale, locales, ...detectors);