glotstack 0.0.6 → 0.0.8
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/dist/cli.js +145 -54
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +14 -4
- package/dist/index.js +63 -19
- package/dist/index.js.map +1 -1
- package/dist/util/findConfig.d.ts +1 -1
- package/dist/util/findConfig.js +40 -13
- package/dist/util/findConfig.js.map +1 -1
- package/eslint-raw-string.mjs +5 -1
- package/package.json +13 -8
- package/src/cli.tsx +150 -50
- package/src/index.tsx +70 -29
- package/src/util/findConfig.ts +27 -11
- package/tsconfig.json +1 -1
- package/package-lock.json +0 -4356
package/dist/cli.js
CHANGED
|
@@ -46,34 +46,90 @@ const yaml_1 = require("./util/yaml");
|
|
|
46
46
|
const eslint_1 = __importDefault(require("eslint"));
|
|
47
47
|
const readline = __importStar(require("node:readline/promises"));
|
|
48
48
|
const node_process_1 = require("node:process");
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
const undici_1 = require("undici");
|
|
50
|
+
const undici_2 = require("undici");
|
|
51
|
+
const node_fs_1 = require("node:fs");
|
|
52
|
+
const promises_1 = require("node:fs/promises");
|
|
53
|
+
const node_path_1 = require("node:path");
|
|
54
|
+
const fetchGlotstack = function (url, apiKey, body, overrideHeaders) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
console.info(`Fetching glotstack.ai: ${url}`);
|
|
57
|
+
const headers = Object.assign({ 'authorization': `Bearer ${apiKey}` }, (overrideHeaders == null ? {} : overrideHeaders));
|
|
58
|
+
let payloadBody;
|
|
59
|
+
if (!(body instanceof undici_2.FormData)) {
|
|
60
|
+
headers['content-type'] = 'application/json';
|
|
61
|
+
payloadBody = JSON.stringify(body);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
payloadBody = body;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const res = yield (0, undici_1.fetch)(url, { method: 'POST', body: payloadBody, headers });
|
|
68
|
+
if (!res.ok)
|
|
69
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
70
|
+
return res.json();
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error('Fetch failed:', err);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
function unflatten(flat) {
|
|
79
|
+
const result = {};
|
|
80
|
+
for (const flatKey in flat) {
|
|
81
|
+
const parts = flatKey.split('.');
|
|
82
|
+
let current = result;
|
|
83
|
+
parts.forEach((part, idx) => {
|
|
84
|
+
if (idx === parts.length - 1) {
|
|
85
|
+
current[part] = flat[flatKey];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (!(part in current)) {
|
|
89
|
+
current[part] = {};
|
|
90
|
+
}
|
|
91
|
+
current = current[part];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
66
94
|
}
|
|
67
|
-
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
const DEFAULT_OPTIONS = {
|
|
98
|
+
sourcePath: '.',
|
|
99
|
+
sourceLocale: 'en-US',
|
|
100
|
+
apiOrigin: 'https://glotstack.ai'
|
|
101
|
+
};
|
|
102
|
+
function resolveConfigAndOptions(options) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
var _a;
|
|
105
|
+
const config = (_a = yield (0, findConfig_1.findGlotstackConfig)((0, process_1.cwd)())) !== null && _a !== void 0 ? _a : {};
|
|
106
|
+
if ('outputLocales' in options) {
|
|
107
|
+
if (options.outputLocales.includes('en-US')) {
|
|
108
|
+
console.warn('en-US detected in outputLocales, removing');
|
|
109
|
+
options.outputLocales = options.outputLocales.filter((x) => x !== 'en-US');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const resolved = (0, object_1.merge)({}, DEFAULT_OPTIONS, config, options);
|
|
113
|
+
// special case to match source
|
|
114
|
+
if (resolved.outputDir == null) {
|
|
115
|
+
resolved.outputDir = resolved.sourcePath;
|
|
116
|
+
}
|
|
117
|
+
return resolved;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
68
120
|
function run(args) {
|
|
69
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
var _a, _b;
|
|
71
122
|
commander_1.program
|
|
72
123
|
.command('extract-translations')
|
|
73
|
-
.
|
|
74
|
-
.option('--
|
|
75
|
-
.option('--
|
|
76
|
-
.
|
|
124
|
+
.description('extract translations from all compatible source files.')
|
|
125
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
126
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
127
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
128
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
129
|
+
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
130
|
+
.option('--yes', 'skip confirm checks')
|
|
131
|
+
.action((inputOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const options = yield resolveConfigAndOptions(inputOptions);
|
|
77
133
|
if (!options.apiOrigin) {
|
|
78
134
|
throw new Error('apiOrigin must be specified');
|
|
79
135
|
}
|
|
@@ -101,7 +157,16 @@ function run(args) {
|
|
|
101
157
|
});
|
|
102
158
|
const send = yield askToSend();
|
|
103
159
|
if (send) {
|
|
104
|
-
console.info('Sending files to
|
|
160
|
+
console.info('Sending files to generate new source and extracted strings');
|
|
161
|
+
const url = `${options.apiOrigin}/uploads/translations/extract`;
|
|
162
|
+
const form = new undici_2.FormData();
|
|
163
|
+
for (let i = 0; i < filesWithIssues.length; i++) {
|
|
164
|
+
const filePath = filesWithIssues[i];
|
|
165
|
+
form.append(`file_${i}`, yield (0, node_fs_1.openAsBlob)(filePath), filePath);
|
|
166
|
+
console.debug(`Uploading file: ${filePath}`);
|
|
167
|
+
}
|
|
168
|
+
const data = yield fetchGlotstack(url, options.apiKey, form);
|
|
169
|
+
data.translations.map(elem => console.info(`Source and translations available for: ${elem.name}:\n ${elem.modified_source.url}\n\n`));
|
|
105
170
|
rl.close();
|
|
106
171
|
}
|
|
107
172
|
else {
|
|
@@ -110,42 +175,26 @@ function run(args) {
|
|
|
110
175
|
}));
|
|
111
176
|
commander_1.program
|
|
112
177
|
.command('get-translations')
|
|
113
|
-
.
|
|
114
|
-
.option('--
|
|
115
|
-
.option('--
|
|
178
|
+
.description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
|
|
179
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
180
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
181
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
182
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
116
183
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
117
184
|
.option('--project-id [id]', '(optional) specific project to use')
|
|
118
185
|
.argument('[output-locales...]', 'locales to get translations for')
|
|
119
186
|
.action((outputLocales, options, command) => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
if (configPath != null) {
|
|
123
|
-
console.info('Loading config file at ', configPath);
|
|
124
|
-
try {
|
|
125
|
-
const text = yield fs_1.promises.readFile(configPath, 'utf-8');
|
|
126
|
-
config = JSON.parse(text);
|
|
127
|
-
console.info('Loaded config file', config);
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
//pass
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const resolved = (0, object_1.merge)(config, options, { outputLocales });
|
|
134
|
-
const { apiOrigin, sourcePath, outputDir, projectId } = resolved;
|
|
135
|
-
if (resolved.outputLocales.includes('en-US')) {
|
|
136
|
-
console.warn('en-US detected in outputLocales, removing');
|
|
137
|
-
resolved.outputLocales = resolved.outputLocales.filter((x) => x !== 'en-US');
|
|
138
|
-
}
|
|
139
|
-
if (!sourcePath) {
|
|
187
|
+
const resolved = yield resolveConfigAndOptions(Object.assign(Object.assign({}, options), { outputLocales: outputLocales }));
|
|
188
|
+
if (!resolved.sourcePath) {
|
|
140
189
|
throw new Error('sourcePath must be specified');
|
|
141
190
|
}
|
|
142
|
-
if (!apiOrigin) {
|
|
191
|
+
if (!resolved.apiOrigin) {
|
|
143
192
|
throw new Error('apiOrigin must be specified');
|
|
144
193
|
}
|
|
145
|
-
if (!outputDir) {
|
|
194
|
+
if (!resolved.outputDir) {
|
|
146
195
|
throw new Error('outputDir must be specified');
|
|
147
196
|
}
|
|
148
|
-
const absPath = path_1.default.resolve(sourcePath);
|
|
197
|
+
const absPath = path_1.default.resolve(resolved.sourcePath, `${resolved.sourceLocale}.json`);
|
|
149
198
|
const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
|
|
150
199
|
let json = null;
|
|
151
200
|
try {
|
|
@@ -160,14 +209,56 @@ function run(args) {
|
|
|
160
209
|
throw err;
|
|
161
210
|
}
|
|
162
211
|
}
|
|
163
|
-
const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (projectId != null ? { projectId } : {})));
|
|
164
|
-
const
|
|
212
|
+
const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (resolved.projectId != null ? { projectId: resolved.projectId } : {})));
|
|
213
|
+
const url = `${resolved.apiOrigin}/api/translations`;
|
|
214
|
+
const data = yield fetchGlotstack(url, resolved.apiKey, body);
|
|
165
215
|
console.info('Received translations:', data);
|
|
166
216
|
Object.entries(data.data).map(([key, val]) => {
|
|
167
|
-
const p = `${outputDir}/${key}.json`;
|
|
217
|
+
const p = `${resolved.outputDir}/${key}.json`;
|
|
168
218
|
console.info(`Writing file ${p}`);
|
|
169
|
-
fs_1.promises.writeFile(`${outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
219
|
+
fs_1.promises.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
220
|
+
});
|
|
221
|
+
}));
|
|
222
|
+
commander_1.program
|
|
223
|
+
.command('format-json')
|
|
224
|
+
.description('format files in --source-path [path] to nested (not flat)')
|
|
225
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
226
|
+
.option('--yes', 'skip confirm checks')
|
|
227
|
+
.action((inputOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
const options = yield resolveConfigAndOptions(inputOptions);
|
|
229
|
+
if (!options.sourcePath) {
|
|
230
|
+
throw new Error('sourcePath must be specified');
|
|
231
|
+
}
|
|
232
|
+
const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
233
|
+
const askToSend = () => __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
if (options.yes) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
const response = yield rl.question(`This will update your source files -- have you checked them into SCM/git? Type yes to proceed (yes/no):`);
|
|
238
|
+
if (response === 'yes') {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
else if (response !== 'no') {
|
|
242
|
+
console.error('Please respond with yes or no.');
|
|
243
|
+
return askToSend();
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
170
248
|
});
|
|
249
|
+
const yes = yield askToSend();
|
|
250
|
+
if (yes) {
|
|
251
|
+
const files = yield (0, promises_1.readdir)(options.sourcePath);
|
|
252
|
+
for (let i = 0; i < (yield files).length; i++) {
|
|
253
|
+
const fp = (0, node_path_1.resolve)(options.sourcePath, files[i]);
|
|
254
|
+
const text = yield (0, promises_1.readFile)(fp, 'utf-8');
|
|
255
|
+
const json = JSON.parse(text);
|
|
256
|
+
const formatted = JSON.stringify(unflatten(json), null, 2);
|
|
257
|
+
yield (0, promises_1.writeFile)(fp, formatted);
|
|
258
|
+
}
|
|
259
|
+
rl.close();
|
|
260
|
+
}
|
|
261
|
+
rl.close();
|
|
171
262
|
}));
|
|
172
263
|
yield commander_1.program.parseAsync(args);
|
|
173
264
|
});
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,gDAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,gDAAuB;AACvB,2BAAqD;AACrD,kDAAuD;AACvD,qCAA6B;AAC7B,0CAAqC;AACrC,sCAAsC;AACtC,oDAA2B;AAC3B,iEAAkD;AAClD,+CAA+D;AAE/D,mCAA8B;AAC9B,mCAAiC;AACjC,qCAAoC;AACpC,+CAA+D;AAC/D,yCAAmC;AAEnC,MAAM,cAAc,GAAG,UAAmB,GAAW,EAAE,MAAc,EAAE,IAAoC,EAAE,eAAqC;;QAChJ,OAAO,CAAC,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAA;QAE7C,MAAM,OAAO,mBACX,eAAe,EAAE,UAAU,MAAM,EAAE,IAChC,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CACpD,CAAA;QAED,IAAI,WAA8B,CAAA;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CAAA;gBACd,CAAC;YACH,CAAC,CAAA,CAAA;YACD,MAAM,GAAG,GAAG,MAAM,SAAS,EAAE,CAAA;YAC7B,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,KAAK,GAAG,MAAM,IAAA,kBAAO,EAAC,OAAO,CAAC,UAAU,CAAC,CAAA;gBAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC9C,MAAM,EAAE,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;oBAChD,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,EAAE,EAAE,OAAO,CAAC,CAAA;oBACxC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;oBAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;oBAC1D,MAAM,IAAA,oBAAS,EAAC,EAAE,EAAE,SAAS,CAAC,CAAA;gBAChC,CAAC;gBACD,EAAE,CAAC,KAAK,EAAE,CAAA;YACZ,CAAC;YACD,EAAE,CAAC,KAAK,EAAE,CAAA;QAEZ,CAAC,CAAA,CAAC,CAAA;QAGJ,MAAM,mBAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CAAA;AAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
export type LocaleRegion =
|
|
2
|
+
export type LocaleRegion = string;
|
|
3
3
|
export interface TranslationLeaf {
|
|
4
4
|
value: string;
|
|
5
5
|
context?: string;
|
|
@@ -16,18 +16,28 @@ export interface ContextType {
|
|
|
16
16
|
t: (key: string, options?: {
|
|
17
17
|
locale?: LocaleRegion;
|
|
18
18
|
}) => string;
|
|
19
|
+
ssr: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare const GlotstackContext: React.Context<ContextType>;
|
|
21
22
|
interface GlotstackProviderProps {
|
|
22
23
|
children: React.ReactNode;
|
|
23
|
-
initialTranslations?: Translations
|
|
24
|
+
initialTranslations?: Record<string, Translations>;
|
|
24
25
|
initialLocale?: LocaleRegion;
|
|
25
26
|
onTranslationLoaded?: (locale: LocaleRegion, translations: Translations) => void;
|
|
26
27
|
onLocaleChange?: (locale: LocaleRegion) => void;
|
|
27
|
-
importMethod:
|
|
28
|
+
importMethod: ContextType['importMethod'];
|
|
29
|
+
ssr?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare enum LogLevel {
|
|
32
|
+
DEBUG = 0,
|
|
33
|
+
LOG = 1,
|
|
34
|
+
INFO = 2,
|
|
35
|
+
WARNING = 3,
|
|
36
|
+
ERROR = 4
|
|
28
37
|
}
|
|
38
|
+
export declare const setLogLevel: (level: LogLevel) => void;
|
|
29
39
|
export declare const access: (key: string, locale: LocaleRegion, translations: Translations) => string;
|
|
30
|
-
export declare const GlotstackProvider: ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod }: GlotstackProviderProps) =>
|
|
40
|
+
export declare const GlotstackProvider: ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod, ssr }: GlotstackProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
41
|
export declare const useGlotstack: () => ContextType;
|
|
32
42
|
export declare const useTranslations: (_options?: Record<never, never>) => ContextType;
|
|
33
43
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -32,8 +32,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.useTranslations = exports.useGlotstack = exports.GlotstackProvider = exports.access = exports.GlotstackContext = void 0;
|
|
35
|
+
exports.useTranslations = exports.useGlotstack = exports.GlotstackProvider = exports.access = exports.setLogLevel = exports.LogLevel = exports.GlotstackContext = void 0;
|
|
36
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
36
37
|
const React = __importStar(require("react"));
|
|
38
|
+
const object_1 = require("./util/object");
|
|
37
39
|
exports.GlotstackContext = React.createContext({
|
|
38
40
|
translations: {},
|
|
39
41
|
loadTranslations: () => { throw new Error('no import method set'); },
|
|
@@ -41,9 +43,46 @@ exports.GlotstackContext = React.createContext({
|
|
|
41
43
|
locale: null,
|
|
42
44
|
importMethod: (_locale) => { throw new Error('import method not set'); },
|
|
43
45
|
t: () => { throw new Error('import method not set'); },
|
|
46
|
+
ssr: false
|
|
44
47
|
});
|
|
48
|
+
var LogLevel;
|
|
49
|
+
(function (LogLevel) {
|
|
50
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
51
|
+
LogLevel[LogLevel["LOG"] = 1] = "LOG";
|
|
52
|
+
LogLevel[LogLevel["INFO"] = 2] = "INFO";
|
|
53
|
+
LogLevel[LogLevel["WARNING"] = 3] = "WARNING";
|
|
54
|
+
LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
|
|
55
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
56
|
+
const LogLevelToFunc = {
|
|
57
|
+
[LogLevel.DEBUG]: console.debug,
|
|
58
|
+
[LogLevel.INFO]: console.info,
|
|
59
|
+
[LogLevel.LOG]: console.log,
|
|
60
|
+
[LogLevel.WARNING]: console.warn,
|
|
61
|
+
[LogLevel.ERROR]: console.error,
|
|
62
|
+
};
|
|
63
|
+
let logLevel = LogLevel.DEBUG;
|
|
64
|
+
const setLogLevel = (level) => {
|
|
65
|
+
logLevel = level;
|
|
66
|
+
};
|
|
67
|
+
exports.setLogLevel = setLogLevel;
|
|
68
|
+
const makeLoggingFunction = (level) => (...args) => {
|
|
69
|
+
const func = LogLevelToFunc[level];
|
|
70
|
+
if (level < logLevel) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return func(`[level=${level} logLevel=${logLevel}][glotstack.ai]`, ...args);
|
|
74
|
+
};
|
|
75
|
+
const logger = {
|
|
76
|
+
debug: makeLoggingFunction(LogLevel.DEBUG),
|
|
77
|
+
info: makeLoggingFunction(LogLevel.INFO),
|
|
78
|
+
warn: makeLoggingFunction(LogLevel.WARNING),
|
|
79
|
+
error: makeLoggingFunction(LogLevel.ERROR),
|
|
80
|
+
};
|
|
45
81
|
const access = (key, locale, translations) => {
|
|
46
82
|
var _a;
|
|
83
|
+
if (translations == null) {
|
|
84
|
+
return key;
|
|
85
|
+
}
|
|
47
86
|
const access = [...key.split('.')];
|
|
48
87
|
const localeTranslations = translations === null || translations === void 0 ? void 0 : translations[locale];
|
|
49
88
|
if (localeTranslations == null) {
|
|
@@ -56,21 +95,29 @@ const access = (key, locale, translations) => {
|
|
|
56
95
|
return ((_a = value === null || value === void 0 ? void 0 : value.value) !== null && _a !== void 0 ? _a : key);
|
|
57
96
|
};
|
|
58
97
|
exports.access = access;
|
|
59
|
-
const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod }) => {
|
|
98
|
+
const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod, ssr }) => {
|
|
60
99
|
if (initialLocale == null) {
|
|
61
100
|
throw new Error('initialLocale must be set');
|
|
62
101
|
}
|
|
63
102
|
const [locale, setLocale] = React.useState(initialLocale);
|
|
64
|
-
const translationsRef = React.useRef(initialTranslations);
|
|
103
|
+
const translationsRef = React.useRef(initialTranslations || null);
|
|
65
104
|
const loadingRef = React.useRef({});
|
|
66
|
-
const loadTranslations = React.useCallback((locale) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
var _a, _b;
|
|
105
|
+
const loadTranslations = React.useCallback((locale, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f;
|
|
68
107
|
// TODO: if translations are loaded only reload if some condition is
|
|
69
108
|
try {
|
|
70
|
-
if (((_a = loadingRef.current) === null || _a === void 0 ? void 0 : _a[locale]) != null) {
|
|
109
|
+
if (((_a = loadingRef.current) === null || _a === void 0 ? void 0 : _a[locale]) != null && (opts === null || opts === void 0 ? void 0 : opts.force) != true) {
|
|
110
|
+
logger.debug('Waiting for translations already loading', locale);
|
|
71
111
|
return (yield ((_b = loadingRef.current) === null || _b === void 0 ? void 0 : _b[locale]));
|
|
72
112
|
}
|
|
73
|
-
|
|
113
|
+
if (((_c = translationsRef.current) === null || _c === void 0 ? void 0 : _c[locale]) != null && (opts === null || opts === void 0 ? void 0 : opts.force) != true) {
|
|
114
|
+
logger.debug('Skipping load for translations', locale, (_d = translationsRef.current) === null || _d === void 0 ? void 0 : _d[locale], translationsRef.current);
|
|
115
|
+
return (_e = translationsRef.current) === null || _e === void 0 ? void 0 : _e[locale];
|
|
116
|
+
}
|
|
117
|
+
if (loadingRef.current != null) {
|
|
118
|
+
logger.debug('Loading translations', locale, (0, object_1.merge)({}, (_f = translationsRef.current) !== null && _f !== void 0 ? _f : {}));
|
|
119
|
+
loadingRef.current[locale] = importMethod(locale);
|
|
120
|
+
}
|
|
74
121
|
const result = yield loadingRef.current[locale];
|
|
75
122
|
if (result == null) {
|
|
76
123
|
throw new Error(`Failed to load translation ${locale} ${JSON.stringify(result)}`);
|
|
@@ -82,14 +129,14 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
82
129
|
return result;
|
|
83
130
|
}
|
|
84
131
|
catch (err) {
|
|
85
|
-
|
|
132
|
+
logger.error('Unable to import translations', err);
|
|
86
133
|
throw err;
|
|
87
134
|
}
|
|
88
135
|
}), [importMethod, onTranslationLoaded]);
|
|
89
136
|
React.useEffect(() => {
|
|
90
137
|
const run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
138
|
onLocaleChange === null || onLocaleChange === void 0 ? void 0 : onLocaleChange(locale);
|
|
92
|
-
|
|
139
|
+
yield loadTranslations(locale);
|
|
93
140
|
});
|
|
94
141
|
React.startTransition(() => {
|
|
95
142
|
run();
|
|
@@ -104,18 +151,15 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
104
151
|
importMethod,
|
|
105
152
|
loadTranslations,
|
|
106
153
|
t: (key, opts) => {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}, [locale, opts === null || opts === void 0 ? void 0 : opts.locale]);
|
|
114
|
-
return (0, exports.access)(key, (_a = opts === null || opts === void 0 ? void 0 : opts.locale) !== null && _a !== void 0 ? _a : locale, (_b = translationsRef.current) !== null && _b !== void 0 ? _b : {});
|
|
115
|
-
}
|
|
154
|
+
var _a, _b, _c;
|
|
155
|
+
const resolvedLocale = (_a = opts === null || opts === void 0 ? void 0 : opts.locale) !== null && _a !== void 0 ? _a : locale;
|
|
156
|
+
loadTranslations(resolvedLocale);
|
|
157
|
+
return (0, exports.access)(key, (_b = opts === null || opts === void 0 ? void 0 : opts.locale) !== null && _b !== void 0 ? _b : locale, (_c = translationsRef.current) !== null && _c !== void 0 ? _c : {});
|
|
158
|
+
},
|
|
159
|
+
ssr: ssr == true,
|
|
116
160
|
};
|
|
117
161
|
}, [locale, importMethod]);
|
|
118
|
-
return
|
|
162
|
+
return (0, jsx_runtime_1.jsx)(exports.GlotstackContext.Provider, { value: context, children: children });
|
|
119
163
|
};
|
|
120
164
|
exports.GlotstackProvider = GlotstackProvider;
|
|
121
165
|
const useGlotstack = () => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings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QAAA,YAAY,gBAExB;AAEM,MAAM,eAAe,GAAG,CAAC,QAA+B,EAAE,EAAE;IACjE,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,wBAAgB,CAAC,CAAA;IAClD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAHY,QAAA,eAAe,mBAG3B"}
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param startDir The directory to start the search from. Defaults to process.cwd().
|
|
4
4
|
* @returns The absolute path to the file if found, or null if not found.
|
|
5
5
|
*/
|
|
6
|
-
export declare function findGlotstackConfig(startDir?: string):
|
|
6
|
+
export declare function findGlotstackConfig(startDir?: string): Promise<object | null>;
|
package/dist/util/findConfig.js
CHANGED
|
@@ -22,29 +22,56 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
35
|
exports.findGlotstackConfig = void 0;
|
|
27
|
-
const
|
|
36
|
+
const fs_1 = require("fs");
|
|
37
|
+
const promises_1 = require("fs/promises");
|
|
28
38
|
const path = __importStar(require("path"));
|
|
29
39
|
/**
|
|
30
40
|
* Recursively looks for `.glotstack.json` from the current directory up to the root.
|
|
31
41
|
* @param startDir The directory to start the search from. Defaults to process.cwd().
|
|
32
42
|
* @returns The absolute path to the file if found, or null if not found.
|
|
33
43
|
*/
|
|
34
|
-
function findGlotstackConfig(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
function findGlotstackConfig() {
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* (startDir = process.cwd()) {
|
|
46
|
+
let currentDir = path.resolve(startDir);
|
|
47
|
+
let configPath = null;
|
|
48
|
+
while (true) {
|
|
49
|
+
const candidate = path.join(currentDir, '.glotstack.json');
|
|
50
|
+
if ((0, fs_1.existsSync)(candidate)) {
|
|
51
|
+
configPath = candidate;
|
|
52
|
+
}
|
|
53
|
+
const parentDir = path.dirname(currentDir);
|
|
54
|
+
if (parentDir === currentDir) {
|
|
55
|
+
break; // Reached root
|
|
56
|
+
}
|
|
57
|
+
currentDir = parentDir;
|
|
40
58
|
}
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
59
|
+
let config = {};
|
|
60
|
+
if (configPath != null) {
|
|
61
|
+
console.info('Loading config file at ', configPath);
|
|
62
|
+
try {
|
|
63
|
+
const text = yield (0, promises_1.readFile)(configPath, 'utf-8');
|
|
64
|
+
config = JSON.parse(text);
|
|
65
|
+
console.info('Loaded config file', config);
|
|
66
|
+
return config;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
console.warn('Could not load config', configPath);
|
|
70
|
+
}
|
|
44
71
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
console.warn('Could not find any .glotstack.json config files');
|
|
73
|
+
return null;
|
|
74
|
+
});
|
|
48
75
|
}
|
|
49
76
|
exports.findGlotstackConfig = findGlotstackConfig;
|
|
50
77
|
//# sourceMappingURL=findConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../src/util/findConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3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H,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;CAAA;AAhCD,kDAgCC"}
|
package/eslint-raw-string.mjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import globals from "globals";
|
|
2
2
|
import tseslint from "typescript-eslint";
|
|
3
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
4
4
|
import i18next from 'eslint-plugin-i18next';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export default defineConfig([
|
|
8
8
|
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"], languageOptions: { globals: globals.browser } },
|
|
9
|
+
globalIgnores([
|
|
10
|
+
'node_modules/*', // ignore node modules
|
|
11
|
+
'**/*.d.ts', // ignore type definitions
|
|
12
|
+
]),
|
|
9
13
|
tseslint.configs.base,
|
|
10
14
|
i18next.configs['flat/recommended'],
|
|
11
15
|
]);
|