Skip to content

Commit

Permalink
#537 Added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
mliebelt committed Apr 14, 2024
1 parent 851ac43 commit e1928a4
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .typesafe-i18n.json
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"
}
12 changes: 12 additions & 0 deletions src/i18n/formatters.ts
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
}
43 changes: 43 additions & 0 deletions src/i18n/i18n-types.ts
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 = {}
27 changes: 27 additions & 0 deletions src/i18n/i18n-util.async.ts
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))
26 changes: 26 additions & 0 deletions src/i18n/i18n-util.sync.ts
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))
38 changes: 38 additions & 0 deletions src/i18n/i18n-util.ts
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)

0 comments on commit e1928a4

Please sign in to comment.