Skip to content

Commit 4e54cae

Browse files
committed
Script: Lang: Add gitignore for config file in language translation scripts + add default config file template + change default locale to 'en_US' instead of 'en'
1 parent 4ec6120 commit 4e54cae

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

tests/scripts/lang/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.php

tests/scripts/lang/ai_translate.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33

44
/* For licensing terms, see /license.txt */
55

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.
77
// Run from tests/scripts/lang/ with access to ../../../translations/
88
// Requires curl and JSON extensions.
99
// Set the $apiKey variable with your Grok API key.
1010
// Usage: php grok_translate.php [lang1] [lang2] ...
1111
// If no languages provided, processes all messages.*.po except messages.en.po
1212

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 ?? '';
1522

1623
/**
1724
* Chamilo Gettext auto-translator using Grok (grok-4-1-fast-non-reasoning)
@@ -36,11 +43,11 @@
3643
*/
3744

3845
// ===================== 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;
4148

4249
// Base (source) language and file
43-
$sourceLanguageCode = 'en_US';
50+
$sourceLanguageCode = $translationSourceLanguageCode;
4451
$translationsDir = __DIR__ . "/../../../translations/";
4552
$basePoFile = $translationsDir . "messages.{$sourceLanguageCode}.po";
4653

@@ -416,7 +423,7 @@ function parseTargetPoFile(string $filePath): array {
416423
* -> considered mostly English, needs translation
417424
*/
418425
function needsTranslationUpdate(string $msgid, string $msgstr, string $targetLang): bool {
419-
if ($targetLang === 'en') {
426+
if ($targetLang === 'en_US') {
420427
return false;
421428
}
422429

@@ -718,7 +725,7 @@ function buildTargetPoContent(
718725

719726
// Skip English and any template (.pot disguised as .po)
720727
// 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') {
722729
continue;
723730
}
724731

tests/scripts/lang/config.dist.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Configuration settings for scripts in this folder.
3+
// Copy this file to config.php and fill in your API key before using the scripts.
4+
$translationAPIKey = '{your_api_key}';
5+
$translationAPIEndpoint = 'https://api.x.ai/v1/chat/completions';
6+
// Base (source) language and file
7+
$translationSourceLanguageCode = 'en_US';

0 commit comments

Comments
 (0)