bfojcapell: better i18n support and more flexibility allowed in templates. Also fixed some possible warnings in 2.02rc1 if more than one language file is found with the same name. ManifestBuilder? now skips language files - they cannot be autoloaded and they are already loaded on demand, so no need to be in the manifest

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41913 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-15 20:06:42 +00:00
parent f2dc279789
commit 408c8d63d5
5 changed files with 20 additions and 15 deletions

View File

@ -62,7 +62,7 @@ Authenticator::registerAuthenticator('OpenIDAuthenticator');
/**
* Define a default language different than english
*/
//LocaleAPI::set_locale('ca_AD');
//i18n::set_locale('ca_AD');
define('MCE_ROOT', 'jsparty/tiny_mce2/');

View File

@ -83,6 +83,13 @@ function stripslashes_recursively(&$array) {
}
}
/**
* Priorities definition. These constants are used in calls to _t() as an optional argument
*/
define('PR_HIGH',100);
define('PR_MEDIUM',50);
define('PR_LOW',10);
/**
* This is the main translator function. Returns the string defined by $class and $entity according to the currently set locale
*

View File

@ -184,6 +184,9 @@ class ManifestBuilder {
// ignore certain directories
if(is_dir("$folder/$item") && in_array($item, self::$ignore_folders)) continue;
// i18n: ignore language files (loaded on demand)
if($item == 'lang' && is_dir("$folder/$item") && ereg_replace("/[^/]+/\\.\\.","",$folder.'/..') == Director::baseFolder()) continue;
if(is_dir("$folder/$item")) {
// recurse into directories (if not in $ignore_folders)

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);
@ -186,7 +186,7 @@ class SSViewer extends Object {
$itemStack = array();
$val = "";
include($cacheFile);
$output = $val;
@ -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(
@ -282,7 +282,8 @@ class SSViewer extends Object {
$content = ereg_replace('<' . '% +end_if +%' . '>', '<? } ?>', $content);
// i18n
$content = ereg_replace('<' . '% +_t\((([^)]|\)[^;])*)\); +%' . '>', '<?= _t(\\1) ?>', $content);
ereg('.*[\/](.*)',$template,$path);
$content = ereg_replace('<' . '% +_t\((\'([^\']*)\'|"([^"]*)")(([^)]|\)[^;])*)\); +%' . '>', '<?= _t(\''. $path[1] . '.\\2\\3\'\\4) ?>', $content);
// </base> isnt valid html? !?
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);

View File

@ -6,13 +6,6 @@
* @author Bernat Foj Capell <bernat@silverstripe.com>
*/
/**
* Priorities definition. These constants are used in calls to _() as an optional argument
*/
define('PR_HIGH',100);
define('PR_MEDIUM',50);
define('PR_LOW',10);
class i18n extends Controller {
/**
@ -118,6 +111,7 @@ class i18n extends Controller {
if (isset($callMap[$class.'--'.$entity])) echo "Warning! Redeclaring entity $entity in file $file<br>";
if (substr($regs[2],0,1) == '"') $regs[2] = addcslashes($regs[2],'\'');
$mst .= '$lang[\'en_US\'][\'' . $class . '\'][\'' . $entity . '\'] = ';
if ($regs[5]) {
$mst .= "array(\n\t'" . substr($regs[2],1,-1) . "',\n\t" . substr($regs[5],1);
@ -148,11 +142,11 @@ class i18n extends Controller {
static $callMap;
$content = file_get_contents($file);
$mst = '';
while (ereg('_t[[:space:]]*\([[:space:]]*("[^,]*"|\\\'[^,]*\\\')[[:space:]]*,[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\')([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*\)',$content,$regs)) {
while (ereg('_t[[:space:]]*\([[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\')([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*\)',$content,$regs)) {
$entityParts = explode('.',substr($regs[1],1,-1));
$entity = array_pop($entityParts);
// Entity redeclaration check
if (isset($callMap[$index.'--'.$entity])) echo "Warning! Redeclaring entity $entity in file $file<br>";
@ -165,7 +159,7 @@ class i18n extends Controller {
$mst .= ",\n\t'" . substr($regs[6],2,-1) . '\'';
}
$mst .= "\n);";
} else $mst .= '\'' . substr($regs[2],2,-1) . '\';';
} else $mst .= '\'' . substr($regs[2],1,-1) . '\';';
$mst .= "\n";
$content = str_replace($regs[0],"",$content);