bfojcapell: LocaleAPI renamed to i18n

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41829 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-15 00:16:11 +00:00
parent bd037abcdc
commit 46be50f0a2
2 changed files with 38 additions and 42 deletions

View File

@ -88,11 +88,11 @@ function stripslashes_recursively(&$array) {
*/ */
function _($class, $entity, $string="", $priority=PR_MEDIUM, $context="") { function _($class, $entity, $string="", $priority=PR_MEDIUM, $context="") {
global $lang; global $lang;
$locale = LocaleAPI::getLocale(); $locale = i18n::getLocale();
$class = ereg_replace('.*([/\\]+)',"",$class); $class = ereg_replace('.*([/\\]+)',"",$class);
if (substr($class,-4) == '.php') $class = substr($class,0,-4); if (substr($class,-4) == '.php') $class = substr($class,0,-4);
if (!$lang[$locale][$class]) LocaleAPI::includeByClass($class); if (!$lang[$locale][$class]) i18n::includeByClass($class);
$transEntity = $lang[LocaleAPI::getLocale()][$class][$entity]; $transEntity = $lang[i18n::getLocale()][$class][$entity];
return (is_array($transEntity) ? $transEntity[0] : $transEntity); return (is_array($transEntity) ? $transEntity[0] : $transEntity);
} }
?> ?>

View File

@ -1,10 +1,6 @@
<?php <?php
define('PR_HIGH', 10); class i18n extends Controller {
define('PR_MEDIUM', 5);
class LocaleAPI extends Controller {
static $currentlocale = 'en'; static $currentlocale = 'en';
static function textCollector() { static function textCollector() {
@ -18,10 +14,10 @@ class LocaleAPI extends Controller {
if (!isset($_GET['module'])) { if (!isset($_GET['module'])) {
$topLevel = scandir($baseDir); $topLevel = scandir($baseDir);
foreach($topLevel as $module) { foreach($topLevel as $module) {
LocaleAPI::processModule($baseDir, $module); i18n::processModule($baseDir, $module);
} }
} else { } else {
LocaleAPI::processModule($baseDir, $_GET['module']); i18n::processModule($baseDir, $_GET['module']);
} }
echo "Done!"; echo "Done!";
@ -30,14 +26,14 @@ class LocaleAPI extends Controller {
private static function processModule($baseDir, $module) { private static function processModule($baseDir, $module) {
if(is_dir("$baseDir/$module") && !in_array($module, array('sapphire','jsparty','assets')) && substr($module,0,1) != '.') { if(is_dir("$baseDir/$module") && !in_array($module, array('sapphire','jsparty','assets')) && substr($module,0,1) != '.') {
LocaleAPI::getFilesRec("$baseDir/$module/code", $fileList); i18n::getFilesRec("$baseDir/$module/code", $fileList);
foreach($fileList as $index => $file) { foreach($fileList as $index => $file) {
$mst .= LocaleAPI::reportCallsCode($index, $file); $mst .= i18n::reportCallsCode($index, $file);
} }
$fileList = NULL; $fileList = NULL;
LocaleAPI::getFilesRec("$baseDir/$module/templates", $fileList); i18n::getFilesRec("$baseDir/$module/templates", $fileList);
foreach($fileList as $index => $file) { foreach($fileList as $index => $file) {
$mst .= LocaleAPI::reportCallsTpl($index, $file); $mst .= i18n::reportCallsTpl($index, $file);
} }
if ($mst) { if ($mst) {
// Create folder for lang files // Create folder for lang files
@ -65,7 +61,7 @@ class LocaleAPI extends Controller {
if(substr($item,0,1) == '.') continue; if(substr($item,0,1) == '.') continue;
if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$folder/$item"; if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$folder/$item";
else if(substr($item,-3) == '.ss') $fileList[$item] = "$folder/$item"; else if(substr($item,-3) == '.ss') $fileList[$item] = "$folder/$item";
else if(is_dir("$folder/$item")) LocaleAPI::getFilesRec("$folder/$item", $fileList); else if(is_dir("$folder/$item")) i18n::getFilesRec("$folder/$item", $fileList);
} }
} }
@ -126,10 +122,10 @@ class LocaleAPI extends Controller {
} }
static function setLocale($locale) { static function setLocale($locale) {
if ($locale) LocaleAPI::$currentlocale = $locale; if ($locale) i18n::$currentlocale = $locale;
} }
static function getLocale() { static function getLocale() {
return LocaleAPI::$currentlocale; return i18n::$currentlocale;
} }
/** /**
@ -160,11 +156,11 @@ class LocaleAPI extends Controller {
$path = $_CLASS_MANIFEST[$class]; $path = $_CLASS_MANIFEST[$class];
ereg('.*/([^/]+)/code/',$path,$module); ereg('.*/([^/]+)/code/',$path,$module);
}//die($class); }//die($class);
if (file_exists($file = Director::getAbsFile("{$module[1]}/lang/". LocaleAPI::getLocale() . '.php'))) { if (file_exists($file = Director::getAbsFile("{$module[1]}/lang/". i18n::getLocale() . '.php'))) {
include_once($file); include_once($file);
} else if (LocaleAPI::getLocale() != 'en') { } else if (i18n::getLocale() != 'en') {
LocaleAPI::setLocale('en'); i18n::setLocale('en');
LocaleAPI::includeByClass($class); i18n::includeByClass($class);
} else { } else {
user_error("Locale file $file should exist", E_USER_WARNING); user_error("Locale file $file should exist", E_USER_WARNING);
} }