mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
bd037abcdc
commit
46be50f0a2
@ -88,11 +88,11 @@ function stripslashes_recursively(&$array) {
|
||||
*/
|
||||
function _($class, $entity, $string="", $priority=PR_MEDIUM, $context="") {
|
||||
global $lang;
|
||||
$locale = LocaleAPI::getLocale();
|
||||
$locale = i18n::getLocale();
|
||||
$class = ereg_replace('.*([/\\]+)',"",$class);
|
||||
if (substr($class,-4) == '.php') $class = substr($class,0,-4);
|
||||
if (!$lang[$locale][$class]) LocaleAPI::includeByClass($class);
|
||||
$transEntity = $lang[LocaleAPI::getLocale()][$class][$entity];
|
||||
if (!$lang[$locale][$class]) i18n::includeByClass($class);
|
||||
$transEntity = $lang[i18n::getLocale()][$class][$entity];
|
||||
return (is_array($transEntity) ? $transEntity[0] : $transEntity);
|
||||
}
|
||||
?>
|
||||
|
@ -1,10 +1,6 @@
|
||||
<?php
|
||||
|
||||
define('PR_HIGH', 10);
|
||||
define('PR_MEDIUM', 5);
|
||||
|
||||
|
||||
class LocaleAPI extends Controller {
|
||||
class i18n extends Controller {
|
||||
static $currentlocale = 'en';
|
||||
|
||||
static function textCollector() {
|
||||
@ -18,10 +14,10 @@ class LocaleAPI extends Controller {
|
||||
if (!isset($_GET['module'])) {
|
||||
$topLevel = scandir($baseDir);
|
||||
foreach($topLevel as $module) {
|
||||
LocaleAPI::processModule($baseDir, $module);
|
||||
i18n::processModule($baseDir, $module);
|
||||
}
|
||||
} else {
|
||||
LocaleAPI::processModule($baseDir, $_GET['module']);
|
||||
i18n::processModule($baseDir, $_GET['module']);
|
||||
}
|
||||
|
||||
echo "Done!";
|
||||
@ -30,14 +26,14 @@ class LocaleAPI extends Controller {
|
||||
|
||||
private static function processModule($baseDir, $module) {
|
||||
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) {
|
||||
$mst .= LocaleAPI::reportCallsCode($index, $file);
|
||||
$mst .= i18n::reportCallsCode($index, $file);
|
||||
}
|
||||
$fileList = NULL;
|
||||
LocaleAPI::getFilesRec("$baseDir/$module/templates", $fileList);
|
||||
i18n::getFilesRec("$baseDir/$module/templates", $fileList);
|
||||
foreach($fileList as $index => $file) {
|
||||
$mst .= LocaleAPI::reportCallsTpl($index, $file);
|
||||
$mst .= i18n::reportCallsTpl($index, $file);
|
||||
}
|
||||
if ($mst) {
|
||||
// Create folder for lang files
|
||||
@ -65,7 +61,7 @@ class LocaleAPI extends Controller {
|
||||
if(substr($item,0,1) == '.') continue;
|
||||
if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$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) {
|
||||
if ($locale) LocaleAPI::$currentlocale = $locale;
|
||||
if ($locale) i18n::$currentlocale = $locale;
|
||||
}
|
||||
static function getLocale() {
|
||||
return LocaleAPI::$currentlocale;
|
||||
return i18n::$currentlocale;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,11 +156,11 @@ class LocaleAPI extends Controller {
|
||||
$path = $_CLASS_MANIFEST[$class];
|
||||
ereg('.*/([^/]+)/code/',$path,$module);
|
||||
}//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);
|
||||
} else if (LocaleAPI::getLocale() != 'en') {
|
||||
LocaleAPI::setLocale('en');
|
||||
LocaleAPI::includeByClass($class);
|
||||
} else if (i18n::getLocale() != 'en') {
|
||||
i18n::setLocale('en');
|
||||
i18n::includeByClass($class);
|
||||
} else {
|
||||
user_error("Locale file $file should exist", E_USER_WARNING);
|
||||
}
|
Loading…
Reference in New Issue
Block a user