glotstack 0.0.4 → 0.0.6
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 +94 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/eslint-raw-string.mjs +11 -0
- package/package-lock.json +4356 -0
- package/package.json +8 -6
- package/src/cli.tsx +82 -34
- package/src/index.tsx +10 -8
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
3
26
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
27
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
28
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -20,12 +43,75 @@ const findConfig_1 = require("./util/findConfig");
|
|
|
20
43
|
const process_1 = require("process");
|
|
21
44
|
const object_1 = require("./util/object");
|
|
22
45
|
const yaml_1 = require("./util/yaml");
|
|
46
|
+
const eslint_1 = __importDefault(require("eslint"));
|
|
47
|
+
const readline = __importStar(require("node:readline/promises"));
|
|
48
|
+
const node_process_1 = require("node:process");
|
|
49
|
+
const fetchGlotstack = (apiOrigin, apiKey, body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const url = `${apiOrigin}/api/translations`;
|
|
51
|
+
console.info(`Fetching translations from: ${url}`);
|
|
52
|
+
const headers = {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
const res = yield fetch(url, { method: 'POST', body: JSON.stringify(body), headers });
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
60
|
+
return res.json();
|
|
61
|
+
// fs.writeFile(`${outputDir}/source.json`, JSON.stringify(json, null, 2))
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error('Fetch failed:', err);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
23
68
|
function run(args) {
|
|
24
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
commander_1.program
|
|
72
|
+
.command('extract-translations')
|
|
73
|
+
.option('--source-path [path]', 'to source files root directory', '.')
|
|
74
|
+
.option('--api-origin [url]', 'glotstack api origin', (_a = process.env.GLOTSTACK_HOST) !== null && _a !== void 0 ? _a : 'https://glotstack.ai')
|
|
75
|
+
.option('--yes', 'skip confirm checks', false)
|
|
76
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
if (!options.apiOrigin) {
|
|
78
|
+
throw new Error('apiOrigin must be specified');
|
|
79
|
+
}
|
|
80
|
+
const linter = new eslint_1.default.ESLint({ overrideConfigFile: path_1.default.join(__dirname, '..', 'eslint-raw-string.mjs') });
|
|
81
|
+
const results = yield linter.lintFiles(["./**/*"]);
|
|
82
|
+
const filesWithIssues = results
|
|
83
|
+
.filter((r) => r.errorCount + r.warningCount > 0)
|
|
84
|
+
.map((r) => r.filePath);
|
|
85
|
+
const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
86
|
+
const askToSend = () => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if (options.yes) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
const response = yield rl.question(`Your source are going to be sent to our LLM -- they should not contain any secrets. Proceed? (yes/no):`);
|
|
91
|
+
if (response === 'yes') {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
else if (response !== 'no') {
|
|
95
|
+
console.error('Please respond with yes or no.');
|
|
96
|
+
return askToSend();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const send = yield askToSend();
|
|
103
|
+
if (send) {
|
|
104
|
+
console.info('Sending files to LLM');
|
|
105
|
+
rl.close();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
rl.close();
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
25
111
|
commander_1.program
|
|
26
112
|
.command('get-translations')
|
|
27
113
|
.option('--source-path [path]', 'path to en-US.json (or your canonical source json)')
|
|
28
|
-
.option('--api-origin [url]', 'glotstack api origin', '
|
|
114
|
+
.option('--api-origin [url]', 'glotstack api origin', (_b = process.env.GLOTSTACK_HOST) !== null && _b !== void 0 ? _b : 'https://glotstack.ai')
|
|
29
115
|
.option('--output-dir [path]', 'path to output directory')
|
|
30
116
|
.option('--api-key [key]', 'api key for glotstack.ai')
|
|
31
117
|
.option('--project-id [id]', '(optional) specific project to use')
|
|
@@ -59,8 +145,6 @@ function run(args) {
|
|
|
59
145
|
if (!outputDir) {
|
|
60
146
|
throw new Error('outputDir must be specified');
|
|
61
147
|
}
|
|
62
|
-
const url = `${apiOrigin}/api/translations`;
|
|
63
|
-
console.info(`Fetching translations from: ${url}`);
|
|
64
148
|
const absPath = path_1.default.resolve(sourcePath);
|
|
65
149
|
const fileContent = yield fs_1.promises.readFile(absPath, 'utf-8');
|
|
66
150
|
let json = null;
|
|
@@ -77,27 +161,13 @@ function run(args) {
|
|
|
77
161
|
}
|
|
78
162
|
}
|
|
79
163
|
const body = Object.assign({ locales: resolved.outputLocales, translations: json }, Object.assign({}, (projectId != null ? { projectId } : {})));
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
88
|
-
const data = yield res.json();
|
|
89
|
-
console.info('Received translations:', data);
|
|
90
|
-
Object.entries(data.data).map(([key, val]) => {
|
|
91
|
-
const p = `${outputDir}/${key}.json`;
|
|
92
|
-
console.info(`Writing file ${p}`);
|
|
93
|
-
fs_1.promises.writeFile(`${outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
94
|
-
});
|
|
95
|
-
// fs.writeFile(`${outputDir}/source.json`, JSON.stringify(json, null, 2))
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
console.error('Fetch failed:', err);
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
164
|
+
const data = yield fetchGlotstack(apiOrigin, resolved.apiKey, body);
|
|
165
|
+
console.info('Received translations:', data);
|
|
166
|
+
Object.entries(data.data).map(([key, val]) => {
|
|
167
|
+
const p = `${outputDir}/${key}.json`;
|
|
168
|
+
console.info(`Writing file ${p}`);
|
|
169
|
+
fs_1.promises.writeFile(`${outputDir}/${key}.json`, JSON.stringify(val, null, 2));
|
|
170
|
+
});
|
|
101
171
|
}));
|
|
102
172
|
yield commander_1.program.parseAsync(args);
|
|
103
173
|
});
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,gDAAuB;AACvB,2BAAyC;AACzC,kDAAuD;AACvD,qCAA6B;AAC7B,0CAAqC;AACrC,sCAAsC;AACtC,oDAA2B;AAC3B,iEAAkD;AAClD,+CAA+D;AAG/D,MAAM,cAAc,GAAG,CAAO,SAAiB,EAAE,MAAc,EAAE,IAAY,EAAE,EAAE;IAC/E,MAAM,GAAG,GAAG,GAAG,SAAS,mBAAmB,CAAA;IAC3C,OAAO,CAAC,IAAI,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAA;IAElD,MAAM,OAAO,GAAG;QACd,cAAc,EAAE,kBAAkB;QAClC,eAAe,EAAE,UAAU,MAAM,EAAE;KACpC,CAAA;IAED,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QACrF,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,UAAU,EAAE,CAAC,CAAA;QACrE,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;QACjB,0EAA0E;IAC5E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,eAAe,EAA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;YACxE,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA,CAAC,CAAA;QAEJ,MAAM,mBAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CAAA;AAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -61,10 +61,11 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
61
61
|
throw new Error('initialLocale must be set');
|
|
62
62
|
}
|
|
63
63
|
const [locale, setLocale] = React.useState(initialLocale);
|
|
64
|
-
const
|
|
64
|
+
const translationsRef = React.useRef(initialTranslations);
|
|
65
65
|
const loadingRef = React.useRef({});
|
|
66
66
|
const loadTranslations = React.useCallback((locale) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
67
|
var _a, _b;
|
|
68
|
+
// TODO: if translations are loaded only reload if some condition is
|
|
68
69
|
try {
|
|
69
70
|
if (((_a = loadingRef.current) === null || _a === void 0 ? void 0 : _a[locale]) != null) {
|
|
70
71
|
return (yield ((_b = loadingRef.current) === null || _b === void 0 ? void 0 : _b[locale]));
|
|
@@ -74,7 +75,9 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
74
75
|
if (result == null) {
|
|
75
76
|
throw new Error(`Failed to load translation ${locale} ${JSON.stringify(result)}`);
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
if (translationsRef.current) {
|
|
79
|
+
translationsRef.current[locale] = result;
|
|
80
|
+
}
|
|
78
81
|
onTranslationLoaded === null || onTranslationLoaded === void 0 ? void 0 : onTranslationLoaded(locale, result);
|
|
79
82
|
return result;
|
|
80
83
|
}
|
|
@@ -82,7 +85,7 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
82
85
|
console.error('Unable to import translations', err);
|
|
83
86
|
throw err;
|
|
84
87
|
}
|
|
85
|
-
}), [importMethod,
|
|
88
|
+
}), [importMethod, onTranslationLoaded]);
|
|
86
89
|
React.useEffect(() => {
|
|
87
90
|
const run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
91
|
onLocaleChange === null || onLocaleChange === void 0 ? void 0 : onLocaleChange(locale);
|
|
@@ -93,23 +96,25 @@ const GlotstackProvider = ({ children, initialLocale, initialTranslations, onLoc
|
|
|
93
96
|
});
|
|
94
97
|
}, [locale]);
|
|
95
98
|
const context = React.useMemo(() => {
|
|
99
|
+
var _a;
|
|
96
100
|
return {
|
|
97
101
|
setLocale,
|
|
98
|
-
translations:
|
|
102
|
+
translations: (_a = translationsRef.current) !== null && _a !== void 0 ? _a : {},
|
|
99
103
|
locale,
|
|
100
104
|
importMethod,
|
|
101
105
|
loadTranslations,
|
|
102
106
|
t: (key, opts) => {
|
|
107
|
+
var _a, _b;
|
|
103
108
|
React.useEffect(() => {
|
|
104
109
|
if ((opts === null || opts === void 0 ? void 0 : opts.locale) == null) {
|
|
105
110
|
return;
|
|
106
111
|
}
|
|
107
112
|
loadTranslations(opts === null || opts === void 0 ? void 0 : opts.locale);
|
|
108
|
-
}, [locale]);
|
|
109
|
-
return (0, exports.access)(key, locale,
|
|
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 : {});
|
|
110
115
|
}
|
|
111
116
|
};
|
|
112
|
-
}, [locale, importMethod
|
|
117
|
+
}, [locale, importMethod]);
|
|
113
118
|
return React.createElement(exports.GlotstackContext.Provider, { value: context }, children);
|
|
114
119
|
};
|
|
115
120
|
exports.GlotstackProvider = GlotstackProvider;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAgCjB,Q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IAAI,CAAE,MAAM,KAAI,IAAI,EAAE,CAAC;wBACzB,OAAM;oBACR,CAAC;oBACD,gBAAgB,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC,CAAA;gBAChC,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC,CAAC,CAAA;gBAC1B,OAAO,IAAA,cAAM,EAAC,GAAG,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,MAAM,EAAE,MAAA,eAAe,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAA;YAC3E,CAAC;SAEF,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;IAE1B,OAAO,oBAAC,wBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,IAC7C,QAAQ,CACiB,CAAA;AAC9B,CAAC,CAAA;AAhEY,QAAA,iBAAiB,qBAgE7B;AAEM,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,wBAAgB,CAAC,CAAA;AAC3C,CAAC,CAAA;AAFY,QAAA,YAAY,gBAExB;AAGM,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
3
|
+
import { defineConfig } from "eslint/config";
|
|
4
|
+
import i18next from 'eslint-plugin-i18next';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default defineConfig([
|
|
8
|
+
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"], languageOptions: { globals: globals.browser } },
|
|
9
|
+
tseslint.configs.base,
|
|
10
|
+
i18next.configs['flat/recommended'],
|
|
11
|
+
]);
|