|
3 | 3 |
|
4 | 4 | /* For licensing terms, see /license.txt */ |
5 | 5 |
|
6 | | -// This script completes translations for Chamilo LMS using the Grok API. |
| 6 | +// This script completes translations for Chamilo LMS using the Grok (or other AI) API. |
7 | 7 | // Run from tests/scripts/lang/ with access to ../../../translations/ |
8 | 8 | // Requires curl and JSON extensions. |
9 | 9 | // Set the $apiKey variable with your Grok API key. |
10 | 10 | // Usage: php grok_translate.php [lang1] [lang2] ... |
11 | 11 | // If no languages provided, processes all messages.*.po except messages.en.po |
12 | 12 |
|
13 | | -exit; |
14 | | -$apiKey = '{some-api-key-here}'; |
| 13 | +$translationSourceLanguageCode = 'en_US'; |
| 14 | +$translationAPIEndpoint = 'https://api.x.ai/v1/chat/completions'; |
| 15 | + |
| 16 | +$configFile = __DIR__ . '/config.php'; |
| 17 | +if (!is_file(__DIR__ . '/config.php')) { |
| 18 | + exit('No config.php file found in this directory. Please copy config.php.dist to config.php and fill in your API key.'); |
| 19 | +} |
| 20 | +require_once __DIR__ . '/config.php'; |
| 21 | +$apiKey = $translationAPIKey ?? ''; |
15 | 22 |
|
16 | 23 | /** |
17 | 24 | * Chamilo Gettext auto-translator using Grok (grok-4-1-fast-non-reasoning) |
|
36 | 43 | */ |
37 | 44 |
|
38 | 45 | // ===================== CONFIGURATION ===================== |
39 | | -// Grok chat-completions-like endpoint URL |
40 | | -$apiUrl = 'https://api.x.ai/v1/chat/completions'; |
| 46 | +// AI chat-completions-like endpoint URL |
| 47 | +$apiUrl = $translationAPIEndpoint; |
41 | 48 |
|
42 | 49 | // Base (source) language and file |
43 | | -$sourceLanguageCode = 'en_US'; |
| 50 | +$sourceLanguageCode = $translationSourceLanguageCode; |
44 | 51 | $translationsDir = __DIR__ . "/../../../translations/"; |
45 | 52 | $basePoFile = $translationsDir . "messages.{$sourceLanguageCode}.po"; |
46 | 53 |
|
@@ -416,7 +423,7 @@ function parseTargetPoFile(string $filePath): array { |
416 | 423 | * -> considered mostly English, needs translation |
417 | 424 | */ |
418 | 425 | function needsTranslationUpdate(string $msgid, string $msgstr, string $targetLang): bool { |
419 | | - if ($targetLang === 'en') { |
| 426 | + if ($targetLang === 'en_US') { |
420 | 427 | return false; |
421 | 428 | } |
422 | 429 |
|
@@ -718,7 +725,7 @@ function buildTargetPoContent( |
718 | 725 |
|
719 | 726 | // Skip English and any template (.pot disguised as .po) |
720 | 727 | // Tibetan (bo) is skipped because error-prone. Might be "unskipped" in the future. Execute manually (add 'po' parameter to command) to update. |
721 | | - if ($code === 'en' || $code === 'bo' || $code === 'pot') { |
| 728 | + if ($code === 'en_US' || $code === 'bo_CN' || $code === 'pot') { |
722 | 729 | continue; |
723 | 730 | } |
724 | 731 |
|
|
0 commit comments