Skip to content

Commit

Permalink
updated tool to extract translations
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusle committed Dec 1, 2023
1 parent 1e11f8d commit 1fed01d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 11 additions & 3 deletions tools/translator/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
global $LANGUAGES;

require_once(__DIR__ . '/libs/translator.php');
$translator = new Translator();
?>
Expand All @@ -20,7 +22,13 @@
<br /><br />
<b>Actions</b>:
<input type="submit" name="action" value="Generate empty.json" />
<input style="font-weight:bold;" type="submit" name="action" value="Auto Translate" />
<input type="submit" name="action" value="Auto Translate: all" /> or

<?php
foreach ($LANGUAGES as $lang) {
echo '<button type="submit" name="action" value="Auto Translate: '.strtolower($lang).'">'.strtoupper($lang).'</button> ';
}
?>
<br /><br />
<?php
if (count($_POST) > 0) {
Expand Down Expand Up @@ -54,13 +62,13 @@
if ($_POST['action'] == 'Merge') {
$translator->merge();
}
if ($_POST['action'] == 'Auto Translate') {
if (stripos($_POST['action'], 'Auto Translate') !== false) {
//prepare
$translator->scan();
$translator->extract();
$translator->filter();

$translator->auto_translate();
$translator->auto_translate($_POST['action']);
}
if ($_POST['action'] == 'Generate empty.json') {
//prepare
Expand Down
11 changes: 10 additions & 1 deletion tools/translator/libs/translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,22 @@ public function add_translation($translation) {
*
* @throws Exception
*/
public function auto_translate() {
public function auto_translate($action_string) {
global $LANGUAGES, $LANG_DIR;

$action_string = str_replace('Auto Translate: ', '', $action_string);
if($action_string == 'all'){
$action_string = '';
}

$service = new GoogleTranslate();
$text = implode("\n", $this->strings);

foreach ($LANGUAGES as $lang) {
if($action_string != '' && $action_string != $lang){
continue;
}

echo "<br />$lang: ";

$file_path = $LANG_DIR . strtolower($lang) . ".json";
Expand Down

0 comments on commit 1fed01d

Please sign in to comment.