mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
bfojcapell: sapphire changes to allow i18n
(merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41827 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d75537eb1c
commit
89b737678e
@ -53,5 +53,8 @@ Authenticator::registerAuthenticator('MemberAuthenticator');
|
|||||||
*/
|
*/
|
||||||
Authenticator::registerAuthenticator('OpenIDAuthenticator');
|
Authenticator::registerAuthenticator('OpenIDAuthenticator');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define a default language different than english
|
||||||
|
*/
|
||||||
|
//LocaleAPI::setLocale('ca_AD');
|
||||||
?>
|
?>
|
@ -82,4 +82,17 @@ function stripslashes_recursively(&$array) {
|
|||||||
else $array[$k] = stripslashes($v);
|
else $array[$k] = stripslashes($v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the main translator function. Returns the string defined by $class and $entity according to the currently set locale
|
||||||
|
*/
|
||||||
|
function _($class, $entity, $string="", $priority=PR_MEDIUM, $context="") {
|
||||||
|
global $lang;
|
||||||
|
$locale = LocaleAPI::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];
|
||||||
|
return (is_array($transEntity) ? $transEntity[0] : $transEntity);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -154,7 +154,7 @@ class SSViewer extends Object {
|
|||||||
if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process - compile", " for $template");
|
if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process - compile", " for $template");
|
||||||
|
|
||||||
$content = file_get_contents($template);
|
$content = file_get_contents($template);
|
||||||
$content = SSViewer::parseTemplateContent($content);
|
$content = SSViewer::parseTemplateContent($content, $template);
|
||||||
|
|
||||||
$fh = fopen($cacheFile,'w');
|
$fh = fopen($cacheFile,'w');
|
||||||
fwrite($fh, $content);
|
fwrite($fh, $content);
|
||||||
@ -199,7 +199,7 @@ class SSViewer extends Object {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function parseTemplateContent($content) {
|
static function parseTemplateContent($content, $template="") {
|
||||||
while(true) {
|
while(true) {
|
||||||
$oldContent = $content;
|
$oldContent = $content;
|
||||||
$content = preg_replace_callback('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', create_function(
|
$content = preg_replace_callback('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', create_function(
|
||||||
@ -281,6 +281,10 @@ class SSViewer extends Object {
|
|||||||
$content = ereg_replace('<' . '% +else +%' . '>', '<? } else { ?>', $content);
|
$content = ereg_replace('<' . '% +else +%' . '>', '<? } else { ?>', $content);
|
||||||
$content = ereg_replace('<' . '% +end_if +%' . '>', '<? } ?>', $content);
|
$content = ereg_replace('<' . '% +end_if +%' . '>', '<? } ?>', $content);
|
||||||
|
|
||||||
|
// i18n
|
||||||
|
ereg('.*[\/](.*)',$template,$path);
|
||||||
|
$content = ereg_replace('<' . '% +_\(([^)]*)\) +%' . '>', '<?= _(\''.$path[1].'\',\\1) ?>', $content);
|
||||||
|
|
||||||
// </base> isnt valid html? !?
|
// </base> isnt valid html? !?
|
||||||
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);
|
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user