glotstack 0.0.7 → 0.0.9
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 +71 -50
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.js +74 -1
- package/dist/index.js.map +1 -1
- package/dist/util/findConfig.d.ts +1 -1
- package/dist/util/findConfig.js +56 -13
- package/dist/util/findConfig.js.map +1 -1
- package/package.json +3 -3
- package/src/cli.tsx +81 -53
- package/src/index.tsx +105 -4
- package/src/util/findConfig.ts +41 -11
package/dist/cli.js
CHANGED
|
@@ -53,7 +53,7 @@ const promises_1 = require("node:fs/promises");
|
|
|
53
53
|
const node_path_1 = require("node:path");
|
|
54
54
|
const fetchGlotstack = function (url, apiKey, body, overrideHeaders) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
console.info(`
|
|
56
|
+
console.info(`Fetching glotstack.ai: ${url}`);
|
|
57
57
|
const headers = Object.assign({ 'authorization': `Bearer ${apiKey}` }, (overrideHeaders == null ? {} : overrideHeaders));
|
|
58
58
|
let payloadBody;
|
|
59
59
|
if (!(body instanceof undici_2.FormData)) {
|
|
@@ -94,46 +94,50 @@ function unflatten(flat) {
|
|
|
94
94
|
}
|
|
95
95
|
return result;
|
|
96
96
|
}
|
|
97
|
+
const DEFAULT_OPTIONS = {
|
|
98
|
+
sourcePath: '.',
|
|
99
|
+
sourceLocale: 'en-US',
|
|
100
|
+
apiOrigin: 'https://glotstack.ai',
|
|
101
|
+
yaml: 'false',
|
|
102
|
+
};
|
|
97
103
|
function resolveConfigAndOptions(options) {
|
|
98
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
config = JSON.parse(text);
|
|
106
|
-
console.info('Loaded config file', config);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
//pass
|
|
110
|
-
}
|
|
105
|
+
var _a;
|
|
106
|
+
const config = (_a = yield (0, findConfig_1.findGlotstackConfig)((0, process_1.cwd)())) !== null && _a !== void 0 ? _a : {};
|
|
107
|
+
const resolved = (0, object_1.merge)({}, DEFAULT_OPTIONS, config, options);
|
|
108
|
+
// special case to match source
|
|
109
|
+
if (resolved.outputDir == null) {
|
|
110
|
+
resolved.outputDir = resolved.sourcePath;
|
|
111
111
|
}
|
|
112
112
|
if ('outputLocales' in options) {
|
|
113
|
-
if (
|
|
114
|
-
console.warn(
|
|
115
|
-
options.outputLocales = options.outputLocales.filter((x) => x !==
|
|
113
|
+
if (resolved.outputLocales.includes(resolved.sourceLocale)) {
|
|
114
|
+
console.warn(`${resolved.sourceLocale} detected in outputLocales, removing`);
|
|
115
|
+
options.outputLocales = options.outputLocales.filter((x) => x !== resolved.sourceLocale);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return resolved;
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
function run(args) {
|
|
122
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
var _a, _b;
|
|
124
123
|
commander_1.program
|
|
125
124
|
.command('extract-translations')
|
|
126
125
|
.description('extract translations from all compatible source files.')
|
|
127
|
-
.option('--source-path [path]',
|
|
128
|
-
.option('--
|
|
126
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
127
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
128
|
+
.option('--yaml', 'Use a .yaml source file and allow conversion to JSON')
|
|
129
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
130
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
129
131
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
130
|
-
.option('--yes', 'skip confirm checks'
|
|
131
|
-
.
|
|
132
|
+
.option('--yes', 'skip confirm checks')
|
|
133
|
+
.argument('[directories...]', 'Directories to scan', './**/*')
|
|
134
|
+
.action((directories, inputOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const options = yield resolveConfigAndOptions(inputOptions);
|
|
132
136
|
if (!options.apiOrigin) {
|
|
133
137
|
throw new Error('apiOrigin must be specified');
|
|
134
138
|
}
|
|
135
139
|
const linter = new eslint_1.default.ESLint({ overrideConfigFile: path_1.default.join(__dirname, '..', 'eslint-raw-string.mjs') });
|
|
136
|
-
const results = yield linter.lintFiles(
|
|
140
|
+
const results = yield linter.lintFiles(directories);
|
|
137
141
|
const filesWithIssues = results
|
|
138
142
|
.filter((r) => r.errorCount + r.warningCount > 0)
|
|
139
143
|
.map((r) => r.filePath);
|
|
@@ -156,8 +160,11 @@ function run(args) {
|
|
|
156
160
|
});
|
|
157
161
|
const send = yield askToSend();
|
|
158
162
|
if (send) {
|
|
159
|
-
console.info('Sending files to
|
|
160
|
-
|
|
163
|
+
console.info('Sending files to generate new source and extracted strings');
|
|
164
|
+
let url = `${options.apiOrigin}/uploads/translations/extract`;
|
|
165
|
+
if (options.yaml) {
|
|
166
|
+
url = `${url}?yaml=true`;
|
|
167
|
+
}
|
|
161
168
|
const form = new undici_2.FormData();
|
|
162
169
|
for (let i = 0; i < filesWithIssues.length; i++) {
|
|
163
170
|
const filePath = filesWithIssues[i];
|
|
@@ -165,7 +172,7 @@ function run(args) {
|
|
|
165
172
|
console.debug(`Uploading file: ${filePath}`);
|
|
166
173
|
}
|
|
167
174
|
const data = yield fetchGlotstack(url, options.apiKey, form);
|
|
168
|
-
data.translations.map(elem => console.info(
|
|
175
|
+
data.translations.map(elem => console.info(`Source and translations available for: ${elem.name}:\n ${elem.modified_source.url}\n\n`));
|
|
169
176
|
rl.close();
|
|
170
177
|
}
|
|
171
178
|
else {
|
|
@@ -175,26 +182,16 @@ function run(args) {
|
|
|
175
182
|
commander_1.program
|
|
176
183
|
.command('get-translations')
|
|
177
184
|
.description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
|
|
178
|
-
.option('--source-path [path]',
|
|
179
|
-
.option('--
|
|
180
|
-
.option('--
|
|
185
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
186
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
187
|
+
.option('--yaml', 'Expect to use yaml source file')
|
|
188
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
189
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
181
190
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
182
191
|
.option('--project-id [id]', '(optional) specific project to use')
|
|
192
|
+
.option('--only [locale]', '(optional) only translate for this locale')
|
|
183
193
|
.argument('[output-locales...]', 'locales to get translations for')
|
|
184
194
|
.action((outputLocales, options, command) => __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
const configPath = (0, findConfig_1.findGlotstackConfig)((0, process_1.cwd)());
|
|
186
|
-
let config = {};
|
|
187
|
-
if (configPath != null) {
|
|
188
|
-
console.info('Loading config file at ', configPath);
|
|
189
|
-
try {
|
|
190
|
-
const text = yield fs_1.promises.readFile(configPath, 'utf-8');
|
|
191
|
-
config = JSON.parse(text);
|
|
192
|
-
console.info('Loaded config file', config);
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
//pass
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
195
|
const resolved = yield resolveConfigAndOptions(Object.assign(Object.assign({}, options), { outputLocales: outputLocales }));
|
|
199
196
|
if (!resolved.sourcePath) {
|
|
200
197
|
throw new Error('sourcePath must be specified');
|
|
@@ -205,7 +202,8 @@ function run(args) {
|
|
|
205
202
|
if (!resolved.outputDir) {
|
|
206
203
|
throw new Error('outputDir must be specified');
|
|
207
204
|
}
|
|
208
|
-
const
|
|
205
|
+
const ext = options.yaml == true ? '.yaml' : '.json';
|
|
206
|
+
const absPath = path_1.default.resolve(resolved.sourcePath, `${resolved.sourceLocale}${ext}`);
|
|
209
207
|
const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
|
|
210
208
|
let json = null;
|
|
211
209
|
try {
|
|
@@ -220,22 +218,45 @@ function run(args) {
|
|
|
220
218
|
throw err;
|
|
221
219
|
}
|
|
222
220
|
}
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
let locales = resolved.outputLocales.map(l => l);
|
|
222
|
+
if (options.only != null) {
|
|
223
|
+
locales = locales.filter(l => l === options.only);
|
|
224
|
+
}
|
|
225
|
+
const body = Object.assign({ locales, translations: json, usage: options.usage }, Object.assign({}, (resolved.projectId != null ? { projectId: resolved.projectId } : {})));
|
|
226
|
+
const url = `${resolved.apiOrigin}/api/translations`;
|
|
227
|
+
console.info('Getting translations for: ', locales);
|
|
225
228
|
const data = yield fetchGlotstack(url, resolved.apiKey, body);
|
|
226
229
|
console.info('Received translations:', data);
|
|
227
230
|
Object.entries(data.data).map(([key, val]) => {
|
|
228
231
|
const p = `${resolved.outputDir}/${key}.json`;
|
|
229
232
|
console.info(`Writing file ${p}`);
|
|
230
|
-
fs_1.promises.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
233
|
+
fs_1.promises.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2), 'utf-8');
|
|
231
234
|
});
|
|
235
|
+
if (options.yaml) {
|
|
236
|
+
const fp = `${resolved.outputDir}/${path_1.default.parse(absPath).name}.json`;
|
|
237
|
+
console.info(`Writing file ${fp}`);
|
|
238
|
+
fs_1.promises.writeFile(fp, JSON.stringify(json, null, 2), 'utf-8');
|
|
239
|
+
}
|
|
240
|
+
}));
|
|
241
|
+
commander_1.program
|
|
242
|
+
.command('yaml-to-json')
|
|
243
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
244
|
+
.action((inputOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const options = yield resolveConfigAndOptions(inputOptions);
|
|
246
|
+
const absPath = path_1.default.resolve(options.sourcePath, `${options.sourceLocale}.yaml`);
|
|
247
|
+
const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
|
|
248
|
+
const fp = `${options.outputDir}/${path_1.default.parse(absPath).name}.json`;
|
|
249
|
+
const json = (0, yaml_1.loadYaml)(fileContent);
|
|
250
|
+
console.info(`Writing file ${fp}`);
|
|
251
|
+
fs_1.promises.writeFile(fp, JSON.stringify(json, null, 2), 'utf-8');
|
|
232
252
|
}));
|
|
233
253
|
commander_1.program
|
|
234
254
|
.command('format-json')
|
|
235
255
|
.description('format files in --source-path [path] to nested (not flat)')
|
|
236
|
-
.option('--source-path [path]',
|
|
237
|
-
.option('--yes', 'skip confirm checks'
|
|
238
|
-
.action((
|
|
256
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
257
|
+
.option('--yes', 'skip confirm checks')
|
|
258
|
+
.action((inputOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
const options = yield resolveConfigAndOptions(inputOptions);
|
|
239
260
|
if (!options.sourcePath) {
|
|
240
261
|
throw new Error('sourcePath must be specified');
|
|
241
262
|
}
|
|
@@ -264,7 +285,7 @@ function run(args) {
|
|
|
264
285
|
const text = yield (0, promises_1.readFile)(fp, 'utf-8');
|
|
265
286
|
const json = JSON.parse(text);
|
|
266
287
|
const formatted = JSON.stringify(unflatten(json), null, 2);
|
|
267
|
-
yield (0, promises_1.writeFile)(fp, formatted);
|
|
288
|
+
yield (0, promises_1.writeFile)(fp, formatted, 'utf-8');
|
|
268
289
|
}
|
|
269
290
|
rl.close();
|
|
270
291
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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AE,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,EAAE,OAAO,CAAC,CAAA;gBACzC,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
|
@@ -40,4 +40,17 @@ export declare const access: (key: string, locale: LocaleRegion, translations: T
|
|
|
40
40
|
export declare const GlotstackProvider: ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod, ssr }: GlotstackProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
41
41
|
export declare const useGlotstack: () => ContextType;
|
|
42
42
|
export declare const useTranslations: (_options?: Record<never, never>) => ContextType;
|
|
43
|
+
export type ParsedSimplePlaceholder = {
|
|
44
|
+
key: string;
|
|
45
|
+
options: string[];
|
|
46
|
+
raw: string;
|
|
47
|
+
index: number;
|
|
48
|
+
kind: 'doubleCurly' | 'component';
|
|
49
|
+
};
|
|
50
|
+
export declare function extractSimplePlaceholders(input: string): ParsedSimplePlaceholder[];
|
|
51
|
+
type Renderer = (props: {
|
|
52
|
+
children: React.ReactNode;
|
|
53
|
+
}) => React.ReactNode;
|
|
54
|
+
export declare function renderPlaceholdersToNodes(input: string, placeholders: ParsedSimplePlaceholder[], assigns: Record<string, React.ReactNode | Renderer>): React.ReactNode[];
|
|
55
|
+
export declare function useRenderPlaceholdersToNodes(...args: Parameters<typeof renderPlaceholdersToNodes>): React.ReactNode[];
|
|
43
56
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ 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.setLogLevel = exports.LogLevel = exports.GlotstackContext = void 0;
|
|
35
|
+
exports.useRenderPlaceholdersToNodes = exports.renderPlaceholdersToNodes = exports.extractSimplePlaceholders = exports.useTranslations = exports.useGlotstack = exports.GlotstackProvider = exports.access = exports.setLogLevel = exports.LogLevel = exports.GlotstackContext = void 0;
|
|
36
36
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
37
|
const React = __importStar(require("react"));
|
|
38
38
|
const object_1 = require("./util/object");
|
|
@@ -171,4 +171,77 @@ const useTranslations = (_options) => {
|
|
|
171
171
|
return context;
|
|
172
172
|
};
|
|
173
173
|
exports.useTranslations = useTranslations;
|
|
174
|
+
const curlyRegex = /(?<!\\)({{\s*([a-zA-Z0-9_]+)\s*(?:,\s*([^{}]*?))?\s*}})/g;
|
|
175
|
+
const componentRegex = /<([A-Z][a-zA-Z0-9]*)>([\s\S]*?)<\/\1>/g;
|
|
176
|
+
function extractSimplePlaceholders(input) {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
const results = [];
|
|
179
|
+
for (const match of input.matchAll(curlyRegex)) {
|
|
180
|
+
const raw = match[1];
|
|
181
|
+
const key = match[2];
|
|
182
|
+
const rawOptions = match[3];
|
|
183
|
+
const index = (_a = match.index) !== null && _a !== void 0 ? _a : -1;
|
|
184
|
+
const options = rawOptions
|
|
185
|
+
? rawOptions.split(',').map(opt => opt.trim()).filter(Boolean)
|
|
186
|
+
: [];
|
|
187
|
+
results.push({ key, options, raw, index, kind: 'doubleCurly' });
|
|
188
|
+
}
|
|
189
|
+
for (const match of input.matchAll(componentRegex)) {
|
|
190
|
+
const raw = match[0];
|
|
191
|
+
const key = match[1];
|
|
192
|
+
const index = (_b = match.index) !== null && _b !== void 0 ? _b : -1;
|
|
193
|
+
results.push({ key, options: [], raw, index, kind: 'component' });
|
|
194
|
+
}
|
|
195
|
+
return results.sort((a, b) => a.index - b.index);
|
|
196
|
+
}
|
|
197
|
+
exports.extractSimplePlaceholders = extractSimplePlaceholders;
|
|
198
|
+
function renderPlaceholdersToNodes(input, placeholders, assigns) {
|
|
199
|
+
const nodes = [];
|
|
200
|
+
let cursor = 0;
|
|
201
|
+
for (const { index, raw, key, kind } of placeholders) {
|
|
202
|
+
if (cursor < index) {
|
|
203
|
+
nodes.push(input.slice(cursor, index));
|
|
204
|
+
}
|
|
205
|
+
let value = raw;
|
|
206
|
+
if (kind === 'component') {
|
|
207
|
+
const Render = assigns[key];
|
|
208
|
+
const inner = raw.replace(new RegExp(`^<${key}>`), '').replace(new RegExp(`</${key}>$`), '');
|
|
209
|
+
if (React.isValidElement(Render)) {
|
|
210
|
+
value = React.cloneElement(Render, {}, inner);
|
|
211
|
+
}
|
|
212
|
+
else if (typeof Render === 'function') {
|
|
213
|
+
value = (0, jsx_runtime_1.jsx)(Render, { children: inner });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
logger.warn(`Invalid assign substitution for:\n\n ${raw}\n\nDid you remember to pass assigns?\n`, `
|
|
217
|
+
t('key', { assigns: {
|
|
218
|
+
${key}: <something /> // children will be copied via React.cloneElement
|
|
219
|
+
}})\nor\n
|
|
220
|
+
t('key', { assigns: {
|
|
221
|
+
${key}: MyComponent // component will be rendered with <Component/>
|
|
222
|
+
}})\n
|
|
223
|
+
`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (kind === 'doubleCurly') {
|
|
227
|
+
const Render = assigns[key];
|
|
228
|
+
value = typeof Render !== 'function' ? Render : raw !== null && raw !== void 0 ? raw : raw;
|
|
229
|
+
}
|
|
230
|
+
nodes.push(value);
|
|
231
|
+
cursor = index + raw.length;
|
|
232
|
+
}
|
|
233
|
+
if (cursor < input.length) {
|
|
234
|
+
nodes.push(input.slice(cursor));
|
|
235
|
+
}
|
|
236
|
+
// Unescape \{{...}} to {{...}}, and wrap ReactNodes
|
|
237
|
+
return nodes.map((node, i) => typeof node === 'string'
|
|
238
|
+
? node.replace(/\\({{[^{}]+}})/g, '$1')
|
|
239
|
+
: (0, jsx_runtime_1.jsx)(React.Fragment, { children: node }, i));
|
|
240
|
+
}
|
|
241
|
+
exports.renderPlaceholdersToNodes = renderPlaceholdersToNodes;
|
|
242
|
+
function useRenderPlaceholdersToNodes(...args) {
|
|
243
|
+
const nodes = React.useMemo(() => renderPlaceholdersToNodes(...args), [...args]);
|
|
244
|
+
return nodes;
|
|
245
|
+
}
|
|
246
|
+
exports.useRenderPlaceholdersToNodes = useRenderPlaceholdersToNodes;
|
|
174
247
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CA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G,IAAI,CAAC,CAAC,CAAA;IAChF,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,oEAGC"}
|
|
@@ -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,72 @@ 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"));
|
|
39
|
+
const yaml_1 = require("./yaml");
|
|
29
40
|
/**
|
|
30
41
|
* Recursively looks for `.glotstack.json` from the current directory up to the root.
|
|
31
42
|
* @param startDir The directory to start the search from. Defaults to process.cwd().
|
|
32
43
|
* @returns The absolute path to the file if found, or null if not found.
|
|
33
44
|
*/
|
|
34
|
-
function findGlotstackConfig(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
function findGlotstackConfig() {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (startDir = process.cwd()) {
|
|
47
|
+
let currentDir = path.resolve(startDir);
|
|
48
|
+
let configPath = null;
|
|
49
|
+
while (true) {
|
|
50
|
+
const jsonCandidate = path.join(currentDir, '.glotstack.json');
|
|
51
|
+
const yamlCandidate = path.join(currentDir, '.glotstack.yaml');
|
|
52
|
+
const jsonExists = (0, fs_1.existsSync)(jsonCandidate);
|
|
53
|
+
const yamlExists = (0, fs_1.existsSync)(yamlCandidate);
|
|
54
|
+
if (jsonExists && yamlExists) {
|
|
55
|
+
console.error('Both .glotstack.json and .glotstack.yaml exist, please delete one\n\n json: ', jsonCandidate, '\n yaml: ', yamlCandidate);
|
|
56
|
+
throw new Error('Two config formats cannot be used at the same time');
|
|
57
|
+
}
|
|
58
|
+
else if (jsonExists) {
|
|
59
|
+
configPath = jsonCandidate;
|
|
60
|
+
}
|
|
61
|
+
else if (yamlExists) {
|
|
62
|
+
configPath = yamlCandidate;
|
|
63
|
+
}
|
|
64
|
+
const parentDir = path.dirname(currentDir);
|
|
65
|
+
if (parentDir === currentDir) {
|
|
66
|
+
break; // Reached root
|
|
67
|
+
}
|
|
68
|
+
currentDir = parentDir;
|
|
40
69
|
}
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
70
|
+
let config = {};
|
|
71
|
+
if (configPath != null) {
|
|
72
|
+
console.info('Loading config file at ', configPath);
|
|
73
|
+
try {
|
|
74
|
+
const text = yield (0, promises_1.readFile)(configPath, 'utf-8');
|
|
75
|
+
if (path.parse(configPath).ext === '.yaml') {
|
|
76
|
+
config = (0, yaml_1.loadYaml)(text);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
config = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
console.info('Loaded config file', config);
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.warn('Could not load config', configPath);
|
|
86
|
+
}
|
|
44
87
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
88
|
+
console.warn('Could not find any .glotstack config files');
|
|
89
|
+
return null;
|
|
90
|
+
});
|
|
48
91
|
}
|
|
49
92
|
exports.findGlotstackConfig = findGlotstackConfig;
|
|
50
93
|
//# sourceMappingURL=findConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../src/util/findConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../src/util/findConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA+B;AAC/B,0CAAsC;AACtC,2CAA4B;AAC5B,iCAAiC;AAEjC;;;;GAIG;AACH,SAAsB,mBAAmB;yDAAC,WAAmB,OAAO,CAAC,GAAG,EAAE;QACxE,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACvC,IAAI,UAAU,GAAG,IAAI,CAAA;QAErB,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAA;YAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAA;YAC9D,MAAM,UAAU,GAAG,IAAA,eAAU,EAAC,aAAa,CAAC,CAAA;YAC5C,MAAM,UAAU,GAAG,IAAA,eAAU,EAAC,aAAa,CAAC,CAAA;YAC5C,IAAI,UAAU,IAAI,UAAU,EAAE,CAAC;gBAC7B,OAAO,CAAC,KAAK,CAAC,+EAA+E,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,CAAC,CAAA;gBAC1I,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAA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
|
"name": "glotstack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "JD Cumpson",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc && scripts/fix-shebang.sh dist/cli.js",
|
|
38
|
-
"watch": "nodemon --watch src --ext ts,tsx,mjs,json --exec \"bash -c '
|
|
39
|
-
"prepublishOnly": "yarn
|
|
38
|
+
"watch": "nodemon --watch src --ext ts,tsx,mjs,json --exec \"bash -c 'yarn build'\"",
|
|
39
|
+
"prepublishOnly": "yarn build",
|
|
40
40
|
"glotstack": "node dist/cli.js"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/cli.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import { readdir, readFile, writeFile } from 'node:fs/promises'
|
|
|
16
16
|
import { resolve } from 'node:path'
|
|
17
17
|
|
|
18
18
|
const fetchGlotstack = async function <T>(url: string, apiKey: string, body: Record<string, any> | FormData, overrideHeaders?: Record<string, any>): Promise<T> {
|
|
19
|
-
console.info(`
|
|
19
|
+
console.info(`Fetching glotstack.ai: ${url}`)
|
|
20
20
|
|
|
21
21
|
const headers: Record<string, any> = {
|
|
22
22
|
'authorization': `Bearer ${apiKey}`,
|
|
@@ -64,30 +64,30 @@ function unflatten(flat: Record<string, any>): Record<string, any> {
|
|
|
64
64
|
return result
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
const DEFAULT_OPTIONS: Record<string, string> = {
|
|
68
|
+
sourcePath: '.',
|
|
69
|
+
sourceLocale: 'en-US',
|
|
70
|
+
apiOrigin: 'https://glotstack.ai',
|
|
71
|
+
yaml: 'false',
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
async function resolveConfigAndOptions(options: Record<string, any>) {
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const text = await fs.readFile(configPath, 'utf-8')
|
|
76
|
-
config = JSON.parse(text)
|
|
77
|
-
console.info('Loaded config file', config)
|
|
78
|
-
} catch (err) {
|
|
79
|
-
//pass
|
|
80
|
-
}
|
|
75
|
+
|
|
76
|
+
const config = await findGlotstackConfig(cwd()) ?? {}
|
|
77
|
+
const resolved = merge({}, DEFAULT_OPTIONS, config, options)
|
|
78
|
+
|
|
79
|
+
// special case to match source
|
|
80
|
+
if (resolved.outputDir == null) {
|
|
81
|
+
resolved.outputDir = resolved.sourcePath
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if ('outputLocales' in options) {
|
|
84
|
-
if ((
|
|
85
|
-
console.warn(
|
|
86
|
-
options.outputLocales = options.outputLocales.filter((x: string) => x !==
|
|
85
|
+
if ((resolved.outputLocales as string[]).includes(resolved.sourceLocale)) {
|
|
86
|
+
console.warn(`${resolved.sourceLocale} detected in outputLocales, removing`)
|
|
87
|
+
options.outputLocales = options.outputLocales.filter((x: string) => x !== resolved.sourceLocale)
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
return merge(config, options)
|
|
90
|
+
return resolved
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
|
|
@@ -95,17 +95,22 @@ async function run(args: string[]) {
|
|
|
95
95
|
program
|
|
96
96
|
.command('extract-translations')
|
|
97
97
|
.description('extract translations from all compatible source files.')
|
|
98
|
-
.option('--source-path [path]',
|
|
99
|
-
.option('--
|
|
98
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
99
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
100
|
+
.option('--yaml', 'Use a .yaml source file and allow conversion to JSON')
|
|
101
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
102
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
100
103
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
101
|
-
.option('--yes', 'skip confirm checks'
|
|
102
|
-
.
|
|
104
|
+
.option('--yes', 'skip confirm checks')
|
|
105
|
+
.argument('[directories...]', 'Directories to scan', './**/*')
|
|
106
|
+
.action(async (directories: string[], inputOptions: Record<string, any>) => {
|
|
107
|
+
const options = await resolveConfigAndOptions(inputOptions)
|
|
103
108
|
if (!options.apiOrigin) {
|
|
104
109
|
throw new Error('apiOrigin must be specified')
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
const linter = new eslint.ESLint({ overrideConfigFile: path.join(__dirname, '..', 'eslint-raw-string.mjs') })
|
|
108
|
-
const results = await linter.lintFiles(
|
|
113
|
+
const results = await linter.lintFiles(directories)
|
|
109
114
|
const filesWithIssues = results
|
|
110
115
|
.filter((r) => r.errorCount + r.warningCount > 0)
|
|
111
116
|
.map((r) => r.filePath)
|
|
@@ -128,8 +133,13 @@ async function run(args: string[]) {
|
|
|
128
133
|
|
|
129
134
|
const send = await askToSend()
|
|
130
135
|
if (send) {
|
|
131
|
-
console.info('Sending files to
|
|
132
|
-
|
|
136
|
+
console.info('Sending files to generate new source and extracted strings')
|
|
137
|
+
let url = `${options.apiOrigin}/uploads/translations/extract`
|
|
138
|
+
|
|
139
|
+
if (options.yaml) {
|
|
140
|
+
url = `${url}?yaml=true`
|
|
141
|
+
}
|
|
142
|
+
|
|
133
143
|
const form = new FormData()
|
|
134
144
|
|
|
135
145
|
for (let i = 0; i < filesWithIssues.length; i++) {
|
|
@@ -138,7 +148,7 @@ async function run(args: string[]) {
|
|
|
138
148
|
console.debug(`Uploading file: ${filePath}`)
|
|
139
149
|
}
|
|
140
150
|
const data = await fetchGlotstack<{ translations: { name: string; modified_source: { url: string } }[] }>(url, options.apiKey, form)
|
|
141
|
-
data.translations.map(elem => console.info(
|
|
151
|
+
data.translations.map(elem => console.info(`Source and translations available for: ${elem.name}:\n ${elem.modified_source.url}\n\n`))
|
|
142
152
|
rl.close()
|
|
143
153
|
} else {
|
|
144
154
|
rl.close()
|
|
@@ -148,28 +158,17 @@ async function run(args: string[]) {
|
|
|
148
158
|
program
|
|
149
159
|
.command('get-translations')
|
|
150
160
|
.description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
|
|
151
|
-
.option('--source-path [path]',
|
|
152
|
-
.option('--
|
|
153
|
-
.option('--
|
|
161
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
162
|
+
.option('--source-locale [locale]', `the locale you provide "context" in, your primary locale (default=${DEFAULT_OPTIONS['sourceLocale']})`)
|
|
163
|
+
.option('--yaml', 'Expect to use yaml source file')
|
|
164
|
+
.option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
|
|
165
|
+
.option('--output-dir [path]', 'path to output directory (default=<source-path>')
|
|
154
166
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
155
167
|
.option('--project-id [id]', '(optional) specific project to use')
|
|
168
|
+
.option('--only [locale]', '(optional) only translate for this locale')
|
|
156
169
|
.argument('[output-locales...]', 'locales to get translations for')
|
|
157
170
|
.action(async (outputLocales: string[], options: Record<string, any>, command: Command) => {
|
|
158
|
-
const
|
|
159
|
-
let config = {}
|
|
160
|
-
|
|
161
|
-
if (configPath != null) {
|
|
162
|
-
console.info('Loading config file at ', configPath)
|
|
163
|
-
try {
|
|
164
|
-
const text = await fs.readFile(configPath, 'utf-8')
|
|
165
|
-
config = JSON.parse(text)
|
|
166
|
-
console.info('Loaded config file', config)
|
|
167
|
-
} catch (err) {
|
|
168
|
-
//pass
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const resolved = await resolveConfigAndOptions({...options, outputLocales: outputLocales})
|
|
171
|
+
const resolved = await resolveConfigAndOptions({ ...options, outputLocales: outputLocales })
|
|
173
172
|
if (!resolved.sourcePath) {
|
|
174
173
|
throw new Error('sourcePath must be specified')
|
|
175
174
|
}
|
|
@@ -180,7 +179,8 @@ async function run(args: string[]) {
|
|
|
180
179
|
throw new Error('outputDir must be specified')
|
|
181
180
|
}
|
|
182
181
|
|
|
183
|
-
const
|
|
182
|
+
const ext = options.yaml == true ? '.yaml' : '.json'
|
|
183
|
+
const absPath = path.resolve(resolved.sourcePath, `${resolved.sourceLocale}${ext}`)
|
|
184
184
|
const fileContent = await fs.readFile(absPath, 'utf-8')
|
|
185
185
|
|
|
186
186
|
let json = null
|
|
@@ -194,29 +194,57 @@ async function run(args: string[]) {
|
|
|
194
194
|
throw err
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
+
let locales: string[] = (resolved.outputLocales as string[]).map(l => l)
|
|
198
|
+
if (options.only != null) {
|
|
199
|
+
locales = locales.filter(l => l === options.only)
|
|
200
|
+
}
|
|
197
201
|
|
|
198
202
|
const body = {
|
|
199
|
-
locales
|
|
203
|
+
locales,
|
|
200
204
|
translations: json,
|
|
205
|
+
usage: options.usage,
|
|
201
206
|
...{ ... (resolved.projectId != null ? { projectId: resolved.projectId } : {}) },
|
|
202
207
|
}
|
|
203
208
|
|
|
204
|
-
const url = `${
|
|
209
|
+
const url = `${resolved.apiOrigin}/api/translations`
|
|
210
|
+
console.info('Getting translations for: ', locales)
|
|
205
211
|
const data = await fetchGlotstack<{ data: Translations }>(url, resolved.apiKey, body)
|
|
206
212
|
console.info('Received translations:', data)
|
|
207
213
|
Object.entries(data.data).map(([key, val]) => {
|
|
208
214
|
const p = `${resolved.outputDir}/${key}.json`
|
|
209
215
|
console.info(`Writing file ${p}`)
|
|
210
|
-
fs.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2))
|
|
216
|
+
fs.writeFile(`${resolved.outputDir}/${key}.json`, JSON.stringify(val, null, 2), 'utf-8')
|
|
211
217
|
})
|
|
218
|
+
|
|
219
|
+
if (options.yaml) {
|
|
220
|
+
const fp = `${resolved.outputDir}/${path.parse(absPath).name}.json`
|
|
221
|
+
console.info(`Writing file ${fp}`)
|
|
222
|
+
fs.writeFile(fp, JSON.stringify(json, null, 2), 'utf-8')
|
|
223
|
+
}
|
|
212
224
|
})
|
|
213
225
|
|
|
226
|
+
program
|
|
227
|
+
.command('yaml-to-json')
|
|
228
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
229
|
+
.action(async (inputOptions: Record<string, any>) => {
|
|
230
|
+
const options = await resolveConfigAndOptions(inputOptions)
|
|
231
|
+
|
|
232
|
+
const absPath = path.resolve(options.sourcePath, `${options.sourceLocale}.yaml`)
|
|
233
|
+
const fileContent = await fs.readFile(absPath, 'utf-8')
|
|
234
|
+
const fp = `${options.outputDir}/${path.parse(absPath).name}.json`
|
|
235
|
+
const json = loadYaml(fileContent)
|
|
236
|
+
console.info(`Writing file ${fp}`)
|
|
237
|
+
fs.writeFile(fp, JSON.stringify(json, null, 2), 'utf-8')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
|
|
214
241
|
program
|
|
215
242
|
.command('format-json')
|
|
216
243
|
.description('format files in --source-path [path] to nested (not flat)')
|
|
217
|
-
.option('--source-path [path]',
|
|
218
|
-
.option('--yes', 'skip confirm checks'
|
|
219
|
-
.action(async (
|
|
244
|
+
.option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
|
|
245
|
+
.option('--yes', 'skip confirm checks')
|
|
246
|
+
.action(async (inputOptions: Record<string, any>) => {
|
|
247
|
+
const options = await resolveConfigAndOptions(inputOptions)
|
|
220
248
|
|
|
221
249
|
if (!options.sourcePath) {
|
|
222
250
|
throw new Error('sourcePath must be specified')
|
|
@@ -244,7 +272,7 @@ async function run(args: string[]) {
|
|
|
244
272
|
const text = await readFile(fp, 'utf-8')
|
|
245
273
|
const json = JSON.parse(text)
|
|
246
274
|
const formatted = JSON.stringify(unflatten(json), null, 2)
|
|
247
|
-
await writeFile(fp, formatted)
|
|
275
|
+
await writeFile(fp, formatted, 'utf-8')
|
|
248
276
|
}
|
|
249
277
|
rl.close()
|
|
250
278
|
}
|
package/src/index.tsx
CHANGED
|
@@ -20,7 +20,7 @@ export interface ContextType {
|
|
|
20
20
|
locale: string | null
|
|
21
21
|
loadTranslations: (locale: LocaleRegion) => Promise<Translations>
|
|
22
22
|
setLocale: (locale: LocaleRegion) => void
|
|
23
|
-
importMethod: (locale: LocaleRegion) => Promise<Translations>
|
|
23
|
+
importMethod: (locale: LocaleRegion) => Promise<Translations>
|
|
24
24
|
t: (key: string, options?: { locale?: LocaleRegion }) => string
|
|
25
25
|
ssr: boolean
|
|
26
26
|
}
|
|
@@ -102,15 +102,15 @@ export const access = (key: string, locale: LocaleRegion, translations: Translat
|
|
|
102
102
|
return (value?.value ?? key) as string
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod, ssr}: GlotstackProviderProps) => {
|
|
105
|
+
export const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLocaleChange, onTranslationLoaded, importMethod, ssr }: GlotstackProviderProps) => {
|
|
106
106
|
if (initialLocale == null) {
|
|
107
107
|
throw new Error('initialLocale must be set')
|
|
108
108
|
}
|
|
109
109
|
const [locale, setLocale] = React.useState<LocaleRegion>(initialLocale)
|
|
110
|
-
const translationsRef = React.useRef<Record<string, Translations
|
|
110
|
+
const translationsRef = React.useRef<Record<string, Translations> | null>(initialTranslations || null)
|
|
111
111
|
const loadingRef = React.useRef<Record<string, Promise<Translations>>>({})
|
|
112
112
|
|
|
113
|
-
const loadTranslations = React.useCallback(async (locale: string, opts?: {force?: boolean}) => {
|
|
113
|
+
const loadTranslations = React.useCallback(async (locale: string, opts?: { force?: boolean }) => {
|
|
114
114
|
// TODO: if translations are loaded only reload if some condition is
|
|
115
115
|
try {
|
|
116
116
|
if (loadingRef.current?.[locale] != null && opts?.force != true) {
|
|
@@ -181,3 +181,104 @@ export const useTranslations = (_options?: Record<never, never>) => {
|
|
|
181
181
|
return context
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
|
|
185
|
+
export type ParsedSimplePlaceholder = {
|
|
186
|
+
key: string
|
|
187
|
+
options: string[]
|
|
188
|
+
raw: string
|
|
189
|
+
index: number
|
|
190
|
+
kind: 'doubleCurly' | 'component'
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const curlyRegex= /(?<!\\)({{\s*([a-zA-Z0-9_]+)\s*(?:,\s*([^{}]*?))?\s*}})/g;
|
|
194
|
+
const componentRegex = /<([A-Z][a-zA-Z0-9]*)>([\s\S]*?)<\/\1>/g;
|
|
195
|
+
|
|
196
|
+
export function extractSimplePlaceholders(input: string): ParsedSimplePlaceholder[] {
|
|
197
|
+
const results: ParsedSimplePlaceholder[] = [];
|
|
198
|
+
|
|
199
|
+
for (const match of input.matchAll(curlyRegex)) {
|
|
200
|
+
const raw = match[1];
|
|
201
|
+
const key = match[2];
|
|
202
|
+
const rawOptions = match[3];
|
|
203
|
+
const index = match.index ?? -1;
|
|
204
|
+
|
|
205
|
+
const options = rawOptions
|
|
206
|
+
? rawOptions.split(',').map(opt => opt.trim()).filter(Boolean)
|
|
207
|
+
: [];
|
|
208
|
+
|
|
209
|
+
results.push({ key, options, raw, index, kind: 'doubleCurly' });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
for (const match of input.matchAll(componentRegex)) {
|
|
213
|
+
const raw = match[0];
|
|
214
|
+
const key = match[1];
|
|
215
|
+
const index = match.index ?? -1;
|
|
216
|
+
|
|
217
|
+
results.push({ key, options: [], raw, index, kind: 'component' });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return results.sort((a, b) => a.index - b.index);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
type Renderer = (props: {children: React.ReactNode}) => React.ReactNode
|
|
224
|
+
|
|
225
|
+
export function renderPlaceholdersToNodes(
|
|
226
|
+
input: string,
|
|
227
|
+
placeholders: ParsedSimplePlaceholder[],
|
|
228
|
+
assigns: Record<string, React.ReactNode | Renderer >
|
|
229
|
+
): React.ReactNode[] {
|
|
230
|
+
const nodes: React.ReactNode[] = []
|
|
231
|
+
let cursor = 0
|
|
232
|
+
|
|
233
|
+
for (const { index, raw, key, kind } of placeholders) {
|
|
234
|
+
if (cursor < index) {
|
|
235
|
+
nodes.push(input.slice(cursor, index))
|
|
236
|
+
}
|
|
237
|
+
let value: React.ReactNode = raw;
|
|
238
|
+
|
|
239
|
+
if (kind === 'component') {
|
|
240
|
+
const Render = assigns[key];
|
|
241
|
+
const inner = raw.replace(new RegExp(`^<${key}>`), '').replace(new RegExp(`</${key}>$`), '');
|
|
242
|
+
|
|
243
|
+
if (React.isValidElement(Render)) {
|
|
244
|
+
value = React.cloneElement(Render, {}, inner);
|
|
245
|
+
} else if (typeof Render === 'function') {
|
|
246
|
+
value = <Render>{inner}</Render>;
|
|
247
|
+
} else {
|
|
248
|
+
logger.warn(`Invalid assign substitution for:\n\n ${raw}\n\nDid you remember to pass assigns?\n`,
|
|
249
|
+
`
|
|
250
|
+
t('key', { assigns: {
|
|
251
|
+
${key}: <something /> // children will be copied via React.cloneElement
|
|
252
|
+
}})\nor\n
|
|
253
|
+
t('key', { assigns: {
|
|
254
|
+
${key}: MyComponent // component will be rendered with <Component/>
|
|
255
|
+
}})\n
|
|
256
|
+
`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
} else if (kind === 'doubleCurly') {
|
|
260
|
+
const Render = assigns[key];
|
|
261
|
+
value = typeof Render !== 'function' ? Render : raw ?? raw;
|
|
262
|
+
}
|
|
263
|
+
nodes.push(value)
|
|
264
|
+
cursor = index + raw.length
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (cursor < input.length) {
|
|
268
|
+
nodes.push(input.slice(cursor))
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Unescape \{{...}} to {{...}}, and wrap ReactNodes
|
|
272
|
+
return nodes.map((node, i) =>
|
|
273
|
+
typeof node === 'string'
|
|
274
|
+
? node.replace(/\\({{[^{}]+}})/g, '$1')
|
|
275
|
+
: <React.Fragment key={i}>{node}</React.Fragment>
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
export function useRenderPlaceholdersToNodes(...args: Parameters<typeof renderPlaceholdersToNodes>) {
|
|
282
|
+
const nodes = React.useMemo(() => renderPlaceholdersToNodes(...args), [...args])
|
|
283
|
+
return nodes;
|
|
284
|
+
}
|
package/src/util/findConfig.ts
CHANGED
|
@@ -1,26 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { existsSync } from 'fs'
|
|
2
|
+
import { readFile } from 'fs/promises'
|
|
3
|
+
import * as path from 'path'
|
|
4
|
+
import { loadYaml } from './yaml'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Recursively looks for `.glotstack.json` from the current directory up to the root.
|
|
6
8
|
* @param startDir The directory to start the search from. Defaults to process.cwd().
|
|
7
9
|
* @returns The absolute path to the file if found, or null if not found.
|
|
8
10
|
*/
|
|
9
|
-
export function findGlotstackConfig(startDir: string = process.cwd()):
|
|
10
|
-
let currentDir = path.resolve(startDir)
|
|
11
|
+
export async function findGlotstackConfig(startDir: string = process.cwd()): Promise<object | null> {
|
|
12
|
+
let currentDir = path.resolve(startDir)
|
|
13
|
+
let configPath = null
|
|
11
14
|
|
|
12
15
|
while (true) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
const jsonCandidate = path.join(currentDir, '.glotstack.json')
|
|
17
|
+
const yamlCandidate = path.join(currentDir, '.glotstack.yaml')
|
|
18
|
+
const jsonExists = existsSync(jsonCandidate)
|
|
19
|
+
const yamlExists = existsSync(yamlCandidate)
|
|
20
|
+
if (jsonExists && yamlExists) {
|
|
21
|
+
console.error('Both .glotstack.json and .glotstack.yaml exist, please delete one\n\n json: ', jsonCandidate, '\n yaml: ', yamlCandidate)
|
|
22
|
+
throw new Error('Two config formats cannot be used at the same time')
|
|
23
|
+
|
|
24
|
+
} else if (jsonExists) {
|
|
25
|
+
configPath = jsonCandidate
|
|
26
|
+
} else if (yamlExists) {
|
|
27
|
+
configPath = yamlCandidate
|
|
16
28
|
}
|
|
17
29
|
|
|
18
|
-
const parentDir = path.dirname(currentDir)
|
|
30
|
+
const parentDir = path.dirname(currentDir)
|
|
19
31
|
if (parentDir === currentDir) {
|
|
20
|
-
break
|
|
32
|
+
break // Reached root
|
|
21
33
|
}
|
|
22
|
-
currentDir = parentDir
|
|
34
|
+
currentDir = parentDir
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
let config = {}
|
|
38
|
+
|
|
39
|
+
if (configPath != null) {
|
|
40
|
+
console.info('Loading config file at ', configPath)
|
|
41
|
+
try {
|
|
42
|
+
const text = await readFile(configPath, 'utf-8')
|
|
43
|
+
if (path.parse(configPath).ext === '.yaml') {
|
|
44
|
+
config = loadYaml(text) as object
|
|
45
|
+
} else {
|
|
46
|
+
config = JSON.parse(text)
|
|
47
|
+
}
|
|
48
|
+
console.info('Loaded config file', config)
|
|
49
|
+
return config
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.warn('Could not load config', configPath)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
console.warn('Could not find any .glotstack config files')
|
|
55
|
+
return null
|
|
26
56
|
}
|