Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
yovanoc committed Oct 2, 2022
1 parent 5555d47 commit 9ff3282
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 189 deletions.
32 changes: 23 additions & 9 deletions packages/translate/src/i18n/i18n-react.tsx
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;
196 changes: 97 additions & 99 deletions packages/translate/src/i18n/i18n-types.ts
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: {
/**
* 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 = {};
66 changes: 38 additions & 28 deletions packages/translate/src/i18n/i18n-util.async.ts
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),
});
Loading

0 comments on commit 9ff3282

Please sign in to comment.