-
Notifications
You must be signed in to change notification settings - Fork 44
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
6 changed files
with
150 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"adapters": [], | ||
"$schema": "https://unpkg.com/typesafe-i18n@5.26.2/schema/typesafe-i18n.json" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { FormattersInitializer } from 'typesafe-i18n' | ||
import type { Formatters } from './i18n-types' | ||
import {SupportedLocales} from "../types"; | ||
|
||
export const initFormatters: FormattersInitializer<SupportedLocales, Formatters> = (locale: SupportedLocales) => { | ||
|
||
const formatters: Formatters = { | ||
// add your formatter functions here | ||
} | ||
|
||
return 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. | ||
/* eslint-disable */ | ||
import type {BaseTranslation as BaseTranslationType, LocalizedString, RequiredParams} from 'typesafe-i18n' | ||
|
||
export type BaseTranslation = BaseTranslationType | ||
export type BaseLocale = 'en' | ||
|
||
export type Locales = | ||
| 'de' | ||
| 'en' | ||
|
||
export type Translation = RootTranslation | ||
|
||
export type Translations = RootTranslation | ||
|
||
type RootTranslation = {} | ||
|
||
export type TranslationFunctions = { | ||
"chess:q": string, | ||
"chess:k": string, | ||
"chess:r": string, | ||
"chess:b": string, | ||
"chess:n": string, | ||
"chess:Q": string, | ||
"chess:K": string, | ||
"chess:R": string, | ||
"chess:B": string, | ||
"chess:N": string, | ||
"buttons:flipper": string, | ||
"buttons:first": string, | ||
"buttons:prev": string, | ||
"buttons:next": string, | ||
"buttons:play": string, | ||
"buttons:last": string, | ||
"buttons:deleteVar": string, | ||
"buttons:promoteVar": string, | ||
"buttons:deleteMoves": string, | ||
"buttons:nags": string, | ||
"buttons:pgn": string, | ||
"buttons:hidePGN": string, | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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' | ||
|
||
const localeTranslationLoaders = { | ||
de: () => import('./de'), | ||
en: () => import('./en'), | ||
} | ||
|
||
const updateDictionary = (locale: Locales, dictionary: Partial<Translations>): Translations => | ||
loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary } | ||
|
||
export const importLocaleAsync = async (locale: Locales): Promise<Translations> => | ||
(await localeTranslationLoaders[locale]()).default as unknown as Translations | ||
|
||
export const loadLocaleAsync = async (locale: Locales): Promise<void> => { | ||
updateDictionary(locale, await importLocaleAsync(locale)) | ||
loadFormatters(locale) | ||
} | ||
|
||
export const loadAllLocalesAsync = (): Promise<void[]> => Promise.all(locales.map(loadLocaleAsync)) | ||
|
||
export const loadFormatters = (locale: Locales): void => | ||
void (loadedFormatters[locale] = initFormatters(locale)) |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 de from '../locales/de' | ||
import en from '../locales/en' | ||
|
||
const localeTranslations = { | ||
de, | ||
en, | ||
} | ||
|
||
export const loadLocale = (locale: Locales): void => { | ||
if (loadedLocales[locale]) return | ||
|
||
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)) |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n' | ||
import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors' | ||
import { initExtendDictionary } from 'typesafe-i18n/utils' | ||
import type { Formatters, Locales, Translations, TranslationFunctions } from './i18n-types' | ||
|
||
export const baseLocale: Locales = 'en' | ||
|
||
export const locales: Locales[] = [ | ||
'de', | ||
'en' | ||
] | ||
|
||
export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales) | ||
|
||
export const loadedLocales: Record<Locales, Translations> = {} as Record<Locales, Translations> | ||
|
||
export const loadedFormatters: Record<Locales, Formatters> = {} as Record<Locales, Formatters> | ||
|
||
export const extendDictionary = initExtendDictionary<Translations>() | ||
|
||
export const i18nString = (locale: Locales): TranslateByString => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale]) | ||
|
||
export const i18nObject = (locale: Locales): TranslationFunctions => | ||
initI18nObject<Locales, Translations, TranslationFunctions, Formatters>( | ||
locale, | ||
loadedLocales[locale], | ||
loadedFormatters[locale] | ||
) | ||
|
||
export const i18n = (): LocaleTranslationFunctions<Locales, Translations, TranslationFunctions> => | ||
initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters) | ||
|
||
export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn<Locales>(baseLocale, locales, ...detectors) |