@ayinza_dev/i18n-config 1.3.0

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,123 @@
1
+ export interface LocaleMapping {
2
+ [key: string]: string;
3
+ }
4
+ export interface CurrencyConfig {
5
+ defaultCurrency?: string;
6
+ localeMapping?: LocaleMapping;
7
+ }
8
+ export interface NumberConfig {
9
+ localeMapping?: LocaleMapping;
10
+ }
11
+ export interface DateConfig {
12
+ localeMapping?: LocaleMapping;
13
+ defaultFormat?: Intl.DateTimeFormatOptions;
14
+ }
15
+ export interface FormattersConfig {
16
+ /** Currency-specific defaults (default currency, locale mapping). */
17
+ currency?: CurrencyConfig;
18
+ /** Number formatting locale overrides. */
19
+ number?: NumberConfig;
20
+ /** Date/time formatting defaults including locale mapping. */
21
+ date?: DateConfig;
22
+ /** Locale to fall back to when a language code is missing from mappings. */
23
+ fallbackLocale?: string;
24
+ }
25
+ export interface ReactConfig {
26
+ useSuspense?: boolean;
27
+ bindI18n?: string;
28
+ bindI18nStore?: string;
29
+ }
30
+ /**
31
+ * Ayinza localization-service integration. When `baseUrl` is set, the library
32
+ * fetches the shared translation catalog for each active language and overlays
33
+ * it (deep-merge, remote wins) on top of the bundled base loaded via
34
+ * `backend.loadPath`. The Ayinza response envelope `{ data: { translations } }`
35
+ * is unwrapped automatically. Loading is lazy (a language's catalog is fetched
36
+ * on first use) and never throws — on failure the bundled base is kept.
37
+ */
38
+ export interface LocalizationConfig {
39
+ /** localization-service base URL, e.g. `https://localization.example/api/v1`. */
40
+ baseUrl: string;
41
+ /** Path appended to `baseUrl`; `{{lng}}` is substituted. Default `/l10n/translations/{{lng}}`. */
42
+ path?: string;
43
+ /** Optional `?category=` filter. notification-service scopes by project; UIs usually omit it. */
44
+ category?: string;
45
+ /** Extra request headers. */
46
+ headers?: Record<string, string>;
47
+ }
48
+ export interface I18nConfig {
49
+ /** i18next backend options (e.g., load paths, custom headers). */
50
+ backend?: {
51
+ loadPath?: string;
52
+ addPath?: string;
53
+ customHeaders?: Record<string, string>;
54
+ /**
55
+ * Transform the raw HTTP response before i18next consumes it (passed through
56
+ * to `i18next-http-backend`'s `parse`). Useful when a backend wraps the map
57
+ * in an envelope.
58
+ */
59
+ parse?: (data: string, languages?: string | string[], namespaces?: string | string[]) => Record<string, unknown>;
60
+ };
61
+ /** Ayinza localization-service integration (see {@link LocalizationConfig}). */
62
+ localization?: LocalizationConfig;
63
+ /** Browser language detection configuration. */
64
+ detection?: {
65
+ order?: string[];
66
+ caches?: string[];
67
+ lookupQuerystring?: string;
68
+ lookupCookie?: string;
69
+ lookupLocalStorage?: string;
70
+ lookupSessionStorage?: string;
71
+ };
72
+ /** Fallback language (or list) used when detection fails. */
73
+ fallbackLng?: string | string[];
74
+ /** Explicit list of supported languages to keep bundles constrained. */
75
+ supportedLngs?: string[];
76
+ /** Default namespace used by i18next. */
77
+ defaultNS?: string;
78
+ /** Namespace list to preload. */
79
+ ns?: string | string[];
80
+ /** Enable extra i18next debug logging. */
81
+ debug?: boolean;
82
+ /** Customize interpolation behavior (e.g., escapeValue). */
83
+ interpolation?: {
84
+ escapeValue?: boolean;
85
+ };
86
+ /** Formatter configuration shared by hooks and interpolation helpers. */
87
+ formatters?: FormattersConfig;
88
+ /** Optional portal identifier used for logging. */
89
+ portalName?: string;
90
+ /** React-i18next specific options (useSuspense, bindI18n, etc.). */
91
+ react?: ReactConfig;
92
+ }
93
+ export interface I18nInitOptions {
94
+ config?: Partial<I18nConfig>;
95
+ onInitialized?: () => void;
96
+ onError?: (error: Error) => void;
97
+ }
98
+ export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
99
+ export interface ParserPushConfig {
100
+ /** Friendly label for logs so multiple portals can be distinguished. */
101
+ portalName: string;
102
+ /** Optional URL to send detected keys to. When omitted the helper only logs the payload. */
103
+ pushUrl?: string;
104
+ /** Skips remote push and only logs keys. Useful for CI dry-runs. */
105
+ dryRun?: boolean;
106
+ /** Optional bearer token appended as an Authorization header. */
107
+ authorizationToken?: string;
108
+ /** Additional headers merged into the push request. */
109
+ headers?: Record<string, string>;
110
+ /** Custom fetch implementation when globalThis.fetch is unavailable. */
111
+ fetchImpl?: FetchLike;
112
+ }
113
+ export interface NewKeyPayload {
114
+ key: string;
115
+ namespace: string;
116
+ defaultValue: string;
117
+ locale: string;
118
+ filePaths?: string[];
119
+ }
120
+ export interface TranslationSnapshot {
121
+ locale: string;
122
+ namespaces: Record<string, Record<string, string>>;
123
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ const config = {
2
+ preset: "ts-jest",
3
+ testEnvironment: "jsdom",
4
+ moduleFileExtensions: ["ts", "tsx", "js"],
5
+ roots: ["<rootDir>/src"],
6
+ moduleNameMapper: {
7
+ "^(\\.{1,2}/.*)\\.js$": "$1",
8
+ },
9
+ transform: {
10
+ "^.+\\.(ts|tsx)$": [
11
+ "ts-jest",
12
+ {
13
+ tsconfig: "tsconfig.test.json",
14
+ },
15
+ ],
16
+ },
17
+ };
18
+
19
+ module.exports = config;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@ayinza_dev/i18n-config",
3
+ "version": "1.3.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "build:watch": "tsc --watch",
10
+ "test": "jest",
11
+ "test:watch": "jest --watch"
12
+ },
13
+ "keywords": [],
14
+ "author": "ayinza",
15
+ "license": "MIT",
16
+ "description": "Shared i18next configuration for multiple portals",
17
+ "peerDependencies": {
18
+ "react": "^19.1.1",
19
+ "react-i18next": "^16.2.4"
20
+ },
21
+ "dependencies": {
22
+ "i18next": "^25.6.1",
23
+ "i18next-browser-languagedetector": "^8.2.0",
24
+ "i18next-http-backend": "^3.0.2"
25
+ },
26
+ "devDependencies": {
27
+ "@types/jest": "^30.0.0",
28
+ "@types/node": "^24.10.0",
29
+ "@types/react": "^19.2.2",
30
+ "@types/react-dom": "^19.2.2",
31
+ "i18next-parser": "^9.0.2",
32
+ "jest": "^30.2.0",
33
+ "jest-environment-jsdom": "^30.2.0",
34
+ "ts-jest": "^29.4.5",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/sseris/ayinza-i18n-config.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/sseris/ayinza-i18n-config/issues"
43
+ },
44
+ "homepage": "https://github.com/sseris/ayinza-i18n-config#readme"
45
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "isolatedModules": false,
7
+ "types": ["node", "jest"]
8
+ }
9
+ }