autoglot 0.6.0 → 0.6.1
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/README.md +7 -5
- package/bin/translate.mjs +49 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,8 +36,8 @@ With Node.js 20 or newer, create an empty directory and preview German translati
|
|
|
36
36
|
```bash
|
|
37
37
|
mkdir autoglot-demo
|
|
38
38
|
cd autoglot-demo
|
|
39
|
-
npx --yes autoglot@0.6.
|
|
40
|
-
npx --yes autoglot@0.6.
|
|
39
|
+
npx --yes autoglot@0.6.1 init --locales=de
|
|
40
|
+
npx --yes autoglot@0.6.1 --dry-run
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
`init` creates the English and German JSON catalogs and `translate.config.json`. It also generates a GitHub workflow file that you can ignore for local use. The dry run exits with status `0` and includes these lines for the fresh starter catalog.
|
|
@@ -50,7 +50,7 @@ npx --yes autoglot@0.6.0 --dry-run
|
|
|
50
50
|
To check whether translations are up to date, run this separately.
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
npx --yes autoglot@0.6.
|
|
53
|
+
npx --yes autoglot@0.6.1 --check
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
On this fresh catalog, the check prints `Locales needing updates: de` and exits with status `1` because the German translations are pending. Both commands leave the catalogs and lock file untouched.
|
|
@@ -60,7 +60,7 @@ On this fresh catalog, the check prints `Locales needing updates: de` and exits
|
|
|
60
60
|
When you're ready to translate, edit `messages/en.json`, set `ANTHROPIC_API_KEY` in your environment, and run the CLI without a preview flag. This sends requests to Anthropic and can incur API charges.
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
npx --yes autoglot@0.6.
|
|
63
|
+
npx --yes autoglot@0.6.1
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
To translate with a different provider, see [Providers](#providers).
|
|
@@ -69,7 +69,7 @@ For a dry run with existing catalogs, see the [basic example](https://github.com
|
|
|
69
69
|
|
|
70
70
|
### Set up an existing app
|
|
71
71
|
|
|
72
|
-
Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.6.
|
|
72
|
+
Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.6.1 init --locales=de,pt-BR`. Setup creates missing files and skips existing paths. Add `--install` to install the suggested runtime libraries. If that install fails, unattended setup exits with an error after printing the retry command.
|
|
73
73
|
|
|
74
74
|
For GitHub automation, add `ANTHROPIC_API_KEY` to your repository secrets before pushing changes to the source catalog. To scaffold for another provider, pass `--provider=<name>`; setup then writes that provider to the config, uses its secret name in the workflow, and prints which secret to add. For a provider that runs on your machine, such as `ollama`, setup skips the GitHub workflow, because a GitHub runner cannot reach it.
|
|
75
75
|
|
|
@@ -498,6 +498,8 @@ npx autoglot --dry-run
|
|
|
498
498
|
|
|
499
499
|
`languine.lock` sits next to `languine.json`. The importer reads the entry for your source JSON catalog and ignores entries for other files.
|
|
500
500
|
|
|
501
|
+
To preview the import first, add `--dry-run`: `npx autoglot --import-languine=languine.lock --dry-run` prints the same report (how many hashes it would import, what it would leave out and the lock file it would write) and writes nothing. The import only creates a lock file. If `translate.lock` already exists and is not empty, the import and its preview stop with an error and leave it untouched, because replacing it would drop the history it records and the next run would translate those keys again. Move or delete it, then run the import again. `--import-languine` cannot be combined with `--check` or `--locales`.
|
|
502
|
+
|
|
501
503
|
Keep your existing locale files and review the dry-run output before replacing the Languine workflow: it prints how many keys each locale would get. To see key names, run `npx autoglot --check`, which lists the new or changed source keys and the locales that need updates, and exits with status `1` while anything is pending. The import prints the entries it did not carry over. Any key it could not match to your source catalog appears as new and is re-translated, and array values are re-translated on the first run because Languine hashes each array item while autoglot hashes the whole array as one value.
|
|
502
504
|
|
|
503
505
|
## How it works
|
package/bin/translate.mjs
CHANGED
|
@@ -174,10 +174,20 @@ const SUMMARY_FILE = args["summary-path"]
|
|
|
174
174
|
const STEP_SUMMARY = process.env.GITHUB_STEP_SUMMARY;
|
|
175
175
|
// The importer needs no provider, so a provider setting can never block it.
|
|
176
176
|
if ("import-languine" in args) {
|
|
177
|
+
// The import writes hashes shared by every locale and checks nothing, so a
|
|
178
|
+
// flag that narrows or checks a translation run cannot apply to it.
|
|
179
|
+
if (args.check) {
|
|
180
|
+
console.error("[translate] --import-languine cannot be combined with --check. Preview the import with --import-languine --dry-run, or run --check on its own.");
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
if (args.locales !== undefined) {
|
|
184
|
+
console.error("[translate] --import-languine cannot be combined with --locales: the imported hashes apply to every locale. Run the import without --locales.");
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
177
187
|
const src = typeof args["import-languine"] === "string"
|
|
178
188
|
? resolvePath(args["import-languine"])
|
|
179
189
|
: resolvePath("languine.lock");
|
|
180
|
-
importLanguineLock(src);
|
|
190
|
+
importLanguineLock(src, { dryRun: Boolean(args["dry-run"]) });
|
|
181
191
|
process.exit(0);
|
|
182
192
|
}
|
|
183
193
|
|
|
@@ -852,7 +862,7 @@ function saveLock(lock, sourceForLocale, sourceHashes, removed, completed, unpro
|
|
|
852
862
|
// loadConfig moved to ./config.mjs (shared with add/doctor; resolves
|
|
853
863
|
// config-relative paths so monorepo invocations work from any subdir).
|
|
854
864
|
|
|
855
|
-
function importLanguineLock(srcPath) {
|
|
865
|
+
function importLanguineLock(srcPath, { dryRun }) {
|
|
856
866
|
if (FORMAT.name !== "json") {
|
|
857
867
|
console.error(`[translate] --import-languine reads JSON catalogs only; ${SOURCE_FILE} is ${FORMAT.label}.`);
|
|
858
868
|
process.exit(1);
|
|
@@ -893,16 +903,32 @@ function importLanguineLock(srcPath) {
|
|
|
893
903
|
}
|
|
894
904
|
const [{ entries, unreadable }] = files;
|
|
895
905
|
const { hashes, arrays, stale } = mapLanguineHashes(source, entries);
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
906
|
+
// The import writes a whole new lock. Replacing one that records history
|
|
907
|
+
// (shared hashes for keys Languine lacks, per-locale overrides) would send
|
|
908
|
+
// those keys to the provider again, so only a missing or empty lock is written.
|
|
909
|
+
const refusal = lockHoldsHistory()
|
|
910
|
+
? `${LOCK_FILE} already exists and the import would replace the translation history it records. Move or delete it, then run the import again.`
|
|
911
|
+
: null;
|
|
912
|
+
if (!dryRun) {
|
|
913
|
+
if (refusal) {
|
|
914
|
+
console.error(`[translate] ${refusal}`);
|
|
915
|
+
process.exit(1);
|
|
916
|
+
}
|
|
917
|
+
const lock = { version: 1, source: LOCK_SOURCE, hashes };
|
|
918
|
+
mkdirSync(dirname(LOCK_FILE), { recursive: true });
|
|
919
|
+
writeFileSync(LOCK_FILE, dumpLockYaml(lock));
|
|
920
|
+
}
|
|
921
|
+
console.log(dryRun
|
|
922
|
+
? `[translate] Dry run, nothing written: would import ${Object.keys(hashes).length} hashes from ${srcPath} → ${LOCK_FILE}`
|
|
923
|
+
: `[translate] Imported ${Object.keys(hashes).length} hashes from ${srcPath} → ${LOCK_FILE}`);
|
|
900
924
|
// Say what was left out so the next run's cost is not a surprise.
|
|
901
925
|
const examples = (keys) => {
|
|
902
926
|
const shown = keys.slice(0, 3).map((key) => JSON.stringify(key)).join(", ");
|
|
903
927
|
return keys.length > 3 ? `${shown} (+${keys.length - 3} more)` : shown;
|
|
904
928
|
};
|
|
905
|
-
const again =
|
|
929
|
+
const again = dryRun
|
|
930
|
+
? "would be translated again on the first run after the import"
|
|
931
|
+
: "will be translated again on the next run";
|
|
906
932
|
if (arrays.length) {
|
|
907
933
|
console.log(`[translate] Not imported: ${arrays.length} array entries (autoglot hashes a whole array as one value; those arrays ${again}): ${examples(arrays)}`);
|
|
908
934
|
}
|
|
@@ -912,6 +938,22 @@ function importLanguineLock(srcPath) {
|
|
|
912
938
|
if (stale.length) {
|
|
913
939
|
console.log(`[translate] Ignored: ${stale.length} entries that match no key in ${SOURCE_FILE}: ${examples(stale)}`);
|
|
914
940
|
}
|
|
941
|
+
// A preview fails the way the import would.
|
|
942
|
+
if (refusal) {
|
|
943
|
+
console.error(`[translate] ${refusal}`);
|
|
944
|
+
process.exit(1);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// An empty or whitespace-only lock records nothing, so the import may replace it.
|
|
949
|
+
function lockHoldsHistory() {
|
|
950
|
+
try {
|
|
951
|
+
return readFileSync(LOCK_FILE, "utf8").trim() !== "";
|
|
952
|
+
} catch (error) {
|
|
953
|
+
// A missing file has nothing to lose. A directory or an unreadable file
|
|
954
|
+
// is left alone.
|
|
955
|
+
return error.code !== "ENOENT" && error.code !== "ENOTDIR";
|
|
956
|
+
}
|
|
915
957
|
}
|
|
916
958
|
|
|
917
959
|
// One line about files that look like catalogs by name and were left alone.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autoglot",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "AI-powered i18n translation bot. Diff your source catalog on every push, translate only what changed, commit the translated files back. JSON, Flutter ARB, YAML and Java .properties. Open-source alternative to Languine, Lokalise, and Crowdin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|