-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
222 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters) | ||
const { component: TypesafeI18n, context: I18nContext } = initI18nReact< | ||
Locales, | ||
Translations, | ||
TranslationFunctions, | ||
Formatters | ||
>(loadedLocales, loadedFormatters); | ||
|
||
const useI18nContext = (): I18nContextType<Locales, Translations, TranslationFunctions> => useContext(I18nContext) | ||
const useI18nContext = (): I18nContextType< | ||
Locales, | ||
Translations, | ||
TranslationFunctions | ||
> => useContext(I18nContext); | ||
|
||
export { I18nContext, useI18nContext } | ||
export { I18nContext, useI18nContext }; | ||
|
||
export default TypesafeI18n | ||
export default TypesafeI18n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: { | ||
/** | ||
* Email address | ||
*/ | ||
label: string | ||
/** | ||
* email@example.com | ||
*/ | ||
placeholder: string | ||
/** | ||
* Sign in with email | ||
*/ | ||
button: string | ||
} | ||
/** | ||
* or | ||
*/ | ||
or: string | ||
/** | ||
* More choices... | ||
*/ | ||
more: string | ||
/** | ||
* Back to website | ||
*/ | ||
'back-to-website': string | ||
} | ||
email: { | ||
/** | ||
* Email address | ||
*/ | ||
label: string; | ||
/** | ||
* email@example.com | ||
*/ | ||
placeholder: string; | ||
/** | ||
* Sign in with email | ||
*/ | ||
button: string; | ||
}; | ||
/** | ||
* or | ||
*/ | ||
or: string; | ||
/** | ||
* More choices... | ||
*/ | ||
more: string; | ||
/** | ||
* Back to website | ||
*/ | ||
'back-to-website': string; | ||
}; | ||
|
||
export type NamespaceCommonTranslation = { | ||
seo: { | ||
/** | ||
* Pikas Template is a website that allows you to start developing your website in minutes. | ||
*/ | ||
description: string | ||
} | ||
} | ||
seo: { | ||
/** | ||
* Pikas Template is a website that allows you to start developing your website in minutes. | ||
*/ | ||
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 = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Translations>) => | ||
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<void> => { | ||
updateDictionary(locale, await importLocaleAsync(locale)) | ||
loadFormatters(locale) | ||
} | ||
updateDictionary(locale, await importLocaleAsync(locale)); | ||
loadFormatters(locale); | ||
}; | ||
|
||
export const loadAllLocalesAsync = (): Promise<void[]> => Promise.all(locales.map(loadLocaleAsync)) | ||
export const loadAllLocalesAsync = (): Promise<void[]> => | ||
Promise.all(locales.map(loadLocaleAsync)); | ||
|
||
export const loadFormatters = (locale: Locales): void => | ||
void (loadedFormatters[locale] = initFormatters(locale)) | ||
|
||
export const importNamespaceAsync = async<Namespace extends Namespaces>(locale: Locales, namespace: Namespace) => | ||
(await localeNamespaceLoaders[locale][namespace]()).default as unknown as Translations[Namespace] | ||
|
||
export const loadNamespaceAsync = async <Namespace extends Namespaces>(locale: Locales, namespace: Namespace): Promise<void> => | ||
void updateDictionary(locale, { [namespace]: await importNamespaceAsync(locale, namespace )}) | ||
void (loadedFormatters[locale] = initFormatters(locale)); | ||
|
||
export const importNamespaceAsync = async <Namespace extends Namespaces>( | ||
locale: Locales, | ||
namespace: Namespace | ||
) => | ||
(await localeNamespaceLoaders[locale][namespace]()) | ||
.default as unknown as Translations[Namespace]; | ||
|
||
export const loadNamespaceAsync = async <Namespace extends Namespaces>( | ||
locale: Locales, | ||
namespace: Namespace | ||
): Promise<void> => | ||
void updateDictionary(locale, { | ||
[namespace]: await importNamespaceAsync(locale, namespace), | ||
}); |
Oops, something went wrong.