glotstack 0.0.6 → 0.0.7
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 +133 -32
- 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/eslint-raw-string.mjs +5 -1
- package/package.json +13 -8
- package/src/cli.tsx +135 -27
- package/src/index.tsx +70 -29
- package/tsconfig.json +1 -1
- package/package-lock.json +0 -4356
package/dist/cli.js
CHANGED
|
@@ -46,32 +46,87 @@ 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(`Extracting translations with: ${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
|
+
function resolveConfigAndOptions(options) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const configPath = (0, findConfig_1.findGlotstackConfig)((0, process_1.cwd)());
|
|
100
|
+
let config = {};
|
|
101
|
+
if (configPath != null) {
|
|
102
|
+
console.info('Loading config file at ', configPath);
|
|
103
|
+
try {
|
|
104
|
+
const text = yield fs_1.promises.readFile(configPath, 'utf-8');
|
|
105
|
+
config = JSON.parse(text);
|
|
106
|
+
console.info('Loaded config file', config);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
//pass
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if ('outputLocales' in options) {
|
|
113
|
+
if (options.outputLocales.includes('en-US')) {
|
|
114
|
+
console.warn('en-US detected in outputLocales, removing');
|
|
115
|
+
options.outputLocales = options.outputLocales.filter((x) => x !== 'en-US');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return (0, object_1.merge)(config, options);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
68
121
|
function run(args) {
|
|
69
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
123
|
var _a, _b;
|
|
71
124
|
commander_1.program
|
|
72
125
|
.command('extract-translations')
|
|
126
|
+
.description('extract translations from all compatible source files.')
|
|
73
127
|
.option('--source-path [path]', 'to source files root directory', '.')
|
|
74
128
|
.option('--api-origin [url]', 'glotstack api origin', (_a = process.env.GLOTSTACK_HOST) !== null && _a !== void 0 ? _a : 'https://glotstack.ai')
|
|
129
|
+
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
75
130
|
.option('--yes', 'skip confirm checks', false)
|
|
76
131
|
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
77
132
|
if (!options.apiOrigin) {
|
|
@@ -102,6 +157,15 @@ function run(args) {
|
|
|
102
157
|
const send = yield askToSend();
|
|
103
158
|
if (send) {
|
|
104
159
|
console.info('Sending files to LLM');
|
|
160
|
+
const url = `${options.apiOrigin}/uploads/translations/extract`;
|
|
161
|
+
const form = new undici_2.FormData();
|
|
162
|
+
for (let i = 0; i < filesWithIssues.length; i++) {
|
|
163
|
+
const filePath = filesWithIssues[i];
|
|
164
|
+
form.append(`file_${i}`, yield (0, node_fs_1.openAsBlob)(filePath), filePath);
|
|
165
|
+
console.debug(`Uploading file: ${filePath}`);
|
|
166
|
+
}
|
|
167
|
+
const data = yield fetchGlotstack(url, options.apiKey, form);
|
|
168
|
+
data.translations.map(elem => console.info(`${elem.name}:\n ${elem.modified_source.url}\n\n`));
|
|
105
169
|
rl.close();
|
|
106
170
|
}
|
|
107
171
|
else {
|
|
@@ -110,6 +174,7 @@ function run(args) {
|
|
|
110
174
|
}));
|
|
111
175
|
commander_1.program
|
|
112
176
|
.command('get-translations')
|
|
177
|
+
.description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
|
|
113
178
|
.option('--source-path [path]', 'path to en-US.json (or your canonical source json)')
|
|
114
179
|
.option('--api-origin [url]', 'glotstack api origin', (_b = process.env.GLOTSTACK_HOST) !== null && _b !== void 0 ? _b : 'https://glotstack.ai')
|
|
115
180
|
.option('--output-dir [path]', 'path to output directory')
|
|
@@ -130,22 +195,17 @@ function run(args) {
|
|
|
130
195
|
//pass
|
|
131
196
|
}
|
|
132
197
|
}
|
|
133
|
-
const resolved = (
|
|
134
|
-
|
|
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) {
|
|
198
|
+
const resolved = yield resolveConfigAndOptions(Object.assign(Object.assign({}, options), { outputLocales: outputLocales }));
|
|
199
|
+
if (!resolved.sourcePath) {
|
|
140
200
|
throw new Error('sourcePath must be specified');
|
|
141
201
|
}
|
|
142
|
-
if (!apiOrigin) {
|
|
202
|
+
if (!resolved.apiOrigin) {
|
|
143
203
|
throw new Error('apiOrigin must be specified');
|
|
144
204
|
}
|
|
145
|
-
if (!outputDir) {
|
|
205
|
+
if (!resolved.outputDir) {
|
|
146
206
|
throw new Error('outputDir must be specified');
|
|
147
207
|
}
|
|
148
|
-
const absPath = path_1.default.resolve(sourcePath);
|
|
208
|
+
const absPath = path_1.default.resolve(resolved.sourcePath);
|
|
149
209
|
const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
|
|
150
210
|
let json = null;
|
|
151
211
|
try {
|
|
@@ -160,14 +220,55 @@ function run(args) {
|
|
|
160
220
|
throw err;
|
|
161
221
|
}
|
|
162
222
|
}
|
|
163
|
-
const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (projectId != null ? { projectId } : {})));
|
|
164
|
-
const
|
|
223
|
+
const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (resolved.projectId != null ? { projectId: resolved.projectId } : {})));
|
|
224
|
+
const url = `${options.apiOrigin}/api/translations`;
|
|
225
|
+
const data = yield fetchGlotstack(url, resolved.apiKey, body);
|
|
165
226
|
console.info('Received translations:', data);
|
|
166
227
|
Object.entries(data.data).map(([key, val]) => {
|
|
167
|
-
const p = `${outputDir}/${key}.json`;
|
|
228
|
+
const p = `${resolved.outputDir}/${key}.json`;
|
|
168
229
|
console.info(`Writing file ${p}`);
|
|
169
|
-
fs_1.promises.writeFile(`${outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
230
|
+
fs_1.promises.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
231
|
+
});
|
|
232
|
+
}));
|
|
233
|
+
commander_1.program
|
|
234
|
+
.command('format-json')
|
|
235
|
+
.description('format files in --source-path [path] to nested (not flat)')
|
|
236
|
+
.option('--source-path [path]', 'to source files root directory', '.')
|
|
237
|
+
.option('--yes', 'skip confirm checks', false)
|
|
238
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
if (!options.sourcePath) {
|
|
240
|
+
throw new Error('sourcePath must be specified');
|
|
241
|
+
}
|
|
242
|
+
const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
243
|
+
const askToSend = () => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
if (options.yes) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
const response = yield rl.question(`This will update your source files -- have you checked them into SCM/git? Type yes to proceed (yes/no):`);
|
|
248
|
+
if (response === 'yes') {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
else if (response !== 'no') {
|
|
252
|
+
console.error('Please respond with yes or no.');
|
|
253
|
+
return askToSend();
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
170
258
|
});
|
|
259
|
+
const yes = yield askToSend();
|
|
260
|
+
if (yes) {
|
|
261
|
+
const files = yield (0, promises_1.readdir)(options.sourcePath);
|
|
262
|
+
for (let i = 0; i < (yield files).length; i++) {
|
|
263
|
+
const fp = (0, node_path_1.resolve)(options.sourcePath, files[i]);
|
|
264
|
+
const text = yield (0, promises_1.readFile)(fp, 'utf-8');
|
|
265
|
+
const json = JSON.parse(text);
|
|
266
|
+
const formatted = JSON.stringify(unflatten(json), null, 2);
|
|
267
|
+
yield (0, promises_1.writeFile)(fp, formatted);
|
|
268
|
+
}
|
|
269
|
+
rl.close();
|
|
270
|
+
}
|
|
271
|
+
rl.close();
|
|
171
272
|
}));
|
|
172
273
|
yield commander_1.program.parseAsync(args);
|
|
173
274
|
});
|
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,iCAAiC,GAAG,EAAE,CAAC,CAAA;QAEpD,MAAM,OAAO,mBACX,eAAe,EAAE,UAAU,MAAM,EAAE,IAChC,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC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AAU,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAC9B,0CAAqC;AA0BxB,QAAA,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAc;IAC/D,YAAY,EAAE,EAAE;IAChB,gBAAgB,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA,CAAC,CAAC;IACnE,SAAS,EAAE,CAAC,OAAqB,EAAE,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA,CAAC,CAAC;IAClF,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,CAAC,OAAqB,EAAE,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA,CAAC,CAAC;IACrF,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA,CAAC,CAAC;IACrD,GAAG,EAAE,KAAK;CACX,CAAC,CAAA;AAYF,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,qCAAO,CAAA;IACP,uCAAQ,CAAA;IACR,6CAAW,CAAA;IACX,yCAAS,CAAA;AACX,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB;AAED,MAAM,cAAc,GAAyE;IAC3F,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;IAC/B,CAAC,QAAQ,CAAC,IA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CAAA;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;IAE1B,OAAO,uBAAC,wBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAC7C,QAAQ,GACiB,CAAA;AAC9B,CAAC,CAAA;AApEY,QAAA,iBAAiB,qBAoE7B;AAEM,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,wBAAgB,CAAC,CAAA;AAC3C,CAAC,CAAA;AAFY,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"}
|
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
|
]);
|
package/package.json
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glotstack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "JD Cumpson",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@eslint/js": "^9.26.0",
|
|
10
11
|
"commander": "^13.1.0",
|
|
11
|
-
"eslint": "^9.26.0"
|
|
12
|
+
"eslint": "^9.26.0",
|
|
13
|
+
"eslint-plugin-i18next": "^6.1.1",
|
|
14
|
+
"eslint-plugin-react": "^7.37.5",
|
|
15
|
+
"form-data": "^4.0.2",
|
|
16
|
+
"undici": "^7.9.0"
|
|
12
17
|
},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@eslint/js": "^9.26.0",
|
|
15
19
|
"@types/js-yaml": "^4.0.9",
|
|
16
20
|
"@types/node": "^22.15.17",
|
|
17
|
-
"@types/react": "^
|
|
21
|
+
"@types/react": "^18.3.1",
|
|
22
|
+
"@types/react-dom": "^18.3.1",
|
|
18
23
|
"globals": "^16.1.0",
|
|
19
24
|
"js-yaml": "^4.1.0",
|
|
25
|
+
"nodemon": "^3.1.10",
|
|
20
26
|
"typescript": "5.4.4",
|
|
21
27
|
"typescript-eslint": "^8.32.1"
|
|
22
28
|
},
|
|
23
29
|
"peerDependencies": {
|
|
24
|
-
"react": "^
|
|
25
|
-
|
|
26
|
-
"resolutions": {
|
|
27
|
-
"react": "18.3.1"
|
|
30
|
+
"react": "^18.3.1",
|
|
31
|
+
"react-dom": "^18.3.1"
|
|
28
32
|
},
|
|
29
33
|
"bin": {
|
|
30
34
|
"glotstack": "dist/cli.js"
|
|
31
35
|
},
|
|
32
36
|
"scripts": {
|
|
33
37
|
"build": "tsc && scripts/fix-shebang.sh dist/cli.js",
|
|
38
|
+
"watch": "nodemon --watch src --ext ts,tsx,mjs,json --exec \"bash -c 'npm run build'\"",
|
|
34
39
|
"prepublishOnly": "yarn run build",
|
|
35
40
|
"glotstack": "node dist/cli.js"
|
|
36
41
|
}
|