@drone1/alt 0.9.3 → 1.0.0
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/.github/workflows/test.yml +30 -0
- package/.mocharc.cjs +13 -0
- package/README.md +8 -15
- package/localization/.localization.cache.json +1244 -140
- package/localization/aa.json +9 -1
- package/localization/af.json +9 -1
- package/localization/agq.json +9 -1
- package/localization/ak.json +9 -1
- package/localization/am.json +9 -1
- package/localization/ar.json +9 -1
- package/localization/as.json +9 -1
- package/localization/asa.json +9 -1
- package/localization/ast.json +9 -1
- package/localization/az.json +9 -1
- package/localization/ba.json +9 -1
- package/localization/bas.json +9 -1
- package/localization/be.json +9 -1
- package/localization/bem.json +9 -1
- package/localization/bez.json +9 -1
- package/localization/bg.json +9 -1
- package/localization/bm.json +9 -1
- package/localization/bn.json +9 -1
- package/localization/bo.json +9 -1
- package/localization/br.json +9 -1
- package/localization/brx.json +9 -1
- package/localization/bs.json +9 -1
- package/localization/byn.json +9 -1
- package/localization/ca.json +9 -1
- package/localization/ccp.json +9 -1
- package/localization/cd-RU.json +9 -1
- package/localization/ceb.json +9 -1
- package/localization/cgg.json +9 -1
- package/localization/chr.json +9 -1
- package/localization/co.json +9 -1
- package/localization/cs.json +9 -1
- package/localization/cu-RU.json +9 -1
- package/localization/da.json +9 -1
- package/localization/de-AT.json +9 -1
- package/localization/de-CH.json +9 -1
- package/localization/de-DE.json +9 -1
- package/localization/dua.json +9 -1
- package/localization/dv.json +9 -1
- package/localization/dz.json +9 -1
- package/localization/ebu.json +9 -1
- package/localization/en.json +9 -1
- package/localization/es-ES.json +9 -1
- package/localization/es-MX.json +9 -1
- package/localization/et.json +9 -1
- package/localization/eu.json +9 -1
- package/localization/fr-CA.json +9 -1
- package/localization/fr-CH.json +9 -1
- package/localization/fr-FR.json +9 -1
- package/localization/gsw.json +9 -1
- package/localization/hi.json +9 -1
- package/localization/hr.json +9 -1
- package/localization/hy.json +9 -1
- package/localization/ja.json +9 -1
- package/localization/km.json +9 -1
- package/localization/ksf.json +9 -1
- package/localization/ku.json +9 -1
- package/localization/kw.json +9 -1
- package/localization/my.json +9 -1
- package/localization/nl.json +9 -1
- package/localization/prs.json +9 -1
- package/localization/reference.js +10 -1
- package/localization/ru.json +9 -1
- package/localization/sq.json +9 -1
- package/localization/swc.json +9 -1
- package/localization/th.json +9 -1
- package/localization/tzm-Latn-.json +9 -1
- package/localization/uk.json +9 -1
- package/localization/vi.json +9 -1
- package/localization/zh-Hans.json +9 -1
- package/localization/zh-Hant.json +9 -1
- package/npm-shrinkwrap.json +6498 -676
- package/package.json +19 -1
- package/src/commands/list-models.js +1 -0
- package/src/commands/translate.js +42 -9
- package/src/lib/config.js +1 -1
- package/src/lib/context-keys.js +12 -3
- package/src/lib/io.js +10 -3
- package/src/lib/reference-loader.js +1 -0
- package/src/main.mjs +2 -2
- package/test/README.md +37 -0
- package/test/common.mjs +29 -0
- package/test/config.test.js +78 -0
- package/test/fixtures/reference.js +5 -0
- package/test/fixtures/reference.json +5 -0
- package/test/fixtures/reference.jsonc +8 -0
- package/test/list-models.test.js +27 -0
- package/test/localization.test.js +124 -0
- package/test/main-cli.test.js +79 -0
- package/test/mocha.setup.js +10 -0
- package/test/translate-command.test.js +122 -0
- package/test/reference.js +0 -28
- package/test/reference.json +0 -28
- package/test/reference.jsonc +0 -29
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { execa } from 'execa'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { fileURLToPath } from 'url'
|
|
6
|
+
import { dirname } from 'path'
|
|
7
|
+
import crypto from 'crypto'
|
|
8
|
+
import { SRC_DATA_DIR, cleanupFile, cleanupCacheFile } from './common.mjs'
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
+
const __dirname = dirname(__filename)
|
|
12
|
+
|
|
13
|
+
describe('translate command', () => {
|
|
14
|
+
it('should translate content to a target language', async function() {
|
|
15
|
+
this.timeout(10000) // Set timeout to 10s as translation might take time
|
|
16
|
+
|
|
17
|
+
// Generate a random ID for the reference file
|
|
18
|
+
const randomId = crypto.randomBytes(4).toString('hex')
|
|
19
|
+
const refFileName = `ref-${randomId}.js`
|
|
20
|
+
const refFilePath = path.join(SRC_DATA_DIR, refFileName)
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// Copy the reference file
|
|
24
|
+
const originalRefPath = path.join(SRC_DATA_DIR, 'reference.js')
|
|
25
|
+
fs.copyFileSync(originalRefPath, refFilePath)
|
|
26
|
+
|
|
27
|
+
expect(fs.existsSync(refFilePath)).to.be.true
|
|
28
|
+
|
|
29
|
+
// Run the translation command
|
|
30
|
+
const result = await execa('node', [
|
|
31
|
+
path.resolve(__dirname, '../alt.mjs'),
|
|
32
|
+
'translate',
|
|
33
|
+
'-r',
|
|
34
|
+
refFilePath,
|
|
35
|
+
'-p',
|
|
36
|
+
'anthropic',
|
|
37
|
+
'-rl',
|
|
38
|
+
'en',
|
|
39
|
+
'-tl',
|
|
40
|
+
'fr-FR',
|
|
41
|
+
'-k',
|
|
42
|
+
'msg-test',
|
|
43
|
+
'-d'
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
// Check command executed successfully
|
|
47
|
+
expect(result.exitCode).to.equal(0)
|
|
48
|
+
|
|
49
|
+
// Check output file was created
|
|
50
|
+
const outputPath = path.join(SRC_DATA_DIR, 'fr-FR.json')
|
|
51
|
+
expect(
|
|
52
|
+
fs.existsSync(outputPath),
|
|
53
|
+
`${outputPath} didn't exist`
|
|
54
|
+
).to.be.true
|
|
55
|
+
|
|
56
|
+
// Verify the translation file contents
|
|
57
|
+
const outputContent = JSON.parse(fs.readFileSync(outputPath, 'utf8'))
|
|
58
|
+
expect(outputContent).to.have.property('msg-test')
|
|
59
|
+
expect(outputContent['msg-test']).to.be.a('string')
|
|
60
|
+
expect(outputContent['msg-test'].length).to.be.greaterThan(0)
|
|
61
|
+
|
|
62
|
+
// Clean up output file
|
|
63
|
+
cleanupFile(outputPath)
|
|
64
|
+
} finally {
|
|
65
|
+
// Clean up reference file
|
|
66
|
+
cleanupFile(refFilePath)
|
|
67
|
+
cleanupCacheFile(SRC_DATA_DIR)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should handle multiple target languages', async function() {
|
|
72
|
+
this.timeout(15000) // Higher timeout for multiple translations
|
|
73
|
+
|
|
74
|
+
// Generate a random ID for the reference file
|
|
75
|
+
const randomId = crypto.randomBytes(4).toString('hex')
|
|
76
|
+
const refFileName = `ref-${randomId}.js`
|
|
77
|
+
const refFilePath = path.join(SRC_DATA_DIR, refFileName)
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
// Copy the reference file
|
|
81
|
+
const originalRefPath = path.join(SRC_DATA_DIR, 'reference.js')
|
|
82
|
+
fs.copyFileSync(originalRefPath, refFilePath)
|
|
83
|
+
|
|
84
|
+
// Run the translation command with multiple languages
|
|
85
|
+
const result = await execa('node', [
|
|
86
|
+
path.resolve(__dirname, '../alt.mjs'),
|
|
87
|
+
'translate',
|
|
88
|
+
'-p',
|
|
89
|
+
'anthropic',
|
|
90
|
+
'-r',
|
|
91
|
+
refFilePath,
|
|
92
|
+
'-rl',
|
|
93
|
+
'en',
|
|
94
|
+
'-tl',
|
|
95
|
+
'fr-FR,es-ES',
|
|
96
|
+
'-k',
|
|
97
|
+
'msg-test'
|
|
98
|
+
])
|
|
99
|
+
|
|
100
|
+
console.log(result.command)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// Check command executed successfully
|
|
104
|
+
expect(result.exitCode).to.equal(0)
|
|
105
|
+
|
|
106
|
+
// Check output files were created
|
|
107
|
+
const frOutputPath = path.join(SRC_DATA_DIR, 'fr-FR.json')
|
|
108
|
+
const esOutputPath = path.join(SRC_DATA_DIR, 'es-ES.json')
|
|
109
|
+
|
|
110
|
+
expect(fs.existsSync(frOutputPath)).to.be.true
|
|
111
|
+
expect(fs.existsSync(esOutputPath)).to.be.true
|
|
112
|
+
|
|
113
|
+
// Clean up output files
|
|
114
|
+
cleanupFile(frOutputPath)
|
|
115
|
+
cleanupFile(esOutputPath)
|
|
116
|
+
} finally {
|
|
117
|
+
// Clean up reference file
|
|
118
|
+
cleanupFile(refFilePath)
|
|
119
|
+
cleanupCacheFile(SRC_DATA_DIR)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
})
|
package/test/reference.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
'msg-nothing-to-do': `Nothing to do`,
|
|
3
|
-
'msg-finished-with-errors': `Finished with %%errorsEncountered%% error%%s%%`,
|
|
4
|
-
|
|
5
|
-
'msg-translating': 'Translating...',
|
|
6
|
-
'msg-translating-key': `Translating %%key%%`,
|
|
7
|
-
'msg-preparing-endpoint-config': `Preparing endpoint configuration...`,
|
|
8
|
-
'msg-hitting-provider-endpoint': `Hitting %%providerName%% endpoint%%attemptStr%%...`,
|
|
9
|
-
|
|
10
|
-
'msg-no-update-needed-for-key': `No update needed for %%key%%`,
|
|
11
|
-
'msg-rate-limited-sleeping': `Rate limited; sleeping for %%interval%%s...%%attemptStr%%`,
|
|
12
|
-
'msg-show-translation-result': `Translated %%key%%: "%%newValue%%"`,
|
|
13
|
-
'msg-processing-lang-and-key': `[%%progress%%%] Processing %%targetLang%% – %%key%%...`,
|
|
14
|
-
|
|
15
|
-
'msg-translation-reason-forced': `Forced update`,
|
|
16
|
-
'msg-translation-reason-outputFileDidNotExist': `Output file %%outputFile%% did not exist`,
|
|
17
|
-
'msg-translation-reason-userMissingReferenceValueHash': `No reference hash found`,
|
|
18
|
-
'msg-translation-reason-userModifiedReferenceValue': `User modified reference string`,
|
|
19
|
-
'msg-translation-reason-missingOutputKey': `No existing translation found`,
|
|
20
|
-
'msg-translation-reason-missingOutputValueHash': `No hash found in cache file`,
|
|
21
|
-
|
|
22
|
-
'error-value-not-a-string': `Value for reference key "%%key%%" was "%%type%%". Expected a string! Skipping...`,
|
|
23
|
-
'error-value-not-in-reference-data': `Key "%%key%%" did not exist in reference file`,
|
|
24
|
-
'error-translation-failed': `Translation failed for target language=%%targetLang%%; key=%%key%%; text=%%refValue%%`,
|
|
25
|
-
'error-bad-reference-file-ext': `Unsupported file type for reference file "%%ext%%"`,
|
|
26
|
-
'error-reference-var-not-found-in-data': `Couldn't find "%%referenceExportedVarName%%" in reference file "%%referenceFile%%". Did you mean one of these instead?: %%possibleKeys%%`,
|
|
27
|
-
'error-reference-file-load-failed': `Failed to load reference file "%%referenceFile%%"`
|
|
28
|
-
}
|
package/test/reference.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"msg-nothing-to-do": "Nothing to do",
|
|
3
|
-
"msg-finished-with-errors": "Finished with %%errorsEncountered%% error%%s%%",
|
|
4
|
-
|
|
5
|
-
"msg-translating": "Translating...",
|
|
6
|
-
"msg-translating-key": "Translating %%key%%",
|
|
7
|
-
"msg-preparing-endpoint-config": "Preparing endpoint configuration...",
|
|
8
|
-
"msg-hitting-provider-endpoint": "Hitting %%providerName%% endpoint%%attemptStr%%...",
|
|
9
|
-
|
|
10
|
-
"msg-no-update-needed-for-key": "No update needed for %%key%%",
|
|
11
|
-
"msg-rate-limited-sleeping": "Rate limited; sleeping for %%interval%%s...%%attemptStr%%",
|
|
12
|
-
"msg-show-translation-result": "Translated %%key%%: \"%%newValue%%\"",
|
|
13
|
-
"msg-processing-lang-and-key": "[%%progress%%%] Processing %%targetLang%% – %%key%%...",
|
|
14
|
-
|
|
15
|
-
"msg-translation-reason-forced": "Forced update",
|
|
16
|
-
"msg-translation-reason-outputFileDidNotExist": "Output file %%outputFile%% did not exist",
|
|
17
|
-
"msg-translation-reason-userMissingReferenceValueHash": "No reference hash found",
|
|
18
|
-
"msg-translation-reason-userModifiedReferenceValue": "User modified reference string",
|
|
19
|
-
"msg-translation-reason-missingOutputKey": "No existing translation found",
|
|
20
|
-
"msg-translation-reason-missingOutputValueHash": "No hash found in cache file",
|
|
21
|
-
|
|
22
|
-
"error-value-not-a-string": "Value for reference key \"%%key%%\" was \"%%type%%\". Expected a string! Skipping...",
|
|
23
|
-
"error-value-not-in-reference-data": "Key \"%%key%%\" did not exist in reference file",
|
|
24
|
-
"error-translation-failed": "Translation failed for target language=%%targetLang%%; key=%%key%%; text=%%refValue%%",
|
|
25
|
-
"error-bad-reference-file-ext": "Unsupported file type for reference file \"%%ext%%\"",
|
|
26
|
-
"error-reference-var-not-found-in-data": "Couldn't find \"%%referenceExportedVarName%%\" in reference file \"%%referenceFile%%\". Did you mean one of these instead?: %%possibleKeys%%",
|
|
27
|
-
"error-reference-file-load-failed": "Failed to load reference file \"%%referenceFile%%\""
|
|
28
|
-
}
|
package/test/reference.jsonc
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"msg-nothing-to-do": "Nothing to do",
|
|
3
|
-
"msg-finished-with-errors": "Finished with %%errorsEncountered%% error%%s%%",
|
|
4
|
-
|
|
5
|
-
"msg-translating": "Translating...",
|
|
6
|
-
"msg-translating-key": "Translating %%key%%",
|
|
7
|
-
"msg-preparing-endpoint-config": "Preparing endpoint configuration...",
|
|
8
|
-
"msg-hitting-provider-endpoint": "Hitting %%providerName%% endpoint%%attemptStr%%...",
|
|
9
|
-
|
|
10
|
-
"msg-no-update-needed-for-key": "No update needed for %%key%%",
|
|
11
|
-
"msg-rate-limited-sleeping": "Rate limited; sleeping for %%interval%%s...%%attemptStr%%",
|
|
12
|
-
"msg-show-translation-result": "Translated %%key%%: \"%%newValue%%\"",
|
|
13
|
-
"msg-processing-lang-and-key": "[%%progress%%%] Processing %%targetLang%% – %%key%%...",
|
|
14
|
-
|
|
15
|
-
"msg-translation-reason-forced": "Forced update",
|
|
16
|
-
"msg-translation-reason-outputFileDidNotExist": "Output file %%outputFile%% did not exist",
|
|
17
|
-
"msg-translation-reason-userMissingReferenceValueHash": "No reference hash found",
|
|
18
|
-
"msg-translation-reason-userModifiedReferenceValue": "User modified reference string",
|
|
19
|
-
"msg-translation-reason-missingOutputKey": "No existing translation found",
|
|
20
|
-
"msg-translation-reason-missingOutputValueHash": "No hash found in cache file",
|
|
21
|
-
|
|
22
|
-
// Errors
|
|
23
|
-
"error-value-not-a-string": "Value for reference key \"%%key%%\" was \"%%type%%\". Expected a string! Skipping...",
|
|
24
|
-
"error-value-not-in-reference-data": "Key \"%%key%%\" did not exist in reference file",
|
|
25
|
-
"error-translation-failed": "Translation failed for target language=%%targetLang%%; key=%%key%%; text=%%refValue%%",
|
|
26
|
-
"error-bad-reference-file-ext": "Unsupported file type for reference file \"%%ext%%\"",
|
|
27
|
-
"error-reference-var-not-found-in-data": "Couldn't find \"%%referenceExportedVarName%%\" in reference file \"%%referenceFile%%\". Did you mean one of these instead?: %%possibleKeys%%",
|
|
28
|
-
"error-reference-file-load-failed": "Failed to load reference file \"%%referenceFile%%\""
|
|
29
|
-
}
|