From 89b737678e1d5251763fdc2767b2ccb22604bbb1 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 15 Sep 2007 00:12:28 +0000 Subject: [PATCH] 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 --- _config.php | 5 ++++- core/Core.php | 13 +++++++++++++ core/SSViewer.php | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/_config.php b/_config.php index 6167fceb0..0e6bf6b36 100644 --- a/_config.php +++ b/_config.php @@ -53,5 +53,8 @@ Authenticator::registerAuthenticator('MemberAuthenticator'); */ Authenticator::registerAuthenticator('OpenIDAuthenticator'); - +/** + * Define a default language different than english + */ +//LocaleAPI::setLocale('ca_AD'); ?> \ No newline at end of file diff --git a/core/Core.php b/core/Core.php index 0042dd48c..e34f6e501 100755 --- a/core/Core.php +++ b/core/Core.php @@ -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); +} ?> diff --git a/core/SSViewer.php b/core/SSViewer.php index 854d78f2c..510a4fc51 100644 --- a/core/SSViewer.php +++ b/core/SSViewer.php @@ -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 +%' . '>', '', $content); $content = ereg_replace('<' . '% +end_if +%' . '>', '', $content); + // i18n + ereg('.*[\/](.*)',$template,$path); + $content = ereg_replace('<' . '% +_\(([^)]*)\) +%' . '>', '', $content); + // isnt valid html? !? $content = ereg_replace('<' . '% +base_tag +%' . '>', '', $content);