mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
f2dc279789
commit
408c8d63d5
@ -62,7 +62,7 @@ Authenticator::registerAuthenticator('OpenIDAuthenticator');
|
|||||||
/**
|
/**
|
||||||
* Define a default language different than english
|
* Define a default language different than english
|
||||||
*/
|
*/
|
||||||
//LocaleAPI::set_locale('ca_AD');
|
//i18n::set_locale('ca_AD');
|
||||||
|
|
||||||
define('MCE_ROOT', 'jsparty/tiny_mce2/');
|
define('MCE_ROOT', 'jsparty/tiny_mce2/');
|
||||||
|
|
||||||
|
@ -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
|
* This is the main translator function. Returns the string defined by $class and $entity according to the currently set locale
|
||||||
*
|
*
|
||||||
|
@ -184,6 +184,9 @@ class ManifestBuilder {
|
|||||||
|
|
||||||
// ignore certain directories
|
// ignore certain directories
|
||||||
if(is_dir("$folder/$item") && in_array($item, self::$ignore_folders)) continue;
|
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")) {
|
if(is_dir("$folder/$item")) {
|
||||||
// recurse into directories (if not in $ignore_folders)
|
// recurse into directories (if not in $ignore_folders)
|
||||||
|
@ -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);
|
||||||
@ -186,7 +186,7 @@ class SSViewer extends Object {
|
|||||||
|
|
||||||
$itemStack = array();
|
$itemStack = array();
|
||||||
$val = "";
|
$val = "";
|
||||||
|
|
||||||
include($cacheFile);
|
include($cacheFile);
|
||||||
|
|
||||||
$output = $val;
|
$output = $val;
|
||||||
@ -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(
|
||||||
@ -282,7 +282,8 @@ class SSViewer extends Object {
|
|||||||
$content = ereg_replace('<' . '% +end_if +%' . '>', '<? } ?>', $content);
|
$content = ereg_replace('<' . '% +end_if +%' . '>', '<? } ?>', $content);
|
||||||
|
|
||||||
// i18n
|
// 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? !?
|
// </base> isnt valid html? !?
|
||||||
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);
|
$content = ereg_replace('<' . '% +base_tag +%' . '>', '<base href="<?= Director::absoluteBaseURL(); ?>" />', $content);
|
||||||
|
@ -6,13 +6,6 @@
|
|||||||
* @author Bernat Foj Capell <bernat@silverstripe.com>
|
* @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 {
|
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 (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 . '\'] = ';
|
$mst .= '$lang[\'en_US\'][\'' . $class . '\'][\'' . $entity . '\'] = ';
|
||||||
if ($regs[5]) {
|
if ($regs[5]) {
|
||||||
$mst .= "array(\n\t'" . substr($regs[2],1,-1) . "',\n\t" . substr($regs[5],1);
|
$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;
|
static $callMap;
|
||||||
$content = file_get_contents($file);
|
$content = file_get_contents($file);
|
||||||
$mst = '';
|
$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));
|
$entityParts = explode('.',substr($regs[1],1,-1));
|
||||||
$entity = array_pop($entityParts);
|
$entity = array_pop($entityParts);
|
||||||
|
|
||||||
// Entity redeclaration check
|
// Entity redeclaration check
|
||||||
if (isset($callMap[$index.'--'.$entity])) echo "Warning! Redeclaring entity $entity in file $file<br>";
|
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\t'" . substr($regs[6],2,-1) . '\'';
|
||||||
}
|
}
|
||||||
$mst .= "\n);";
|
$mst .= "\n);";
|
||||||
} else $mst .= '\'' . substr($regs[2],2,-1) . '\';';
|
} else $mst .= '\'' . substr($regs[2],1,-1) . '\';';
|
||||||
$mst .= "\n";
|
$mst .= "\n";
|
||||||
$content = str_replace($regs[0],"",$content);
|
$content = str_replace($regs[0],"",$content);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user