@enact/i18n
Version:
Internationalization support for Enact using iLib
91 lines (83 loc) • 2.71 kB
TypeScript
// Type definitions for i18n/I18nDecorator
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
export interface I18nDecoratorConfig extends Object {
/**
* Array of locales that should be treated as latin regardless of their script.
*/
latinLanguageOverrides?: string[];
/**
* Array of locales that should be treated as non-latin regardless of their script.
*/
nonLatinLanguageOverrides?: string[];
/**
* Array of resource loaders to be invoked after a locale change.
*
* Each loader must be a function which accepts an object and returns either the resource when
`options.sync` is `true` or a `Promise` for the resource when `options.sync` is `false` .
* ```
resources: [
(options) => new Promise((resolve, reject) => {
fetchResource({onLoad: resolve, onError: reject});
})
]
```
* If you need to handle the resource in some way on load, you can pass an object with an
`onLoad` member that will be called once all resources have been loaded. This should be used
if loading a resource has side effects that should only be applied once all loading has
completed.
* ```
resources: [
{resource: (options) => { ... fetch ... }, onLoad: (res) => { ... apply side effect ... }}
]
```
*/
resources?: Function | object[];
/**
* Retrieve i18n resource files synchronously.
*/
sync?: boolean;
}
export interface I18nDecoratorProps {
/**
* Classes to apply to the wrapped component.
*/
className?: string;
/**
* The locale to use.
*
* A string with a . The
system locale will be used by default.
*/
locale?: string;
}
export function I18nDecorator<P>(
config: I18nDecoratorConfig,
Component: React.ComponentType<P> | string,
): React.ComponentType<P & I18nDecoratorProps>;
export function I18nDecorator<P>(
Component: React.ComponentType<P> | string,
): React.ComponentType<P & I18nDecoratorProps>;
export interface I18nContextDecoratorConfig extends Object {
/**
* The prop name for `locale` property of i18nContext.
*/
localeProp?: string;
/**
* The prop name for `rtl` property of i18nContext.
*/
rtlProp?: string;
/**
* The prop name for `updateLocale` property of i18nContext.
*/
updateLocaleProp?: string;
}
export interface I18nContextDecoratorProps {}
export function I18nContextDecorator<P>(
config: I18nContextDecoratorConfig,
Component: React.ComponentType<P> | string,
): React.ComponentType<P & I18nContextDecoratorProps>;
export function I18nContextDecorator<P>(
Component: React.ComponentType<P> | string,
): React.ComponentType<P & I18nContextDecoratorProps>;
export default I18nDecorator;