Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update language (command-line) scripts so now the 'lang_update.php' s…
…cript runs to automate the entire process. Must be run from the cron folder (it's not that smart)
- Loading branch information
Showing
3 changed files
with
108 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
|
||
?> |