@publishpress/potomatic 0.0.0-stage → 1.4.5
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/CHANGELOG.md +127 -0
- package/LICENSE.md +20 -0
- package/README.md +470 -2
- package/config/openai-pricing.json +112 -0
- package/config/po-header.json +10 -0
- package/config/prompt.md +23 -0
- package/package.json +84 -5
- package/potomatic +103 -0
- package/src/config/index.js +497 -0
- package/src/logging/index.js +362 -0
- package/src/orchestrator/index.js +1031 -0
- package/src/processors/batchProcessor.js +171 -0
- package/src/processors/languageProcessor.js +1464 -0
- package/src/providers/ProviderFactory.js +124 -0
- package/src/providers/base/Provider.js +198 -0
- package/src/providers/openai/OpenAIProvider.js +805 -0
- package/src/providers/openai/modelCapabilities.js +256 -0
- package/src/reporters/ConsoleReporter.js +256 -0
- package/src/reporters/JsonReporter.js +254 -0
- package/src/reporters/ReporterFactory.js +218 -0
- package/src/reporters/base/BaseReporter.js +124 -0
- package/src/utils/colorUtils.js +93 -0
- package/src/utils/costCalculations.js +245 -0
- package/src/utils/costTracker.js +277 -0
- package/src/utils/dictionaryUtils.js +211 -0
- package/src/utils/languageMapping.js +1113 -0
- package/src/utils/pluralization.js +39 -0
- package/src/utils/poFileUtils.js +599 -0
- package/src/utils/promptLoader.js +115 -0
- package/src/utils/reportingUtils.js +417 -0
- package/src/utils/validationStats.js +110 -0
- package/src/utils/xmlTranslation.js +532 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lastUpdated": "2026-11-19",
|
|
3
|
+
"source": "https://platform.openai.com/docs/pricing",
|
|
4
|
+
"note": "Prices are per 1,000 tokens in USD. Standard tier, short context. These model keys also define which models the OpenAI provider accepts, so only chat-completions-capable models belong here.",
|
|
5
|
+
"models": {
|
|
6
|
+
"gpt-6.2-astra": {
|
|
7
|
+
"prompt": 0.008,
|
|
8
|
+
"completion": 0.04
|
|
9
|
+
},
|
|
10
|
+
"gpt-6.2-sol": {
|
|
11
|
+
"prompt": 0.002,
|
|
12
|
+
"completion": 0.01
|
|
13
|
+
},
|
|
14
|
+
"gpt-6-astra": {
|
|
15
|
+
"prompt": 0.01,
|
|
16
|
+
"completion": 0.05
|
|
17
|
+
},
|
|
18
|
+
"gpt-6.1-sol": {
|
|
19
|
+
"prompt": 0.002,
|
|
20
|
+
"completion": 0.01
|
|
21
|
+
},
|
|
22
|
+
"gpt-6.1-terra": {
|
|
23
|
+
"prompt": 0.001,
|
|
24
|
+
"completion": 0.005
|
|
25
|
+
},
|
|
26
|
+
"gpt-6-sol": {
|
|
27
|
+
"prompt": 0.002,
|
|
28
|
+
"completion": 0.01
|
|
29
|
+
},
|
|
30
|
+
"gpt-6-luna": {
|
|
31
|
+
"prompt": 0.0001,
|
|
32
|
+
"completion": 0.0005
|
|
33
|
+
},
|
|
34
|
+
"gpt-5.6-sol": {
|
|
35
|
+
"prompt": 0.004,
|
|
36
|
+
"completion": 0.02
|
|
37
|
+
},
|
|
38
|
+
"gpt-5.6-terra": {
|
|
39
|
+
"prompt": 0.002,
|
|
40
|
+
"completion": 0.012
|
|
41
|
+
},
|
|
42
|
+
"gpt-5.6-luna": {
|
|
43
|
+
"prompt": 0.0002,
|
|
44
|
+
"completion": 0.0012
|
|
45
|
+
},
|
|
46
|
+
"gpt-5.5": {
|
|
47
|
+
"prompt": 0.005,
|
|
48
|
+
"completion": 0.03
|
|
49
|
+
},
|
|
50
|
+
"gpt-5.4": {
|
|
51
|
+
"prompt": 0.0025,
|
|
52
|
+
"completion": 0.015
|
|
53
|
+
},
|
|
54
|
+
"gpt-5.4-mini": {
|
|
55
|
+
"prompt": 0.00075,
|
|
56
|
+
"completion": 0.0045
|
|
57
|
+
},
|
|
58
|
+
"gpt-5.4-nano": {
|
|
59
|
+
"prompt": 0.0002,
|
|
60
|
+
"completion": 0.00125
|
|
61
|
+
},
|
|
62
|
+
"gpt-5.2": {
|
|
63
|
+
"prompt": 0.00175,
|
|
64
|
+
"completion": 0.014
|
|
65
|
+
},
|
|
66
|
+
"gpt-5.1": {
|
|
67
|
+
"prompt": 0.00125,
|
|
68
|
+
"completion": 0.01
|
|
69
|
+
},
|
|
70
|
+
"gpt-5": {
|
|
71
|
+
"prompt": 0.00125,
|
|
72
|
+
"completion": 0.01
|
|
73
|
+
},
|
|
74
|
+
"gpt-5-mini": {
|
|
75
|
+
"prompt": 0.00025,
|
|
76
|
+
"completion": 0.002
|
|
77
|
+
},
|
|
78
|
+
"gpt-5-nano": {
|
|
79
|
+
"prompt": 0.00005,
|
|
80
|
+
"completion": 0.0004
|
|
81
|
+
},
|
|
82
|
+
"gpt-4.1": {
|
|
83
|
+
"prompt": 0.002,
|
|
84
|
+
"completion": 0.008
|
|
85
|
+
},
|
|
86
|
+
"gpt-4.1-mini": {
|
|
87
|
+
"prompt": 0.0004,
|
|
88
|
+
"completion": 0.0016
|
|
89
|
+
},
|
|
90
|
+
"gpt-4.1-nano": {
|
|
91
|
+
"prompt": 0.0001,
|
|
92
|
+
"completion": 0.0004
|
|
93
|
+
},
|
|
94
|
+
"o4-mini": {
|
|
95
|
+
"prompt": 0.0011,
|
|
96
|
+
"completion": 0.0044
|
|
97
|
+
},
|
|
98
|
+
"o3": {
|
|
99
|
+
"prompt": 0.002,
|
|
100
|
+
"completion": 0.008
|
|
101
|
+
},
|
|
102
|
+
"o3-mini": {
|
|
103
|
+
"prompt": 0.0011,
|
|
104
|
+
"completion": 0.0044
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"fallback": {
|
|
108
|
+
"prompt": 0.00075,
|
|
109
|
+
"completion": 0.0045,
|
|
110
|
+
"note": "Used for unknown models, based on gpt-5.4-mini"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Project-Id-Version": "GravityKita",
|
|
3
|
+
"Report-Msgid-Bugs-To": "GravityKit <support@gravitykit.com>",
|
|
4
|
+
"Last-Translator": "GravityKit <support@gravitykit.com>",
|
|
5
|
+
"Language-Team": "GravityKit <support@gravitykit.com>",
|
|
6
|
+
"MIME-Version": "1.0",
|
|
7
|
+
"Content-Type": "text/plain; charset=UTF-8",
|
|
8
|
+
"Content-Transfer-Encoding": "8bit",
|
|
9
|
+
"X-Generator": "GravityKit Automated Translations"
|
|
10
|
+
}
|
package/config/prompt.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
You are a professional translator specializing in software localization. Your task is to translate XML tags from {{SOURCE_LANGUAGE}} to {{TARGET_LANGUAGE}} ({{TARGET_LANGUAGE_CODE}}), intended for use in app UIs, tooltips, dialogs, and help content.
|
|
2
|
+
|
|
3
|
+
### Instructions
|
|
4
|
+
|
|
5
|
+
1. **Translate each XML tag** and respond with the translated content in the same XML structure.
|
|
6
|
+
2. **CRITICAL — Preserve placeholders exactly**: The translation MUST contain the **exact same placeholders** as the source (%s, %d, %1$s, etc.) — no more, no fewer. If none in source, none in translation. Do NOT add %d or any placeholder that is not in the source. Always use standard ASCII percent sign (%), never the fullwidth % (U+FF05).
|
|
7
|
+
3. **Preserve bracket placeholders**: [example], [product], {value} — keep as-is. Do NOT convert to %s/%1$s.
|
|
8
|
+
4. **Preserve bracket tags**: [strong], [/strong], [link], [/link] — keep as-is. Do NOT convert to HTML.
|
|
9
|
+
5. **Preserve formatting**: Keep line breaks, HTML tags, trailing whitespace unchanged.
|
|
10
|
+
6. **Context/comments**: Use provided context and comment attributes.
|
|
11
|
+
7. **Singular vs. plural entries**:
|
|
12
|
+
- **Singular entries** (no `<singular>`/`<plural>` tags): Provide ONE translation. Do NOT use `<f0>`, `<f1>`, etc. — just `<t i="N">translation</t>`. Translate the string literally, even if it contains a number (e.g., "30 files" → translate as-is, do NOT split into plural forms).
|
|
13
|
+
- **Plural entries** (with `<singular>` and `<plural>` tags): Provide exactly {{PLURAL_COUNT}} DISTINCT translations using `<f0>`, `<f1>`, etc. Only use placeholders that exist in the source — if the source uses [number] instead of %d, use [number] in ALL forms, never add %d. Rules:
|
|
14
|
+
- Arabic(6): f0=zero(plural), f1=one(singular, may drop %d if source has it), f2=two(dual تان/تين, may drop %d if source has it), f3=few(plural), f4=many(plural), f5=other(plural)
|
|
15
|
+
- Russian/Polish(3): f0=singular, f1=paucal(2-4), f2=plural(5+)
|
|
16
|
+
- French(2): f0=0+1, f1=2+
|
|
17
|
+
- Japanese/Chinese/Korean(1): f0 only, MUST keep all placeholders
|
|
18
|
+
|
|
19
|
+
### Output Format
|
|
20
|
+
|
|
21
|
+
Singular: `<t i="N">translation</t>`
|
|
22
|
+
|
|
23
|
+
Plural: `<t i="N"><f0>...</f0><f1>...</f1>...</t>`
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@publishpress/potomatic",
|
|
3
|
+
"version": "1.4.5",
|
|
4
|
+
"description": "AI-powered translation utility for translating .po(t) files into multiple languages",
|
|
5
|
+
"author": "PublishPress",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ai",
|
|
8
|
+
"gpt",
|
|
9
|
+
"translation",
|
|
10
|
+
"po",
|
|
11
|
+
"pot",
|
|
12
|
+
"OpenAI",
|
|
13
|
+
"gpt",
|
|
14
|
+
"i18n",
|
|
15
|
+
"gettext",
|
|
16
|
+
"localization",
|
|
17
|
+
"WordPress"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://www.gravitykit.com/potomatic/",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/publishpress/library-potomatic/issues"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/publishpress/library-potomatic.git"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "potomatic",
|
|
30
|
+
"files": [
|
|
31
|
+
"potomatic",
|
|
32
|
+
"src/",
|
|
33
|
+
"config/",
|
|
34
|
+
"CHANGELOG.md",
|
|
35
|
+
"LICENSE.md",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"bin": {
|
|
39
|
+
"potomatic": "potomatic"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"translate": "./potomatic",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:watch": "vitest",
|
|
45
|
+
"test:coverage": "vitest run --coverage",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"lint:fix": "eslint . --fix",
|
|
48
|
+
"format": "prettier --write \"**/*.{js,json}\"",
|
|
49
|
+
"format:check": "prettier --check \"**/*.{js,json}\"",
|
|
50
|
+
"prepublishOnly": "npm run lint && npm run format:check && npm test"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"chalk": "^5.3.0",
|
|
57
|
+
"commander": "^12.0.0",
|
|
58
|
+
"dotenv": "^16.5.0",
|
|
59
|
+
"extract-zip": "^2.0.1",
|
|
60
|
+
"gettext-parser": "^8.0.0",
|
|
61
|
+
"listr2": "^8.0.0",
|
|
62
|
+
"node-fetch": "^3.3.2",
|
|
63
|
+
"openai": "^4.0.0",
|
|
64
|
+
"tiktoken": "^1.0.22",
|
|
65
|
+
"zod": "^3.25.23"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
69
|
+
"eslint": "^8.57.1",
|
|
70
|
+
"eslint-config-prettier": "^10.1.5",
|
|
71
|
+
"eslint-config-standard": "^17.1.0",
|
|
72
|
+
"eslint-plugin-import": "^2.31.0",
|
|
73
|
+
"eslint-plugin-node": "^11.1.0",
|
|
74
|
+
"eslint-plugin-promise": "^6.6.0",
|
|
75
|
+
"execa": "^8.0.1",
|
|
76
|
+
"nock": "^13.5.4",
|
|
77
|
+
"prettier": "^3.5.3",
|
|
78
|
+
"tmp": "^0.2.3",
|
|
79
|
+
"vitest": "^3.1.4"
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public",
|
|
83
|
+
"registry": "https://registry.npmjs.org/"
|
|
84
|
+
}
|
|
85
|
+
}
|
package/potomatic
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Suppress punycode deprecation warning from tiktoken/whatwg-url dependency.
|
|
4
|
+
process.noDeprecation = true;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Potomatic
|
|
8
|
+
*
|
|
9
|
+
* AI-powered translation utility for converting .pot files to multiple languages.
|
|
10
|
+
*
|
|
11
|
+
* @author GravityKit (https://www.gravitykit.com)
|
|
12
|
+
* @copyright 2025 GravityKit
|
|
13
|
+
* @license GPL-3.0-or-later
|
|
14
|
+
* @version 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import 'dotenv/config';
|
|
18
|
+
import chalk from 'chalk';
|
|
19
|
+
import { parseCliArguments, createConfiguration, validateConfiguration } from './src/config/index.js';
|
|
20
|
+
import { createLogger } from './src/logging/index.js';
|
|
21
|
+
import { TranslationOrchestrator } from './src/orchestrator/index.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Main entry point for the translation system.
|
|
25
|
+
* Handles CLI argument parsing, configuration setup, logging initialization,
|
|
26
|
+
* and orchestrates the complete translation workflow.
|
|
27
|
+
*
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*
|
|
30
|
+
* @return {Promise<void>} Resolves when translation process completes.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} If critical configuration or execution errors occur.
|
|
33
|
+
*/
|
|
34
|
+
async function main() {
|
|
35
|
+
try {
|
|
36
|
+
// Parse CLI arguments.
|
|
37
|
+
const options = parseCliArguments();
|
|
38
|
+
|
|
39
|
+
// Validate configuration before proceeding.
|
|
40
|
+
const validation = validateConfiguration(options);
|
|
41
|
+
if (!validation.isValid) {
|
|
42
|
+
console.error(chalk.red('❌ Configuration validation failed:'));
|
|
43
|
+
validation.errors.forEach((error) => {
|
|
44
|
+
console.error(chalk.red(` ${error}`));
|
|
45
|
+
});
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Create configuration.
|
|
50
|
+
const config = createConfiguration(options);
|
|
51
|
+
|
|
52
|
+
// Initialize main logger with adjusted verbosity for JSON output
|
|
53
|
+
// When outputting JSON to stdout, suppress console logs to avoid mixing output
|
|
54
|
+
let loggerVerbosity = config.verboseLevel;
|
|
55
|
+
if (config.outputFormat === 'json' && !config.outputFile) {
|
|
56
|
+
// JSON to stdout - suppress all console logs to keep output clean
|
|
57
|
+
loggerVerbosity = 0;
|
|
58
|
+
}
|
|
59
|
+
const mainLogger = createLogger(loggerVerbosity);
|
|
60
|
+
|
|
61
|
+
// Create and initialize orchestrator.
|
|
62
|
+
const orchestrator = new TranslationOrchestrator(config, mainLogger);
|
|
63
|
+
await orchestrator.initialize();
|
|
64
|
+
|
|
65
|
+
// Process all languages.
|
|
66
|
+
const exitCode = await orchestrator.processAllLanguages();
|
|
67
|
+
|
|
68
|
+
process.exit(exitCode);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('Fatal error:', error.message);
|
|
71
|
+
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Global unhandled promise rejection handler.
|
|
78
|
+
* Ensures the process exits with error code when promises are rejected without handling.
|
|
79
|
+
*
|
|
80
|
+
* @since 1.0.0
|
|
81
|
+
*
|
|
82
|
+
* @param {any} reason - The rejection reason.
|
|
83
|
+
* @param {Promise} promise - The promise that was rejected.
|
|
84
|
+
*/
|
|
85
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
86
|
+
console.error('Unhandled promise rejection:', reason);
|
|
87
|
+
|
|
88
|
+
process.exit(1);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Error catch handler for the main function.
|
|
93
|
+
* Provides additional safety net for errors not caught by the main try/catch.
|
|
94
|
+
*
|
|
95
|
+
* @since 1.0.0
|
|
96
|
+
*
|
|
97
|
+
* @param {Error} error - The unhandled error.
|
|
98
|
+
*/
|
|
99
|
+
main().catch((error) => {
|
|
100
|
+
console.error('Unhandled error in main:', error);
|
|
101
|
+
|
|
102
|
+
process.exit(1);
|
|
103
|
+
});
|