Skip to content

Commit

Permalink
Update language (command-line) scripts so now the 'lang_update.php' s…
Browse files Browse the repository at this point in the history
…cript runs to automate the entire process. Must be run from the cron folder (it's not that smart)
  • Loading branch information
dleffler committed Dec 15, 2011
1 parent fd5d136 commit 2e3b354
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 61 deletions.
2 changes: 1 addition & 1 deletion cron/lang_extract.php
Expand Up @@ -134,7 +134,7 @@ function do_dir($dir) {
$pi = pathinfo($_SERVER['argv'][$ac]);
do_file($_SERVER['argv'][$ac],$pi['extension']);
}
print "\nCompleted Extracting from ".$total_new." Phrases!\n";
print "\nCompleted Extracting from ".$total_new." Phrases!\n\n";
}

?>
75 changes: 75 additions & 0 deletions cron/lang_translate.php
@@ -0,0 +1,75 @@
#!/usr/bin/env php
<?php
/**
* lang_translate.php - attempts to auto-translate ExponentCMS language files
*/

// Initialize the exponent environment
include_once('../exponent_bootstrap.php');
// Initialize the language subsystem
expLang::loadLang();
global $default_lang, $cur_lang;
if (empty($default_lang)) $default_lang = include(BASE."framework/core/lang/English - US.php");

if (LANGUAGE=="English - US") {
print "You can't update the current language 'English - US' which is also the default translation!\n";
print "Create and/or Switch to another Translation using Manage Translations!\n";
exit;
} elseif (!is_readable(BASE . 'framework/core/lang/' . utf8_decode(LANGUAGE) . '.php')) {
print "The '".utf8_decode(LANGUAGE)."' Translation doesn't seem to exist yet!\n";
print "You must first Create and/or Switch to this Translation using Manage Translations!\n";
exit;
}
print "Updating ".utf8_decode(LANG)." Translation\n";
print count($cur_lang)." Phrases in the ".utf8_decode(LANG)." Translation\n";

// Add new/missing phrases in current language
$num_missing = 0;
foreach ($default_lang as $key => $value) {
if (!array_key_exists($key,$cur_lang)) $num_missing++;
}
$changes = expLang::updateCurrLangFile();
$changes = $changes?$changes:'No';
print $changes." New Phases were Added to the ".utf8_decode(LANG)." Translation\n";

// Remove Obsolete phrases from current language
$num_extra = 0;
foreach ($cur_lang as $key => $value) {
if (!array_key_exists($key,$default_lang)) {
unset($cur_lang[$key]);
expLang::saveCurrLangFile();
$num_extra++;
}
}
$num_extra = $num_extra?$num_extra:'No';
print $num_extra." Obsolete Phases were Found and Removed from the ".utf8_decode(LANG)." Translation\n";

// Attempt a machine translation for un-translated phrases in current language
$num_untrans = 0;
foreach ($cur_lang as $key => $value) {
if ($key == $value) $num_untrans++;
}
print $num_untrans." Phrases appear Un-Translated in the ".utf8_decode(LANG)." Translation\n";
$num_added = 0;
if (defined('LOCALE')) {
foreach ($cur_lang as $key => $value) {
if ($key == $value) {
$translation = expLang::translate($value,'en',LOCALE);
if ($translation) {
$translation = str_replace('"', "\'", $translation); // remove the killer double-quotes
$cur_lang[$key] = addslashes(stripslashes(strip_tags($translation)));
expLang::saveCurrLangFile();
$num_added++;
}
}
}
print $num_added." New Phases were Translated in the ".utf8_decode(LANG)." Translation\n";
} else {
print "There is no Locale Assigned for the ".utf8_decode(LANG)." to attempt a Translation\n";
exit;
}

print count($cur_lang)." Phrases are now in the ".utf8_decode(LANG)." Translation\n";
print "\nCompleted Updating the ".utf8_decode(LANG)." Translation!\n";

?>
92 changes: 32 additions & 60 deletions cron/lang_update.php
@@ -1,75 +1,47 @@
#!/usr/bin/env php
<?php
/**
* lang_update.php - attempts to auto-translate ExponentCMS language files
* lang_update.php - attempts to auto-update all ExponentCMS language files
* by running the other two language scripts lang_extract.php & lang_translate.php
*/

