@forgedevstack/lingo 1.0.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.
- package/CHANGELOG.md +17 -0
- package/README.md +257 -0
- package/dist/constants/index.d.ts +12 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +553 -0
- package/dist/lingo-react/index.d.ts +53 -0
- package/dist/lingo-react/index.d.ts.map +1 -0
- package/dist/load-local-bundles.d.ts +3 -0
- package/dist/load-local-bundles.d.ts.map +1 -0
- package/dist/locale-globs.d.ts +13 -0
- package/dist/locale-globs.d.ts.map +1 -0
- package/dist/logo.d.ts +7 -0
- package/dist/logo.d.ts.map +1 -0
- package/dist/normalize-config.d.ts +3 -0
- package/dist/normalize-config.d.ts.map +1 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +89 -0
- package/dist/types/index.d.ts +176 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/index.d.ts +30 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createContext as w, createElement as i, useState as L, useEffect as C, useCallback as m, useMemo as S, useContext as I } from "react";
|
|
2
|
+
const b = w(null), P = ({ instance: e, children: n }) => {
|
|
3
|
+
const [o, s] = L(e.locale), [r, c] = L(e.direction), [t, a] = L(e.isLoading), [h, p] = L(0), [f, E] = L(null);
|
|
4
|
+
C(() => e.subscribe((l) => {
|
|
5
|
+
s(l.locale), c(l.direction), a(l.isLoading), p(l.stateRevision), E(l.remoteFetchError);
|
|
6
|
+
}), [e]);
|
|
7
|
+
const d = m(
|
|
8
|
+
async (g) => {
|
|
9
|
+
await e.setLocale(g);
|
|
10
|
+
},
|
|
11
|
+
[e]
|
|
12
|
+
), v = m(
|
|
13
|
+
(g, l) => e.t(g, l),
|
|
14
|
+
[e, h]
|
|
15
|
+
), R = S(
|
|
16
|
+
() => ({
|
|
17
|
+
t: v,
|
|
18
|
+
locale: o,
|
|
19
|
+
setLocale: d,
|
|
20
|
+
locales: e.locales,
|
|
21
|
+
direction: r,
|
|
22
|
+
isLoading: t,
|
|
23
|
+
remoteFetchError: f,
|
|
24
|
+
getLocaleInfo: e.getLocaleInfo,
|
|
25
|
+
refreshRemote: e.refreshRemote.bind(e)
|
|
26
|
+
}),
|
|
27
|
+
[e, v, o, r, t, f, d]
|
|
28
|
+
);
|
|
29
|
+
return i(
|
|
30
|
+
b.Provider,
|
|
31
|
+
{ value: R },
|
|
32
|
+
i("div", { dir: r, lang: o }, n)
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
function u() {
|
|
36
|
+
const e = I(b);
|
|
37
|
+
if (!e)
|
|
38
|
+
throw new Error("useLingo must be used within a <LingoProvider>");
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
function k() {
|
|
42
|
+
const { t: e } = u();
|
|
43
|
+
return e;
|
|
44
|
+
}
|
|
45
|
+
function D() {
|
|
46
|
+
const { locale: e, setLocale: n, locales: o } = u();
|
|
47
|
+
return { locale: e, setLocale: n, locales: o };
|
|
48
|
+
}
|
|
49
|
+
function $() {
|
|
50
|
+
const { direction: e } = u();
|
|
51
|
+
return e;
|
|
52
|
+
}
|
|
53
|
+
const x = ({ k: e, vars: n, as: o = "span", className: s, style: r }) => {
|
|
54
|
+
const { t: c } = u();
|
|
55
|
+
return i(o, { className: s, style: r }, c(e, n));
|
|
56
|
+
}, y = ({ k: e, vars: n, as: o = "span", className: s, style: r, children: c }) => {
|
|
57
|
+
const { t } = u(), a = t(e, n);
|
|
58
|
+
return c ? i(o, { className: s, style: r }, c(a)) : i(o, { className: s, style: r }, a);
|
|
59
|
+
}, M = ({ className: e, style: n }) => {
|
|
60
|
+
const { locale: o, setLocale: s, locales: r, getLocaleInfo: c } = u();
|
|
61
|
+
return i(
|
|
62
|
+
"select",
|
|
63
|
+
{
|
|
64
|
+
value: o,
|
|
65
|
+
onChange: (t) => s(t.target.value),
|
|
66
|
+
className: e,
|
|
67
|
+
style: n,
|
|
68
|
+
"aria-label": "Select language"
|
|
69
|
+
},
|
|
70
|
+
r.map((t) => {
|
|
71
|
+
const a = c(t);
|
|
72
|
+
return i(
|
|
73
|
+
"option",
|
|
74
|
+
{ key: t, value: t },
|
|
75
|
+
a ? `${a.flag ?? ""} ${a.nativeName}` : t
|
|
76
|
+
);
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
y as Lingo,
|
|
82
|
+
P as LingoProvider,
|
|
83
|
+
M as LocaleSwitcher,
|
|
84
|
+
x as T,
|
|
85
|
+
$ as useDirection,
|
|
86
|
+
u as useLingo,
|
|
87
|
+
D as useLocale,
|
|
88
|
+
k as useTranslate
|
|
89
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/** Locale code (e.g. 'en', 'es', 'fr', 'ar', 'he', 'zh') */
|
|
2
|
+
export type Locale = string;
|
|
3
|
+
/** Direction: LTR or RTL */
|
|
4
|
+
export type Direction = 'ltr' | 'rtl';
|
|
5
|
+
/** A flat or nested map of translation keys to strings */
|
|
6
|
+
export interface TranslationMap {
|
|
7
|
+
[key: string]: string | TranslationMap;
|
|
8
|
+
}
|
|
9
|
+
/** All translations for a project: locale → key map */
|
|
10
|
+
export type TranslationBundle = Record<Locale, TranslationMap>;
|
|
11
|
+
/** Interpolation variables passed to t() */
|
|
12
|
+
export type TranslateVars = Record<string, string | number | boolean>;
|
|
13
|
+
/** Plural rules: { one: '...', few: '...', many: '...', other: '...' } */
|
|
14
|
+
export interface PluralEntry {
|
|
15
|
+
zero?: string;
|
|
16
|
+
one?: string;
|
|
17
|
+
two?: string;
|
|
18
|
+
few?: string;
|
|
19
|
+
many?: string;
|
|
20
|
+
other: string;
|
|
21
|
+
}
|
|
22
|
+
export type RemoteSourceConfig = {
|
|
23
|
+
projectId: string;
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
};
|
|
27
|
+
export type RemoteTranslationSource = {
|
|
28
|
+
type: 'remote';
|
|
29
|
+
remotes: RemoteSourceConfig[];
|
|
30
|
+
} | ({
|
|
31
|
+
type: 'remote';
|
|
32
|
+
} & RemoteSourceConfig);
|
|
33
|
+
/** Source of translations: bundled locally or fetched from Lingo Portal */
|
|
34
|
+
export type TranslationSource = {
|
|
35
|
+
type: 'local';
|
|
36
|
+
translations: TranslationBundle;
|
|
37
|
+
} | RemoteTranslationSource | {
|
|
38
|
+
type: 'hybrid';
|
|
39
|
+
remote: RemoteSourceConfig | RemoteSourceConfig[];
|
|
40
|
+
local?: TranslationBundle;
|
|
41
|
+
};
|
|
42
|
+
/** Locale metadata */
|
|
43
|
+
export interface LocaleInfo {
|
|
44
|
+
code: Locale;
|
|
45
|
+
name: string;
|
|
46
|
+
nativeName: string;
|
|
47
|
+
direction: Direction;
|
|
48
|
+
flag?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Main configuration */
|
|
51
|
+
export interface LingoConfig {
|
|
52
|
+
/** Default locale (used on first load) */
|
|
53
|
+
defaultLocale: Locale;
|
|
54
|
+
/** Fallback locale when a key is missing in the active locale */
|
|
55
|
+
fallbackLocale?: Locale;
|
|
56
|
+
/** List of supported locales */
|
|
57
|
+
locales: Locale[];
|
|
58
|
+
/**
|
|
59
|
+
* Optional path bundle (e.g. Vite eager globs). When set with `source`, not required at call site.
|
|
60
|
+
* Same as calling `buildLocaleLayersFromGlobs` and passing bundles into `source`.
|
|
61
|
+
*/
|
|
62
|
+
localeLayersFromGlobs?: LocaleGlobMapsInput;
|
|
63
|
+
/** Where translations come from */
|
|
64
|
+
source: TranslationSource;
|
|
65
|
+
/**
|
|
66
|
+
* When a key has no dots, try `namespace + '.' + key` in order (e.g. `t('title')` → `common.title`).
|
|
67
|
+
*/
|
|
68
|
+
namespaces?: string[];
|
|
69
|
+
/** Cache translations in localStorage (default: true) */
|
|
70
|
+
cache?: boolean;
|
|
71
|
+
/** Key to use in localStorage (default: 'lingo_locale') */
|
|
72
|
+
storageKey?: string;
|
|
73
|
+
/** Log missing keys to console in dev (default: true) */
|
|
74
|
+
debug?: boolean;
|
|
75
|
+
/** Called when locale changes */
|
|
76
|
+
onLocaleChange?: (locale: Locale) => void;
|
|
77
|
+
/** Called when a translation key is missing */
|
|
78
|
+
onMissingKey?: (key: string, locale: Locale) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Minimum milliseconds between automatic remote refetches for the same locale.
|
|
81
|
+
* Avoids hammering the API when setLocale or subscribers repeat.
|
|
82
|
+
*/
|
|
83
|
+
remoteRevalidateIntervalMs?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Optional WebSocket URL. When the server sends a message with
|
|
86
|
+
* `{ "type": "lingo:bundle-updated", "locales": ["en"] }` (locales optional),
|
|
87
|
+
* remote cache for those locales is invalidated and the active locale refetches once.
|
|
88
|
+
*/
|
|
89
|
+
remoteBundleWebSocketUrl?: string;
|
|
90
|
+
/**
|
|
91
|
+
* If set, only these dotted keys from the remote bundle are merged (after unflatten). Local / hybrid overlay is unchanged.
|
|
92
|
+
*/
|
|
93
|
+
remoteKeysAllowlist?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* When a key is missing, return this instead of the raw key. Does not run interpolation.
|
|
96
|
+
* Maps are checked in order: exact dotted key, then namespace segment (first path segment) for any key under that namespace.
|
|
97
|
+
*/
|
|
98
|
+
missingKeyFallback?: MissingKeyFallback;
|
|
99
|
+
}
|
|
100
|
+
export type MissingKeyFallbackMap = Record<string, string>;
|
|
101
|
+
export type MissingKeyFallback = string | MissingKeyFallbackMap | MissingKeyFallbackMap[] | ((key: string, locale: Locale) => string);
|
|
102
|
+
export type LocaleGlobMapsInput = {
|
|
103
|
+
locales: Locale[];
|
|
104
|
+
baseGlob: Record<string, unknown>;
|
|
105
|
+
overlayGlob?: Record<string, unknown>;
|
|
106
|
+
};
|
|
107
|
+
/** The translate function */
|
|
108
|
+
export type TranslateFn = (key: string, vars?: TranslateVars) => string;
|
|
109
|
+
/** The public Lingo instance */
|
|
110
|
+
export interface LingoInstance {
|
|
111
|
+
/** Translate a key */
|
|
112
|
+
t: TranslateFn;
|
|
113
|
+
/** Current active locale */
|
|
114
|
+
locale: Locale;
|
|
115
|
+
/** Change the active locale */
|
|
116
|
+
setLocale: (locale: Locale) => Promise<void>;
|
|
117
|
+
/** All supported locales */
|
|
118
|
+
locales: Locale[];
|
|
119
|
+
/** Direction of the current locale */
|
|
120
|
+
direction: Direction;
|
|
121
|
+
/** Get locale metadata */
|
|
122
|
+
getLocaleInfo: (locale: Locale) => LocaleInfo | undefined;
|
|
123
|
+
/** Check if translations are loading (remote source) */
|
|
124
|
+
isLoading: boolean;
|
|
125
|
+
/** Last remote fetch error message, if any */
|
|
126
|
+
remoteFetchError: string | null;
|
|
127
|
+
/** Subscribe to locale changes */
|
|
128
|
+
subscribe: (listener: LingoListener) => () => void;
|
|
129
|
+
/** Get all translations for the current locale */
|
|
130
|
+
getTranslations: () => TranslationMap;
|
|
131
|
+
/** Add or override translations at runtime */
|
|
132
|
+
addTranslations: (locale: Locale, translations: TranslationMap) => void;
|
|
133
|
+
/** Refetch remote (and re-apply hybrid local overlay). Dedupes concurrent fetches per locale. */
|
|
134
|
+
refreshRemote: (options?: {
|
|
135
|
+
locale?: Locale;
|
|
136
|
+
force?: boolean;
|
|
137
|
+
}) => Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
/** Listener callback for state changes */
|
|
140
|
+
export type LingoListener = (state: LingoState) => void;
|
|
141
|
+
/** Internal state */
|
|
142
|
+
export interface LingoState {
|
|
143
|
+
locale: Locale;
|
|
144
|
+
direction: Direction;
|
|
145
|
+
isLoading: boolean;
|
|
146
|
+
translations: TranslationBundle;
|
|
147
|
+
stateRevision: number;
|
|
148
|
+
remoteFetchError: string | null;
|
|
149
|
+
}
|
|
150
|
+
/** Namespace descriptor (used in Portal) */
|
|
151
|
+
export interface LingoNamespace {
|
|
152
|
+
id: string;
|
|
153
|
+
name: string;
|
|
154
|
+
keys: LingoKey[];
|
|
155
|
+
}
|
|
156
|
+
/** Single translation key (used in Portal) */
|
|
157
|
+
export interface LingoKey {
|
|
158
|
+
id: string;
|
|
159
|
+
key: string;
|
|
160
|
+
description?: string;
|
|
161
|
+
values: Record<Locale, string>;
|
|
162
|
+
namespace?: string;
|
|
163
|
+
tags?: string[];
|
|
164
|
+
updatedAt?: string;
|
|
165
|
+
}
|
|
166
|
+
/** Project (used in Portal) */
|
|
167
|
+
export interface LingoProject {
|
|
168
|
+
id: string;
|
|
169
|
+
name: string;
|
|
170
|
+
locales: Locale[];
|
|
171
|
+
defaultLocale: Locale;
|
|
172
|
+
namespaces: LingoNamespace[];
|
|
173
|
+
createdAt: string;
|
|
174
|
+
updatedAt: string;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,4BAA4B;AAC5B,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAEtC,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC;CACxC;AAED,uDAAuD;AACvD,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAE/D,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAEtE,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IAC1B,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GAAG,IAAI,CAAC;CACjC;AAED,4CAA4C;AAC5C,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,EAAE,CAAC;CAClB;AAED,8CAA8C;AAC9C,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,+BAA+B;AAC/B,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TranslationMap, TranslateVars, PluralEntry, Direction, Locale, TranslationBundle, MissingKeyFallback } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a dot-separated key from a nested translation map.
|
|
4
|
+
* e.g. resolveKey({ auth: { login: 'Sign In' } }, 'auth.login') → 'Sign In'
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveKey(map: TranslationMap, key: string): string | PluralEntry | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Interpolate variables into a string.
|
|
9
|
+
* e.g. interpolate('Hello, {{name}}!', { name: 'John' }) → 'Hello, John!'
|
|
10
|
+
*/
|
|
11
|
+
export declare function interpolate(template: string, vars?: TranslateVars): string;
|
|
12
|
+
/**
|
|
13
|
+
* Select the correct plural form for a given count.
|
|
14
|
+
* Follows CLDR plural categories: zero, one, two, few, many, other.
|
|
15
|
+
*/
|
|
16
|
+
export declare function selectPlural(entry: PluralEntry, count: number, locale: Locale): string;
|
|
17
|
+
/** Get text direction for a locale */
|
|
18
|
+
export declare function getDirection(locale: Locale): Direction;
|
|
19
|
+
/** Flatten a nested translation map into dot-separated keys */
|
|
20
|
+
export declare function flattenTranslations(map: TranslationMap, prefix?: string): Record<string, string>;
|
|
21
|
+
export declare function dedupeStutterNamespaceInFlatKeys(flat: Record<string, string>): Record<string, string>;
|
|
22
|
+
/** Unflatten dot-separated keys back into a nested map */
|
|
23
|
+
export declare function unflattenTranslations(flat: Record<string, string>): TranslationMap;
|
|
24
|
+
/** Merge two translation maps (deep merge, b overrides a) */
|
|
25
|
+
export declare function mergeTranslations(a: TranslationMap, b: TranslationMap): TranslationMap;
|
|
26
|
+
export declare function mergeTranslationBundles(a: TranslationBundle, b: TranslationBundle): TranslationBundle;
|
|
27
|
+
export declare function warnLocalOverridesRemote(remoteNested: TranslationMap, localNested: TranslationMap, debug: boolean): void;
|
|
28
|
+
export declare function resolveMissingKeyFallback(key: string, locale: Locale, fb: MissingKeyFallback | undefined): string | undefined;
|
|
29
|
+
export declare function parseMissingKeyFallbackEnv(raw: string): MissingKeyFallback | undefined;
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAGlB;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAY7F;AAED;;;GAGG;AACH,wBA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|
+
{
|
|
2
|
+
"name": "@forgedevstack/lingo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Translation and localization library for ForgeStack. Manage languages, keys, and AI-powered translations.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/react/index.d.ts",
|
|
17
|
+
"import": "./dist/react/index.js",
|
|
18
|
+
"require": "./dist/react/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"CHANGELOG.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite build --watch",
|
|
28
|
+
"build": "tsc && vite build",
|
|
29
|
+
"lint": "eslint . --ext ts,tsx",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"react": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.3.18",
|
|
42
|
+
"@types/node": "^22.10.7",
|
|
43
|
+
"react": "^18.3.1",
|
|
44
|
+
"typescript": "^5.7.3",
|
|
45
|
+
"vite": "^6.0.7",
|
|
46
|
+
"vite-plugin-dts": "^4.4.0"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"translation",
|
|
50
|
+
"localization",
|
|
51
|
+
"lingo",
|
|
52
|
+
"languages",
|
|
53
|
+
"forgestack",
|
|
54
|
+
"react",
|
|
55
|
+
"multilingual"
|
|
56
|
+
],
|
|
57
|
+
"author": "John Yaghobieh",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/AY-Space/forgestack.git"
|
|
62
|
+
}
|
|
63
|
+
}
|