From 4910132c2ce7b379ec459f0528bec4545146adef Mon Sep 17 00:00:00 2001 From: nichenqin Date: Sat, 29 Jun 2024 15:23:50 +0800 Subject: [PATCH] chore: gen --- .prettierignore | 1 + packages/i18n/src/i18n/i18n-node.ts | 8 +- packages/i18n/src/i18n/i18n-svelte.ts | 13 +- packages/i18n/src/i18n/i18n-types.ts | 585 +++++++++++----------- packages/i18n/src/i18n/i18n-util.async.ts | 19 +- packages/i18n/src/i18n/i18n-util.sync.ts | 19 +- packages/i18n/src/i18n/i18n-util.ts | 36 +- 7 files changed, 341 insertions(+), 340 deletions(-) diff --git a/.prettierignore b/.prettierignore index dde3c67d2..23ccfd61b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ pnpm-lock.yaml package-lock.json yarn.lock bun.lockb +packages/i18n/**/*.ts \ No newline at end of file diff --git a/packages/i18n/src/i18n/i18n-node.ts b/packages/i18n/src/i18n/i18n-node.ts index 367754ac8..7dab23b46 100644 --- a/packages/i18n/src/i18n/i18n-node.ts +++ b/packages/i18n/src/i18n/i18n-node.ts @@ -1,10 +1,10 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { i18n } from "./i18n-util.js" -import { loadAllLocales } from "./i18n-util.sync.js" -import type { LocaleTranslationFunctions } from "typesafe-i18n" -import type { Locales, Translations, TranslationFunctions } from "./i18n-types.js" +import { i18n } from './i18n-util.js' +import { loadAllLocales } from './i18n-util.sync.js' +import type { LocaleTranslationFunctions } from 'typesafe-i18n' +import type { Locales, Translations, TranslationFunctions } from './i18n-types.js' loadAllLocales() diff --git a/packages/i18n/src/i18n/i18n-svelte.ts b/packages/i18n/src/i18n/i18n-svelte.ts index afca54533..23d478de0 100644 --- a/packages/i18n/src/i18n/i18n-svelte.ts +++ b/packages/i18n/src/i18n/i18n-svelte.ts @@ -1,14 +1,11 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { initI18nSvelte } from "typesafe-i18n/svelte" -import type { Formatters, Locales, TranslationFunctions, Translations } from "./i18n-types.js" -import { loadedFormatters, loadedLocales } from "./i18n-util.js" - -const { locale, LL, setLocale } = initI18nSvelte( - loadedLocales, - loadedFormatters, -) +import { initI18nSvelte } from 'typesafe-i18n/svelte' +import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types.js' +import { loadedFormatters, loadedLocales } from './i18n-util.js' + +const { locale, LL, setLocale } = initI18nSvelte(loadedLocales, loadedFormatters) export { locale, LL, setLocale } diff --git a/packages/i18n/src/i18n/i18n-types.ts b/packages/i18n/src/i18n/i18n-types.ts index 9cbde27f2..d06b65768 100644 --- a/packages/i18n/src/i18n/i18n-types.ts +++ b/packages/i18n/src/i18n/i18n-types.ts @@ -1,309 +1,310 @@ // 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" +import type { BaseTranslation as BaseTranslationType, LocalizedString, RequiredParams } from 'typesafe-i18n' export type BaseTranslation = BaseTranslationType -export type BaseLocale = "en" +export type BaseLocale = 'en' -export type Locales = "en" +export type Locales = + | 'en' export type Translation = RootTranslation export type Translations = RootTranslation type RootTranslation = { - /** - * H​i​ ​{​n​a​m​e​}​!​ ​P​l​e​a​s​e​ ​l​e​a​v​e​ ​a​ ​s​t​a​r​ ​i​f​ ​y​o​u​ ​l​i​k​e​ ​t​h​i​s​ ​p​r​o​j​e​c​t​:​ ​h​t​t​p​s​:​/​/​g​i​t​h​u​b​.​c​o​m​/​i​v​a​n​h​o​f​e​r​/​t​y​p​e​s​a​f​e​-​i​1​8​n - * @param {string} name - */ - HI: RequiredParams<"name"> - table: { - ops: { - /** - * = - */ - eq: string - /** - * !​= - */ - neq: string - /** - * c​o​n​t​a​i​n​s - */ - contains: string - /** - * n​o​t​ ​c​o​n​t​a​i​n​s - */ - does_not_contain: string - /** - * s​t​a​r​t​s​ ​w​i​t​h - */ - starts_with: string - /** - * e​n​d​s​ ​w​i​t​h - */ - ends_with: string - /** - * i​s​ ​e​m​p​t​y - */ - is_empty: string - /** - * i​s​ ​n​o​t​ ​e​m​p​t​y - */ - is_not_empty: string - /** - * m​i​n - */ - min: string - /** - * m​a​x - */ - max: string - /** - * > - */ - gt: string - /** - * >​= - */ - gte: string - /** - * < - */ - lt: string - /** - * <​= - */ - lte: string - /** - * i​s​ ​s​a​m​e​ ​d​a​y - */ - is_same_day: string - /** - * i​s​ ​n​o​t​ ​s​a​m​e​ ​d​a​y - */ - is_not_same_day: string - /** - * i​s​ ​t​o​d​a​y - */ - is_tody: string - /** - * i​s​ ​n​o​t​ ​t​o​d​a​y - */ - is_not_today: string - /** - * i​s​ ​a​f​t​e​r​ ​t​o​d​a​y - */ - is_after_today: string - /** - * i​s​ ​b​e​f​o​r​e​ ​t​o​d​a​y - */ - is_before_today: string - /** - * i​s​ ​t​o​m​o​r​r​o​w - */ - is_tomorrow: string - /** - * i​s​ ​n​o​t​ ​t​o​m​o​r​r​o​w - */ - is_not_tomorrow: string - /** - * i​s​ ​a​f​t​e​r​ ​t​o​m​o​r​r​o​w - */ - is_after_tomorrow: string - /** - * i​s​ ​b​e​f​o​r​e​ ​t​o​m​o​r​r​o​w - */ - is_before_tommorow: string - /** - * i​s​ ​y​e​s​t​e​r​d​a​y - */ - is_yesterday: string - /** - * i​s​ ​n​o​t​ ​y​e​s​t​e​r​d​a​y - */ - is_not_yesterday: string - /** - * i​s​ ​a​f​t​e​r​ ​y​e​s​t​e​r​d​a​y - */ - is_after_yesterday: string - /** - * i​s​ ​b​e​f​o​r​e​ ​y​e​s​t​e​r​d​a​y - */ - is_before_yesterday: string - /** - * i​s​ ​b​e​f​o​r​e - */ - is_before: string - /** - * i​s​ ​n​o​t​ ​b​e​f​o​r​e - */ - is_not_before: string - /** - * i​s​ ​a​f​t​e​r - */ - is_after: string - /** - * i​s​ ​n​o​t​ ​a​f​t​e​r - */ - is_not_after: string - /** - * i​s​ ​t​r​u​e - */ - is_true: string - /** - * i​s​ ​f​a​l​s​e - */ - is_false: string - } - } + /** + * H​i​ ​{​n​a​m​e​}​!​ ​P​l​e​a​s​e​ ​l​e​a​v​e​ ​a​ ​s​t​a​r​ ​i​f​ ​y​o​u​ ​l​i​k​e​ ​t​h​i​s​ ​p​r​o​j​e​c​t​:​ ​h​t​t​p​s​:​/​/​g​i​t​h​u​b​.​c​o​m​/​i​v​a​n​h​o​f​e​r​/​t​y​p​e​s​a​f​e​-​i​1​8​n + * @param {string} name + */ + HI: RequiredParams<'name'> + table: { + ops: { + /** + * = + */ + eq: string + /** + * !​= + */ + neq: string + /** + * c​o​n​t​a​i​n​s + */ + contains: string + /** + * n​o​t​ ​c​o​n​t​a​i​n​s + */ + does_not_contain: string + /** + * s​t​a​r​t​s​ ​w​i​t​h + */ + starts_with: string + /** + * e​n​d​s​ ​w​i​t​h + */ + ends_with: string + /** + * i​s​ ​e​m​p​t​y + */ + is_empty: string + /** + * i​s​ ​n​o​t​ ​e​m​p​t​y + */ + is_not_empty: string + /** + * m​i​n + */ + min: string + /** + * m​a​x + */ + max: string + /** + * > + */ + gt: string + /** + * >​= + */ + gte: string + /** + * < + */ + lt: string + /** + * <​= + */ + lte: string + /** + * i​s​ ​s​a​m​e​ ​d​a​y + */ + is_same_day: string + /** + * i​s​ ​n​o​t​ ​s​a​m​e​ ​d​a​y + */ + is_not_same_day: string + /** + * i​s​ ​t​o​d​a​y + */ + is_tody: string + /** + * i​s​ ​n​o​t​ ​t​o​d​a​y + */ + is_not_today: string + /** + * i​s​ ​a​f​t​e​r​ ​t​o​d​a​y + */ + is_after_today: string + /** + * i​s​ ​b​e​f​o​r​e​ ​t​o​d​a​y + */ + is_before_today: string + /** + * i​s​ ​t​o​m​o​r​r​o​w + */ + is_tomorrow: string + /** + * i​s​ ​n​o​t​ ​t​o​m​o​r​r​o​w + */ + is_not_tomorrow: string + /** + * i​s​ ​a​f​t​e​r​ ​t​o​m​o​r​r​o​w + */ + is_after_tomorrow: string + /** + * i​s​ ​b​e​f​o​r​e​ ​t​o​m​o​r​r​o​w + */ + is_before_tommorow: string + /** + * i​s​ ​y​e​s​t​e​r​d​a​y + */ + is_yesterday: string + /** + * i​s​ ​n​o​t​ ​y​e​s​t​e​r​d​a​y + */ + is_not_yesterday: string + /** + * i​s​ ​a​f​t​e​r​ ​y​e​s​t​e​r​d​a​y + */ + is_after_yesterday: string + /** + * i​s​ ​b​e​f​o​r​e​ ​y​e​s​t​e​r​d​a​y + */ + is_before_yesterday: string + /** + * i​s​ ​b​e​f​o​r​e + */ + is_before: string + /** + * i​s​ ​n​o​t​ ​b​e​f​o​r​e + */ + is_not_before: string + /** + * i​s​ ​a​f​t​e​r + */ + is_after: string + /** + * i​s​ ​n​o​t​ ​a​f​t​e​r + */ + is_not_after: string + /** + * i​s​ ​t​r​u​e + */ + is_true: string + /** + * i​s​ ​f​a​l​s​e + */ + is_false: string + } + } } export type TranslationFunctions = { - /** - * Hi {name}! Please leave a star if you like this project: https://github.com/ivanhofer/typesafe-i18n - */ - HI: (arg: { name: string }) => LocalizedString - table: { - ops: { - /** - * = - */ - eq: () => LocalizedString - /** - * != - */ - neq: () => LocalizedString - /** - * contains - */ - contains: () => LocalizedString - /** - * not contains - */ - does_not_contain: () => LocalizedString - /** - * starts with - */ - starts_with: () => LocalizedString - /** - * ends with - */ - ends_with: () => LocalizedString - /** - * is empty - */ - is_empty: () => LocalizedString - /** - * is not empty - */ - is_not_empty: () => LocalizedString - /** - * min - */ - min: () => LocalizedString - /** - * max - */ - max: () => LocalizedString - /** - * > - */ - gt: () => LocalizedString - /** - * >= - */ - gte: () => LocalizedString - /** - * < - */ - lt: () => LocalizedString - /** - * <= - */ - lte: () => LocalizedString - /** - * is same day - */ - is_same_day: () => LocalizedString - /** - * is not same day - */ - is_not_same_day: () => LocalizedString - /** - * is today - */ - is_tody: () => LocalizedString - /** - * is not today - */ - is_not_today: () => LocalizedString - /** - * is after today - */ - is_after_today: () => LocalizedString - /** - * is before today - */ - is_before_today: () => LocalizedString - /** - * is tomorrow - */ - is_tomorrow: () => LocalizedString - /** - * is not tomorrow - */ - is_not_tomorrow: () => LocalizedString - /** - * is after tomorrow - */ - is_after_tomorrow: () => LocalizedString - /** - * is before tomorrow - */ - is_before_tommorow: () => LocalizedString - /** - * is yesterday - */ - is_yesterday: () => LocalizedString - /** - * is not yesterday - */ - is_not_yesterday: () => LocalizedString - /** - * is after yesterday - */ - is_after_yesterday: () => LocalizedString - /** - * is before yesterday - */ - is_before_yesterday: () => LocalizedString - /** - * is before - */ - is_before: () => LocalizedString - /** - * is not before - */ - is_not_before: () => LocalizedString - /** - * is after - */ - is_after: () => LocalizedString - /** - * is not after - */ - is_not_after: () => LocalizedString - /** - * is true - */ - is_true: () => LocalizedString - /** - * is false - */ - is_false: () => LocalizedString - } - } + /** + * Hi {name}! Please leave a star if you like this project: https://github.com/ivanhofer/typesafe-i18n + */ + HI: (arg: { name: string }) => LocalizedString + table: { + ops: { + /** + * = + */ + eq: () => LocalizedString + /** + * != + */ + neq: () => LocalizedString + /** + * contains + */ + contains: () => LocalizedString + /** + * not contains + */ + does_not_contain: () => LocalizedString + /** + * starts with + */ + starts_with: () => LocalizedString + /** + * ends with + */ + ends_with: () => LocalizedString + /** + * is empty + */ + is_empty: () => LocalizedString + /** + * is not empty + */ + is_not_empty: () => LocalizedString + /** + * min + */ + min: () => LocalizedString + /** + * max + */ + max: () => LocalizedString + /** + * > + */ + gt: () => LocalizedString + /** + * >= + */ + gte: () => LocalizedString + /** + * < + */ + lt: () => LocalizedString + /** + * <= + */ + lte: () => LocalizedString + /** + * is same day + */ + is_same_day: () => LocalizedString + /** + * is not same day + */ + is_not_same_day: () => LocalizedString + /** + * is today + */ + is_tody: () => LocalizedString + /** + * is not today + */ + is_not_today: () => LocalizedString + /** + * is after today + */ + is_after_today: () => LocalizedString + /** + * is before today + */ + is_before_today: () => LocalizedString + /** + * is tomorrow + */ + is_tomorrow: () => LocalizedString + /** + * is not tomorrow + */ + is_not_tomorrow: () => LocalizedString + /** + * is after tomorrow + */ + is_after_tomorrow: () => LocalizedString + /** + * is before tomorrow + */ + is_before_tommorow: () => LocalizedString + /** + * is yesterday + */ + is_yesterday: () => LocalizedString + /** + * is not yesterday + */ + is_not_yesterday: () => LocalizedString + /** + * is after yesterday + */ + is_after_yesterday: () => LocalizedString + /** + * is before yesterday + */ + is_before_yesterday: () => LocalizedString + /** + * is before + */ + is_before: () => LocalizedString + /** + * is not before + */ + is_not_before: () => LocalizedString + /** + * is after + */ + is_after: () => LocalizedString + /** + * is not after + */ + is_not_after: () => LocalizedString + /** + * is true + */ + is_true: () => LocalizedString + /** + * is false + */ + is_false: () => LocalizedString + } + } } export type Formatters = {} diff --git a/packages/i18n/src/i18n/i18n-util.async.ts b/packages/i18n/src/i18n/i18n-util.async.ts index 1967c2642..efa55d935 100644 --- a/packages/i18n/src/i18n/i18n-util.async.ts +++ b/packages/i18n/src/i18n/i18n-util.async.ts @@ -1,25 +1,26 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { initFormatters } from "./formatters.js" -import type { Locales, Translations } from "./i18n-types.js" -import { loadedFormatters, loadedLocales, locales } from "./i18n-util.js" +import { initFormatters } from './formatters.js' +import type { Locales, Translations } from './i18n-types.js' +import { loadedFormatters, loadedLocales, locales } from './i18n-util.js' const localeTranslationLoaders = { - en: () => import("./en/index.js"), + en: () => import('./en/index.js'), } 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)) +export const loadFormatters = (locale: Locales): void => + void (loadedFormatters[locale] = initFormatters(locale)) diff --git a/packages/i18n/src/i18n/i18n-util.sync.ts b/packages/i18n/src/i18n/i18n-util.sync.ts index 6d024515b..adad083a0 100644 --- a/packages/i18n/src/i18n/i18n-util.sync.ts +++ b/packages/i18n/src/i18n/i18n-util.sync.ts @@ -1,23 +1,24 @@ // This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten. /* eslint-disable */ -import { initFormatters } from "./formatters.js" -import type { Locales, Translations } from "./i18n-types.js" -import { loadedFormatters, loadedLocales, locales } from "./i18n-util.js" +import { initFormatters } from './formatters.js' +import type { Locales, Translations } from './i18n-types.js' +import { loadedFormatters, loadedLocales, locales } from './i18n-util.js' -import en from "./en/index.js" +import en from './en/index.js' const localeTranslations = { - en, + en, } 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)) +export const loadFormatters = (locale: Locales): void => + void (loadedFormatters[locale] = initFormatters(locale)) diff --git a/packages/i18n/src/i18n/i18n-util.ts b/packages/i18n/src/i18n/i18n-util.ts index a3b2a5e6d..10270522a 100644 --- a/packages/i18n/src/i18n/i18n-util.ts +++ b/packages/i18n/src/i18n/i18n-util.ts @@ -1,16 +1,18 @@ // 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.js" +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.js' -export const baseLocale: Locales = "en" +export const baseLocale: Locales = 'en' -export const locales: Locales[] = ["en"] +export const locales: Locales[] = [ + 'en' +] export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales) @@ -20,18 +22,16 @@ 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)