// Initialize the exponent environment
output("Updating the Exponent Language System!\n");

// Update the default phrase library by extracting the English phrases
output("Now extracting phrases from the root folder!\n");
exec ('php ./lang_extract.php -r ..',$output);
output($output);
unset ($output);
output("Now extracting phrases from the folders!\n");
exec ('php ./lang_extract.php ../conf ../cron ../framework ../install ../themes', $output);
output($output);
unset ($output);

//Update each language file based on default language and then attempt to translate
// Initialize the exponent environment and language subsystem
include_once('../exponent_bootstrap.php');
// Initialize the language subsystem
expLang::loadLang();
global $default_lang, $cur_lang;
if (empty($default_lang)) $default_lang = include(BASE."framework/core/lang/English - US.php");

if (LANGUAGE=="English - US") {
print "You can't update the current language 'English - US' which is also the default translation!\n";
print "Create and/or Switch to another Translation using Manage Translations!\n";
exit;
} elseif (!is_readable(BASE . 'framework/core/lang/' . utf8_decode(LANGUAGE) . '.php')) {
print "The '".utf8_decode(LANGUAGE)."' Translation doesn't seem to exist yet!\n";
print "You must first Create and/or Switch to this Translation using Manage Translations!\n";
exit;
}
print "Updating ".utf8_decode(LANG)." Translation\n";
print count($cur_lang)." Phrases in the ".utf8_decode(LANG)." Translation\n";

// Add new/missing phrases in current language
$num_missing = 0;
foreach ($default_lang as $key => $value) {
if (!array_key_exists($key,$cur_lang)) $num_missing++;
}
$changes = expLang::updateCurrLangFile();
$changes = $changes?$changes:'No';
print $changes." New Phases were Added to the ".utf8_decode(LANG)." Translation\n";

// Remove Obsolete phrases from current language
$num_extra = 0;
foreach ($cur_lang as $key => $value) {
if (!array_key_exists($key,$default_lang)) {
unset($cur_lang[$key]);
expLang::saveCurrLangFile();
$num_extra++;
$orig_lang = LANG;
$lang_list = expLang::langList();
foreach ($lang_list as $key=>$value) {
if ($key!="English - US") {
output("Now attempting to translate new ".$key." phrases\n");
expSettings::change('LANGUAGE', $key);
exec ('php ./lang_translate.php',$output);
output($output);
unset ($output);
}
}
$num_extra = $num_extra?$num_extra:'No';
print $num_extra." Obsolete Phases were Found and Removed from the ".utf8_decode(LANG)." Translation\n";
expSettings::change('LANGUAGE', $orig_lang);

// Attempt a machine translation for un-translated phrases in current language
$num_untrans = 0;
foreach ($cur_lang as $key => $value) {
if ($key == $value) $num_untrans++;
}
print $num_untrans." Phrases appear Un-Translated in the ".utf8_decode(LANG)." Translation\n";
$num_added = 0;
if (defined('LOCALE')) {
foreach ($cur_lang as $key => $value) {
if ($key == $value) {
$translation = expLang::translate($value,'en',LOCALE);
if ($translation) {
$translation = str_replace('"', "\'", $translation); // remove the killer double-quotes
$cur_lang[$key] = addslashes(stripslashes(strip_tags($translation)));
expLang::saveCurrLangFile();
$num_added++;
}
}
print "\nCompleted Updating the Exponent Language System!\n";

function output($text) {
if (!is_array($text)) $text = array($text);
foreach ($text as $string) {
print $string."\n";
}
print $num_added." New Phases were Translated in the ".utf8_decode(LANG)." Translation\n";
} else {
print "There is no Locale Assigned for the ".utf8_decode(LANG)." to attempt a Translation\n";
exit;
}

print count($cur_lang)." Phrases are now in the ".utf8_decode(LANG)." Translation\n";
print "\nCompleted Updating the ".utf8_decode(LANG)." Translation!\n";

?>

0 comments on commit 2e3b354

Please sign in to comment.