mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
mlanthaler: Added the needed constants *PR_HIGH* and *PR_MEDIUM* so that the new "testing" code doesn't break all our builds..
(merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41828 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
89b737678e
commit
bd037abcdc
@ -1,12 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
define('PR_HIGH', 10);
|
||||||
|
define('PR_MEDIUM', 5);
|
||||||
|
|
||||||
|
|
||||||
class LocaleAPI extends Controller {
|
class LocaleAPI extends Controller {
|
||||||
static $currentlocale = 'en';
|
static $currentlocale = 'en';
|
||||||
|
|
||||||
static function textCollector() {
|
static function textCollector() {
|
||||||
|
|
||||||
echo "Collecting text...<br /><br />";
|
echo "Collecting text...<br /><br />";
|
||||||
|
|
||||||
//Calculate base directory
|
//Calculate base directory
|
||||||
$baseDir = Director::baseFolder();
|
$baseDir = Director::baseFolder();
|
||||||
|
|
||||||
@ -19,12 +23,12 @@ class LocaleAPI extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
LocaleAPI::processModule($baseDir, $_GET['module']);
|
LocaleAPI::processModule($baseDir, $_GET['module']);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Done!";
|
echo "Done!";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function processModule($baseDir, $module) {
|
private static function processModule($baseDir, $module) {
|
||||||
if(is_dir("$baseDir/$module") && !in_array($module, array('sapphire','jsparty','assets')) && substr($module,0,1) != '.') {
|
if(is_dir("$baseDir/$module") && !in_array($module, array('sapphire','jsparty','assets')) && substr($module,0,1) != '.') {
|
||||||
LocaleAPI::getFilesRec("$baseDir/$module/code", $fileList);
|
LocaleAPI::getFilesRec("$baseDir/$module/code", $fileList);
|
||||||
foreach($fileList as $index => $file) {
|
foreach($fileList as $index => $file) {
|
||||||
@ -41,13 +45,13 @@ class LocaleAPI extends Controller {
|
|||||||
if(!file_exists($baseDir. '/' . $module . '/lang')) {
|
if(!file_exists($baseDir. '/' . $module . '/lang')) {
|
||||||
mkdir($langFolder);
|
mkdir($langFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the English file and write the Master String Table
|
// Open the English file and write the Master String Table
|
||||||
if($fh = fopen($langFolder . '/en.php', "w")) {
|
if($fh = fopen($langFolder . '/en.php', "w")) {
|
||||||
fwrite($fh, "<?php\n\nglobal \$lang;\n\n" . $mst . "\n?>");
|
fwrite($fh, "<?php\n\nglobal \$lang;\n\n" . $mst . "\n?>");
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
echo "Created file: $langFolder/en.php<br />";
|
echo "Created file: $langFolder/en.php<br />";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
die("Cannot write language file! Please check permissions of $langFolder/en.php");
|
die("Cannot write language file! Please check permissions of $langFolder/en.php");
|
||||||
}
|
}
|
||||||
@ -64,9 +68,9 @@ class LocaleAPI extends Controller {
|
|||||||
else if(is_dir("$folder/$item")) LocaleAPI::getFilesRec("$folder/$item", $fileList);
|
else if(is_dir("$folder/$item")) LocaleAPI::getFilesRec("$folder/$item", $fileList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for calls to the underscore function and build our MST
|
* Look for calls to the underscore function and build our MST
|
||||||
*/
|
*/
|
||||||
private static function reportCallsCode($index, $file) {
|
private static function reportCallsCode($index, $file) {
|
||||||
static $callMap;
|
static $callMap;
|
||||||
@ -75,13 +79,13 @@ class LocaleAPI extends Controller {
|
|||||||
|
|
||||||
$class = ($regs[1] == '__FILE__' ? $index : $regs[1]);
|
$class = ($regs[1] == '__FILE__' ? $index : $regs[1]);
|
||||||
$entity = substr($regs[2],2,-1);
|
$entity = substr($regs[2],2,-1);
|
||||||
|
|
||||||
if ($callMap[$class.'--'.$entity]) echo "Warning! Redeclaring entity $entity in file $file<br>";
|
if ($callMap[$class.'--'.$entity]) echo "Warning! Redeclaring entity $entity in file $file<br>";
|
||||||
|
|
||||||
$mst .= '$lang[\'en\'][\'' . $class . '\'][\'' . substr($regs[2],2,-1) . '\'] = ';
|
$mst .= '$lang[\'en\'][\'' . $class . '\'][\'' . substr($regs[2],2,-1) . '\'] = ';
|
||||||
if ($regs[4]) {
|
if ($regs[4]) {
|
||||||
$mst .= "array(\n\t'" . substr($regs[3],2,-1) . "',\n\t" . substr($regs[4],1);
|
$mst .= "array(\n\t'" . substr($regs[3],2,-1) . "',\n\t" . substr($regs[4],1);
|
||||||
if ($regs[5]) $mst .= ",\n\t'" . substr($regs[5],2,-1) . '\'';
|
if ($regs[5]) $mst .= ",\n\t'" . substr($regs[5],2,-1) . '\'';
|
||||||
$mst .= "\n);";
|
$mst .= "\n);";
|
||||||
} else $mst .= '\'' . substr($regs[3],2,-1) . '\';';
|
} else $mst .= '\'' . substr($regs[3],2,-1) . '\';';
|
||||||
$mst .= "\n";
|
$mst .= "\n";
|
||||||
@ -89,12 +93,12 @@ class LocaleAPI extends Controller {
|
|||||||
|
|
||||||
$callMap[$class.'--'.$entity] = $regs[3];
|
$callMap[$class.'--'.$entity] = $regs[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mst;
|
return $mst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for calls to the underscore function and build our MST
|
* Look for calls to the underscore function and build our MST
|
||||||
* Template version - no "class" argument
|
* Template version - no "class" argument
|
||||||
*/
|
*/
|
||||||
private static function reportCallsTpl($index, $file) {
|
private static function reportCallsTpl($index, $file) {
|
||||||
@ -103,13 +107,13 @@ class LocaleAPI extends Controller {
|
|||||||
while (ereg('_\(([^$][^,"\']*|"[^,]*"|\'[^,]*\')(,[^$][^,)]*)(,[^,)]*)?(,[^)]*)?\)',$content,$regs)) {
|
while (ereg('_\(([^$][^,"\']*|"[^,]*"|\'[^,]*\')(,[^$][^,)]*)(,[^,)]*)?(,[^)]*)?\)',$content,$regs)) {
|
||||||
|
|
||||||
$entity = substr($regs[1],2,-1);
|
$entity = substr($regs[1],2,-1);
|
||||||
|
|
||||||
if ($callMap[$index.'--'.$entity]) echo "Warning! Redeclaring entity $entity in file $file<br>";
|
if ($callMap[$index.'--'.$entity]) echo "Warning! Redeclaring entity $entity in file $file<br>";
|
||||||
|
|
||||||
$mst .= '$lang[\'en\'][\'' . $index . '\'][\'' . substr($regs[1],1,-1) . '\'] = ';
|
$mst .= '$lang[\'en\'][\'' . $index . '\'][\'' . substr($regs[1],1,-1) . '\'] = ';
|
||||||
if ($regs[3]) {
|
if ($regs[3]) {
|
||||||
$mst .= "array(\n\t'" . substr($regs[2],2,-1) . "',\n\t" . substr($regs[3],1);
|
$mst .= "array(\n\t'" . substr($regs[2],2,-1) . "',\n\t" . substr($regs[3],1);
|
||||||
if ($regs[4]) $mst .= ",\n\t'" . substr($regs[4],2,-1) . '\'';
|
if ($regs[4]) $mst .= ",\n\t'" . substr($regs[4],2,-1) . '\'';
|
||||||
$mst .= "\n);";
|
$mst .= "\n);";
|
||||||
} else $mst .= '\'' . substr($regs[2],2,-1) . '\';';
|
} else $mst .= '\'' . substr($regs[2],2,-1) . '\';';
|
||||||
$mst .= "\n";
|
$mst .= "\n";
|
||||||
@ -117,7 +121,7 @@ class LocaleAPI extends Controller {
|
|||||||
|
|
||||||
$callMap[$index.'--'.$entity] = $regs[3];
|
$callMap[$index.'--'.$entity] = $regs[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mst;
|
return $mst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,19 +131,19 @@ class LocaleAPI extends Controller {
|
|||||||
static function getLocale() {
|
static function getLocale() {
|
||||||
return LocaleAPI::$currentlocale;
|
return LocaleAPI::$currentlocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Includes all available language files for a certain defined locale
|
* Includes all available language files for a certain defined locale
|
||||||
*/
|
*/
|
||||||
static function includeByLocale($locale) {
|
static function includeByLocale($locale) {
|
||||||
$topLevel = scandir(Director::baseFolder());
|
$topLevel = scandir(Director::baseFolder());
|
||||||
foreach($topLevel as $module) {
|
foreach($topLevel as $module) {
|
||||||
if (file_exists($file = Director::getAbsFile("$module/lang/$locale.php"))) {
|
if (file_exists($file = Director::getAbsFile("$module/lang/$locale.php"))) {
|
||||||
include_once($file);
|
include_once($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a class name (a "locale namespace"), will search for its module and, if available,
|
* Given a class name (a "locale namespace"), will search for its module and, if available,
|
||||||
* will load the resources for the currently defined locale.
|
* will load the resources for the currently defined locale.
|
||||||
|
Loading…
Reference in New Issue
Block a user