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:
Ingo Schommer 2007-09-15 00:12:28 +00:00
parent d75537eb1c
commit 89b737678e
3 changed files with 23 additions and 3 deletions

View File

@ -53,5 +53,8 @@ Authenticator::registerAuthenticator('MemberAuthenticator');
*/
Authenticator::registerAuthenticator('OpenIDAuthenticator');
/**
* Define a default language different than english
*/
//LocaleAPI::setLocale('ca_AD');
?>

View File

@ -82,4 +82,17 @@ function stripslashes_recursively(&$array) {
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);
}
?>

View File

@ -154,7 +154,7 @@ class SSViewer extends Object {
if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process - compile", " for $template");
$content = file_get_contents($template);
$content = SSViewer::parseTemplateContent($content);
$content = SSViewer::parseTemplateContent($content, $template);
$fh = fopen($cacheFile,'w');
fwrite($fh, $content);
@ -199,7 +199,7 @@ class SSViewer extends Object {
return $output;
}
static function parseTemplateContent($content) {
static function parseTemplateContent($content, $template="") {
while(true) {
$oldContent = $content;
$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('<' . '% +end_if +%' . '>', '<? } ?>', $content);
// i18n
ereg('.*[\/](.*)',$template,$path);
$content = ereg_replace('<' . '% +_\(([^)]*)\) +%' . '>', '<?= _(\''.$path[1].'\',\\1) ?>', $content);
// </base> isnt valid html? !?
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);