@v-miniapp/locale 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ import { ILocalesConfig } from './types';
3
+ export declare const LocalesProvider: ({ config, children, }: {
4
+ config?: ILocalesConfig;
5
+ children: ReactNode;
6
+ }) => ReactNode;
@@ -0,0 +1,13 @@
1
+ import { ILang, IResources, IOptionalResources, ITemplateParams, IResourceKey, IAppLanguage } from './types';
2
+ export type ILocalesStore = {
3
+ language: IAppLanguage;
4
+ systemLanguage: ILang;
5
+ initialized: boolean;
6
+ resources: IResources;
7
+ translate: (key: IResourceKey, params?: ITemplateParams, lang?: IAppLanguage) => string;
8
+ setLanguage: (language: IAppLanguage) => void;
9
+ init: (options?: {
10
+ resources?: IOptionalResources;
11
+ }) => void;
12
+ };
13
+ export declare const useLocalesStore: import('zustand').UseBoundStore<import('zustand').StoreApi<ILocalesStore>>;
@@ -0,0 +1,38 @@
1
+ type IMergeResources<A, B> = {
2
+ [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
3
+ };
4
+ type IMergeLang<D, C> = D | (C extends string ? C : never);
5
+ export interface IDefaultLocales {
6
+ resource: object;
7
+ language: 'vi' | 'en';
8
+ }
9
+ export interface ICustomLocales {
10
+ }
11
+ export interface ICustomLibLocales {
12
+ }
13
+ export interface ILocales {
14
+ resource: IMergeResources<IDefaultLocales['resource'], IMergeResources<ICustomLocales extends {
15
+ resource: infer R;
16
+ } ? R : undefined, ICustomLibLocales extends {
17
+ resource: infer R;
18
+ } ? R : undefined>>;
19
+ language: IMergeLang<IDefaultLocales['language'], IMergeLang<ICustomLocales extends {
20
+ language: infer L;
21
+ } ? L : never, ICustomLibLocales extends {
22
+ language: infer L;
23
+ } ? L : never>>;
24
+ }
25
+ export type ILang = ILocales['language'];
26
+ export type IResource = ILocales['resource'];
27
+ export type IResourceKey = keyof IResource;
28
+ export type IResources = Record<ILang, IResource>;
29
+ export type IOptionalResources = Partial<Record<ILang, Partial<IResource>>>;
30
+ export type ITranslateFunction = {
31
+ (key: IResourceKey, params?: ITemplateParams): string;
32
+ };
33
+ export type ITemplateParams = Record<string, (string | number) | undefined>;
34
+ export type IAppLanguage = ILang | 'system';
35
+ export type ILocalesConfig = {
36
+ resources?: IOptionalResources;
37
+ };
38
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ITemplateParams } from './types';
2
+ export declare function renderTemplate(value: string, params?: ITemplateParams): string;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@v-miniapp/locale",
3
+ "version": "1.0.2",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./*": "./dist/*"
15
+ },
16
+ "dependencies": {
17
+ "@types/lodash": "^4.17.23",
18
+ "lodash": "^4.17.23",
19
+ "zustand": "^5.0.9"
20
+ },
21
+ "peerDependencies": {
22
+ "react": ">=19.0.0",
23
+ "react-dom": ">=19.0.0"
24
+ },
25
+ "engines": {
26
+ "node": ">=22"
27
+ }
28
+ }