glotstack 0.0.8 → 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 CHANGED
@@ -97,23 +97,24 @@ function unflatten(flat) {
97
97
  const DEFAULT_OPTIONS = {
98
98
  sourcePath: '.',
99
99
  sourceLocale: 'en-US',
100
- apiOrigin: 'https://glotstack.ai'
100
+ apiOrigin: 'https://glotstack.ai',
101
+ yaml: 'false',
101
102
  };
102
103
  function resolveConfigAndOptions(options) {
103
104
  return __awaiter(this, void 0, void 0, function* () {
104
105
  var _a;
105
106
  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
107
  const resolved = (0, object_1.merge)({}, DEFAULT_OPTIONS, config, options);
113
108
  // special case to match source
114
109
  if (resolved.outputDir == null) {
115
110
  resolved.outputDir = resolved.sourcePath;
116
111
  }
112
+ if ('outputLocales' in options) {
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
+ }
117
+ }
117
118
  return resolved;
118
119
  });
119
120
  }
@@ -124,17 +125,19 @@ function run(args) {
124
125
  .description('extract translations from all compatible source files.')
125
126
  .option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
126
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')
127
129
  .option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
128
130
  .option('--output-dir [path]', 'path to output directory (default=<source-path>')
129
131
  .option('--api-key [key]', 'api key for glotstack.ai')
130
132
  .option('--yes', 'skip confirm checks')
131
- .action((inputOptions) => __awaiter(this, void 0, void 0, function* () {
133
+ .argument('[directories...]', 'Directories to scan', './**/*')
134
+ .action((directories, inputOptions) => __awaiter(this, void 0, void 0, function* () {
132
135
  const options = yield resolveConfigAndOptions(inputOptions);
133
136
  if (!options.apiOrigin) {
134
137
  throw new Error('apiOrigin must be specified');
135
138
  }
136
139
  const linter = new eslint_1.default.ESLint({ overrideConfigFile: path_1.default.join(__dirname, '..', 'eslint-raw-string.mjs') });
137
- const results = yield linter.lintFiles(["./**/*"]);
140
+ const results = yield linter.lintFiles(directories);
138
141
  const filesWithIssues = results
139
142
  .filter((r) => r.errorCount + r.warningCount > 0)
140
143
  .map((r) => r.filePath);
@@ -158,7 +161,10 @@ function run(args) {
158
161
  const send = yield askToSend();
159
162
  if (send) {
160
163
  console.info('Sending files to generate new source and extracted strings');
161
- const url = `${options.apiOrigin}/uploads/translations/extract`;
164
+ let url = `${options.apiOrigin}/uploads/translations/extract`;
165
+ if (options.yaml) {
166
+ url = `${url}?yaml=true`;
167
+ }
162
168
  const form = new undici_2.FormData();
163
169
  for (let i = 0; i < filesWithIssues.length; i++) {
164
170
  const filePath = filesWithIssues[i];
@@ -178,10 +184,12 @@ function run(args) {
178
184
  .description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
179
185
  .option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
180
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')
181
188
  .option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
182
189
  .option('--output-dir [path]', 'path to output directory (default=<source-path>')
183
190
  .option('--api-key [key]', 'api key for glotstack.ai')
184
191
  .option('--project-id [id]', '(optional) specific project to use')
192
+ .option('--only [locale]', '(optional) only translate for this locale')
185
193
  .argument('[output-locales...]', 'locales to get translations for')
186
194
  .action((outputLocales, options, command) => __awaiter(this, void 0, void 0, function* () {
187
195
  const resolved = yield resolveConfigAndOptions(Object.assign(Object.assign({}, options), { outputLocales: outputLocales }));
@@ -194,7 +202,8 @@ function run(args) {
194
202
  if (!resolved.outputDir) {
195
203
  throw new Error('outputDir must be specified');
196
204
  }
197
- const absPath = path_1.default.resolve(resolved.sourcePath, `${resolved.sourceLocale}.json`);
205
+ const ext = options.yaml == true ? '.yaml' : '.json';
206
+ const absPath = path_1.default.resolve(resolved.sourcePath, `${resolved.sourceLocale}${ext}`);
198
207
  const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
199
208
  let json = null;
200
209
  try {
@@ -209,15 +218,37 @@ function run(args) {
209
218
  throw err;
210
219
  }
211
220
  }
212
- const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (resolved.projectId != null ? { projectId: resolved.projectId } : {})));
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 } : {})));
213
226
  const url = `${resolved.apiOrigin}/api/translations`;
227
+ console.info('Getting translations for: ', locales);
214
228
  const data = yield fetchGlotstack(url, resolved.apiKey, body);
215
229
  console.info('Received translations:', data);
216
230
  Object.entries(data.data).map(([key, val]) => {
217
231
  const p = `${resolved.outputDir}/${key}.json`;
218
232
  console.info(`Writing file ${p}`);
219
- 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');
220
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');
221
252
  }));
222
253
  commander_1.program
223
254
  .command('format-json')
@@ -254,7 +285,7 @@ function run(args) {
254
285
  const text = yield (0, promises_1.readFile)(fp, 'utf-8');
255
286
  const json = JSON.parse(text);
256
287
  const formatted = JSON.stringify(unflatten(json), null, 2);
257
- yield (0, promises_1.writeFile)(fp, formatted);
288
+ yield (0, promises_1.writeFile)(fp, formatted, 'utf-8');
258
289
  }
259
290
  rl.close();
260
291
  }
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,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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AAI,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,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,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AC;YAClC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,KAAK,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAE,MAAM,CAAC,CAAC,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,GAAG,CAAC;QAC9D,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACjB,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,CAAA;IAC7B,CAAC;IAED,IAAI,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,CAAC;IAED,oDAAoD;IACpD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAC3B,OAAO,IAAI,KAAK,QAAQ;QACtB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC;QACvC,CAAC,CAAC,uBAAC,KAAK,CAAC,QAAQ,cAAU,IAAI,IAAR,CAAC,CAAyB,CACpD,CAAA;AACH,CAAC;AApDD,8DAoDC;AAID,SAAgB,4BAA4B,CAAC,GAAG,IAAkD;IAChG,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAChF,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,oEAGC"}
@@ -36,6 +36,7 @@ exports.findGlotstackConfig = void 0;
36
36
  const fs_1 = require("fs");
37
37
  const promises_1 = require("fs/promises");
38
38
  const path = __importStar(require("path"));
39
+ const yaml_1 = require("./yaml");
39
40
  /**
40
41
  * Recursively looks for `.glotstack.json` from the current directory up to the root.
41
42
  * @param startDir The directory to start the search from. Defaults to process.cwd().
@@ -46,9 +47,19 @@ function findGlotstackConfig() {
46
47
  let currentDir = path.resolve(startDir);
47
48
  let configPath = null;
48
49
  while (true) {
49
- const candidate = path.join(currentDir, '.glotstack.json');
50
- if ((0, fs_1.existsSync)(candidate)) {
51
- configPath = candidate;
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;
52
63
  }
53
64
  const parentDir = path.dirname(currentDir);
54
65
  if (parentDir === currentDir) {
@@ -61,7 +72,12 @@ function findGlotstackConfig() {
61
72
  console.info('Loading config file at ', configPath);
62
73
  try {
63
74
  const text = yield (0, promises_1.readFile)(configPath, 'utf-8');
64
- config = JSON.parse(text);
75
+ if (path.parse(configPath).ext === '.yaml') {
76
+ config = (0, yaml_1.loadYaml)(text);
77
+ }
78
+ else {
79
+ config = JSON.parse(text);
80
+ }
65
81
  console.info('Loaded config file', config);
66
82
  return config;
67
83
  }
@@ -69,7 +85,7 @@ function findGlotstackConfig() {
69
85
  console.warn('Could not load config', configPath);
70
86
  }
71
87
  }
72
- console.warn('Could not find any .glotstack.json config files');
88
+ console.warn('Could not find any .glotstack config files');
73
89
  return null;
74
90
  });
75
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"findConfig.js","sourceRoot":"","sources":["../../src/util/findConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA+B;AAC/B,0CAAsC;AACtC,2CAA4B;AAE5B;;;;GAIG;AACH,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YACvB,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,UAAU,CAAC,CAAA;YACnD,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,UAAU,EAAE,OAAO,CAAC,CAAA;gBAChD,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;oBAC3C,MAAM,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAW,CAAA;gBACnC,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAC3B,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAA;gBAC1C,OAAO,MAAM,CAAA;YACf,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAA;YACnD,CAAC;QACH,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAA;QAC1D,OAAO,IAAI,CAAA;IACb,CAAC;CAAA;AA7CD,kDA6CC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glotstack",
3
- "version": "0.0.8",
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 'npm run build'\"",
39
- "prepublishOnly": "yarn run build",
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
@@ -67,20 +67,13 @@ function unflatten(flat: Record<string, any>): Record<string, any> {
67
67
  const DEFAULT_OPTIONS: Record<string, string> = {
68
68
  sourcePath: '.',
69
69
  sourceLocale: 'en-US',
70
- apiOrigin: 'https://glotstack.ai'
70
+ apiOrigin: 'https://glotstack.ai',
71
+ yaml: 'false',
71
72
  }
72
73
 
73
74
  async function resolveConfigAndOptions(options: Record<string, any>) {
74
75
 
75
76
  const config = await findGlotstackConfig(cwd()) ?? {}
76
-
77
- if ('outputLocales' in options) {
78
- if ((options.outputLocales as string[]).includes('en-US')) {
79
- console.warn('en-US detected in outputLocales, removing')
80
- options.outputLocales = options.outputLocales.filter((x: string) => x !== 'en-US')
81
- }
82
- }
83
-
84
77
  const resolved = merge({}, DEFAULT_OPTIONS, config, options)
85
78
 
86
79
  // special case to match source
@@ -88,6 +81,12 @@ async function resolveConfigAndOptions(options: Record<string, any>) {
88
81
  resolved.outputDir = resolved.sourcePath
89
82
  }
90
83
 
84
+ if ('outputLocales' in options) {
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)
88
+ }
89
+ }
91
90
  return resolved
92
91
  }
93
92
 
@@ -98,18 +97,20 @@ async function run(args: string[]) {
98
97
  .description('extract translations from all compatible source files.')
99
98
  .option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
100
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
101
  .option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
102
102
  .option('--output-dir [path]', 'path to output directory (default=<source-path>')
103
103
  .option('--api-key [key]', 'api key for glotstack.ai')
104
104
  .option('--yes', 'skip confirm checks')
105
- .action(async (inputOptions: Record<string, any>) => {
105
+ .argument('[directories...]', 'Directories to scan', './**/*')
106
+ .action(async (directories: string[], inputOptions: Record<string, any>) => {
106
107
  const options = await resolveConfigAndOptions(inputOptions)
107
108
  if (!options.apiOrigin) {
108
109
  throw new Error('apiOrigin must be specified')
109
110
  }
110
111
 
111
112
  const linter = new eslint.ESLint({ overrideConfigFile: path.join(__dirname, '..', 'eslint-raw-string.mjs') })
112
- const results = await linter.lintFiles(["./**/*"])
113
+ const results = await linter.lintFiles(directories)
113
114
  const filesWithIssues = results
114
115
  .filter((r) => r.errorCount + r.warningCount > 0)
115
116
  .map((r) => r.filePath)
@@ -133,7 +134,12 @@ async function run(args: string[]) {
133
134
  const send = await askToSend()
134
135
  if (send) {
135
136
  console.info('Sending files to generate new source and extracted strings')
136
- const url = `${options.apiOrigin}/uploads/translations/extract`
137
+ let url = `${options.apiOrigin}/uploads/translations/extract`
138
+
139
+ if (options.yaml) {
140
+ url = `${url}?yaml=true`
141
+ }
142
+
137
143
  const form = new FormData()
138
144
 
139
145
  for (let i = 0; i < filesWithIssues.length; i++) {
@@ -154,10 +160,12 @@ async function run(args: string[]) {
154
160
  .description('fetch translations for all [output-locals...]. Use .glotstack.json for repeatable results.')
155
161
  .option('--source-path [path]', `path directory containing [locale].json files (default=${DEFAULT_OPTIONS['sourcePath']})`)
156
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')
157
164
  .option('--api-origin [url]', `glotstack api origin (default=${DEFAULT_OPTIONS['apiOrigin']})`)
158
165
  .option('--output-dir [path]', 'path to output directory (default=<source-path>')
159
166
  .option('--api-key [key]', 'api key for glotstack.ai')
160
167
  .option('--project-id [id]', '(optional) specific project to use')
168
+ .option('--only [locale]', '(optional) only translate for this locale')
161
169
  .argument('[output-locales...]', 'locales to get translations for')
162
170
  .action(async (outputLocales: string[], options: Record<string, any>, command: Command) => {
163
171
  const resolved = await resolveConfigAndOptions({ ...options, outputLocales: outputLocales })
@@ -171,7 +179,8 @@ async function run(args: string[]) {
171
179
  throw new Error('outputDir must be specified')
172
180
  }
173
181
 
174
- const absPath = path.resolve(resolved.sourcePath, `${resolved.sourceLocale}.json`)
182
+ const ext = options.yaml == true ? '.yaml' : '.json'
183
+ const absPath = path.resolve(resolved.sourcePath, `${resolved.sourceLocale}${ext}`)
175
184
  const fileContent = await fs.readFile(absPath, 'utf-8')
176
185
 
177
186
  let json = null
@@ -185,23 +194,50 @@ async function run(args: string[]) {
185
194
  throw err
186
195
  }
187
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
+ }
188
201
 
189
202
  const body = {
190
- locales: resolved.outputLocales,
203
+ locales,
191
204
  translations: json,
205
+ usage: options.usage,
192
206
  ...{ ... (resolved.projectId != null ? { projectId: resolved.projectId } : {}) },
193
207
  }
194
208
 
195
209
  const url = `${resolved.apiOrigin}/api/translations`
210
+ console.info('Getting translations for: ', locales)
196
211
  const data = await fetchGlotstack<{ data: Translations }>(url, resolved.apiKey, body)
197
212
  console.info('Received translations:', data)
198
213
  Object.entries(data.data).map(([key, val]) => {
199
214
  const p = `${resolved.outputDir}/${key}.json`
200
215
  console.info(`Writing file ${p}`)
201
- 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')
202
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
+ }
224
+ })
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')
203
238
  })
204
239
 
240
+
205
241
  program
206
242
  .command('format-json')
207
243
  .description('format files in --source-path [path] to nested (not flat)')
@@ -236,7 +272,7 @@ async function run(args: string[]) {
236
272
  const text = await readFile(fp, 'utf-8')
237
273
  const json = JSON.parse(text)
238
274
  const formatted = JSON.stringify(unflatten(json), null, 2)
239
- await writeFile(fp, formatted)
275
+ await writeFile(fp, formatted, 'utf-8')
240
276
  }
241
277
  rl.close()
242
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>|null>(initialTranslations || null)
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
+ }
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from 'fs'
2
2
  import { readFile } from 'fs/promises'
3
3
  import * as path from 'path'
4
+ import { loadYaml } from './yaml'
4
5
 
5
6
  /**
6
7
  * Recursively looks for `.glotstack.json` from the current directory up to the root.
@@ -12,9 +13,18 @@ export async function findGlotstackConfig(startDir: string = process.cwd()): Pro
12
13
  let configPath = null
13
14
 
14
15
  while (true) {
15
- const candidate = path.join(currentDir, '.glotstack.json')
16
- if (existsSync(candidate)) {
17
- configPath = candidate
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
18
28
  }
19
29
 
20
30
  const parentDir = path.dirname(currentDir)
@@ -30,13 +40,17 @@ export async function findGlotstackConfig(startDir: string = process.cwd()): Pro
30
40
  console.info('Loading config file at ', configPath)
31
41
  try {
32
42
  const text = await readFile(configPath, 'utf-8')
33
- config = JSON.parse(text)
43
+ if (path.parse(configPath).ext === '.yaml') {
44
+ config = loadYaml(text) as object
45
+ } else {
46
+ config = JSON.parse(text)
47
+ }
34
48
  console.info('Loaded config file', config)
35
49
  return config
36
50
  } catch (err) {
37
51
  console.warn('Could not load config', configPath)
38
52
  }
39
53
  }
40
- console.warn('Could not find any .glotstack.json config files')
54
+ console.warn('Could not find any .glotstack config files')
41
55
  return null
42
56
  }