mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Fixed distribution of textcollector files to modules (was collecting all entities into all modules before) - added unit tests
ENHANCEMENT Using ksort() in textcollector to get alphabetized language master files (=easier to compare and debug) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64494 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c4cdc9ce87
commit
12f2457677
@ -83,7 +83,7 @@ class i18nTextCollector extends Object {
|
|||||||
// Search for calls in code files if these exists
|
// Search for calls in code files if these exists
|
||||||
if(is_dir("$this->basePath/$module/code")) {
|
if(is_dir("$this->basePath/$module/code")) {
|
||||||
$fileList = $this->getFilesRecursive("$this->basePath/$module/code");
|
$fileList = $this->getFilesRecursive("$this->basePath/$module/code");
|
||||||
} else if('sapphire' == $module) {
|
} else if($module == 'sapphire') {
|
||||||
// sapphire doesn't have the usual module structure, so we'll scan all subfolders
|
// sapphire doesn't have the usual module structure, so we'll scan all subfolders
|
||||||
$fileList = $this->getFilesRecursive("$this->basePath/$module");
|
$fileList = $this->getFilesRecursive("$this->basePath/$module");
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ class i18nTextCollector extends Object {
|
|||||||
if(substr($filePath,-3) == 'php') {
|
if(substr($filePath,-3) == 'php') {
|
||||||
$content = file_get_contents($filePath);
|
$content = file_get_contents($filePath);
|
||||||
$entitiesArr = array_merge($entitiesArr,(array)$this->collectFromCode($content, $module));
|
$entitiesArr = array_merge($entitiesArr,(array)$this->collectFromCode($content, $module));
|
||||||
//$entitiesArr = array_merge($entitiesArr, (array)$this->collectFromStatics($filePath, $module));
|
$entitiesArr = array_merge($entitiesArr, (array)$this->collectFromStatics($filePath, $module));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class i18nTextCollector extends Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort for easier lookup and comparison with translated files
|
// sort for easier lookup and comparison with translated files
|
||||||
asort($entitiesArr);
|
ksort($entitiesArr);
|
||||||
|
|
||||||
return $entitiesArr;
|
return $entitiesArr;
|
||||||
}
|
}
|
||||||
@ -117,15 +117,15 @@ class i18nTextCollector extends Object {
|
|||||||
* Write the master string table of every processed module
|
* Write the master string table of every processed module
|
||||||
*/
|
*/
|
||||||
protected function writeMasterStringFile($entitiesByModule) {
|
protected function writeMasterStringFile($entitiesByModule) {
|
||||||
$php = '';
|
|
||||||
|
|
||||||
// Write each module language file
|
// Write each module language file
|
||||||
if($entitiesByModule) foreach($entitiesByModule as $module => $entities) {
|
if($entitiesByModule) foreach($entitiesByModule as $module => $entities) {
|
||||||
|
$php = '';
|
||||||
|
|
||||||
// Create folder for lang files
|
// Create folder for lang files
|
||||||
$langFolder = $this->baseSavePath . '/' . $module . '/lang';
|
$langFolder = $this->baseSavePath . '/' . $module . '/lang';
|
||||||
if(!file_exists($this->baseSavePath. '/' . $module . '/lang')) {
|
if(!file_exists($langFolder)) {
|
||||||
Filesystem::makeFolder($langFolder, Filesystem::$folder_create_mask);
|
Filesystem::makeFolder($langFolder, Filesystem::$folder_create_mask);
|
||||||
touch($this->baseSavePath. '/' . $module . '/lang/_manifest_exclude');
|
touch($langFolder . '/_manifest_exclude');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the English file and write the Master String Table
|
// Open the English file and write the Master String Table
|
||||||
@ -161,7 +161,11 @@ class i18nTextCollector extends Object {
|
|||||||
protected function getFilesRecursive($folder, &$fileList = null) {
|
protected function getFilesRecursive($folder, &$fileList = null) {
|
||||||
if(!$fileList) $fileList = array();
|
if(!$fileList) $fileList = array();
|
||||||
$items = scandir($folder);
|
$items = scandir($folder);
|
||||||
if($items) foreach($items as $item) {
|
$isValidFolder = (
|
||||||
|
!in_array('_manifest_exclude', $items)
|
||||||
|
&& !preg_match('/\/tests$/', $folder)
|
||||||
|
);
|
||||||
|
if($items && $isValidFolder) foreach($items as $item) {
|
||||||
if(substr($item,0,1) == '.') continue;
|
if(substr($item,0,1) == '.') continue;
|
||||||
if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$folder/$item";
|
if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$folder/$item";
|
||||||
else if(substr($item,-3) == '.ss') $fileList[$item] = "$folder/$item";
|
else if(substr($item,-3) == '.ss') $fileList[$item] = "$folder/$item";
|
||||||
@ -186,6 +190,8 @@ class i18nTextCollector extends Object {
|
|||||||
$content = str_replace($regs[0],"",$content);
|
$content = str_replace($regs[0],"",$content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($entitiesArr);
|
||||||
|
|
||||||
return $entitiesArr;
|
return $entitiesArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +222,8 @@ class i18nTextCollector extends Object {
|
|||||||
$content = str_replace($regs[0],"",$content);
|
$content = str_replace($regs[0],"",$content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($entitiesArr);
|
||||||
|
|
||||||
return $entitiesArr;
|
return $entitiesArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,6 +319,8 @@ class i18nTextCollector extends Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($entitiesArr);
|
||||||
|
|
||||||
return $entitiesArr;
|
return $entitiesArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
tests/i18n/_fakewebroot/_manifest_exclude
Normal file
0
tests/i18n/_fakewebroot/_manifest_exclude
Normal file
0
tests/i18n/_fakewebroot/i18nothermodule/_config.php
Normal file
0
tests/i18n/_fakewebroot/i18nothermodule/_config.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
class i18nOtherModule extends Object {
|
||||||
|
function __construct() {
|
||||||
|
_t(
|
||||||
|
'i18nOtherModule.ENTITY',
|
||||||
|
'Other Module Entity',
|
||||||
|
);
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1 @@
|
|||||||
|
<% _t('i18nOtherModule.MAINTEMPLATE',"Main Template Other Module")%>
|
@ -1 +1,2 @@
|
|||||||
<% _t('i18nTestModule.MAINTEMPLATE',"Main Template")%>
|
<% _t('i18nTestModule.MAINTEMPLATE',"Main Template")%>
|
||||||
|
lonely _t() call that should be ignored
|
@ -38,6 +38,10 @@ class i18nTextCollectorTest extends SapphireTest {
|
|||||||
$_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss'] = array(
|
$_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss'] = array(
|
||||||
'Includes' => Director::baseFolder() . $this->alternateBasePath . 'i18ntestmodule/templates/Includes/i18nTestModuleInclude.ss',
|
'Includes' => Director::baseFolder() . $this->alternateBasePath . 'i18ntestmodule/templates/Includes/i18nTestModuleInclude.ss',
|
||||||
);
|
);
|
||||||
|
$_TEMPLATE_MANIFEST['i18nTestModule.ss'] = array(
|
||||||
|
'main' => Director::baseFolder() . $this->alternateBasePath . 'i18ntestmodule/templates/i18nTestModule.ss',
|
||||||
|
'Layout' => Director::baseFolder() . $this->alternateBasePath . 'i18ntestmodule/templates/Layout/i18nTestModule.ss',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
@ -285,21 +289,14 @@ PHP;
|
|||||||
function testCollectFromIncludedTemplates() {
|
function testCollectFromIncludedTemplates() {
|
||||||
$c = new i18nTextCollector();
|
$c = new i18nTextCollector();
|
||||||
|
|
||||||
$html = <<<SS
|
$templateFilePath = $this->alternateBasePath . 'i18ntestmodule/templates/Layout/i18nTestModule.ss';
|
||||||
<% _t("MainTemplate.MAINVALUE", 'Main Value'); %>
|
$html = file_get_contents($templateFilePath);
|
||||||
<% if Bar %>
|
|
||||||
<% include i18nTextCollectorTest_Include %>
|
|
||||||
<% end_if %>
|
|
||||||
lonely _t() call that should be ignored
|
|
||||||
SS;
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$c->collectFromTemplate($html, 'mymodule', 'RandomNamespace'),
|
$c->collectFromTemplate($html, 'mymodule', 'RandomNamespace'),
|
||||||
array(
|
array(
|
||||||
'i18nTextCollectorTest_NestedInclude.ss.NESTEDINCLUDE' => array('Nested Include Value', null, null),
|
'i18nTestModule.WITHNAMESPACE' => array('Include Entity with Namespace', null, null),
|
||||||
'Test.NESTEDINCLUDEWITHNAMESPACE' => array('Nested Include Value with namespace', null, null),
|
'i18nTestModuleInclude.ss.NONAMESPACE' => array('Include Entity without Namespace', null, null),
|
||||||
'i18nTextCollectorTest_Include.ss.INCLUDENONAMESPACE' => array('Include Value', null, null),
|
'i18nTestModule.LAYOUTTEMPLATE' => array('Layout Template', null, null),
|
||||||
'Test.INCLUDEWITHNAMESPACE' => array('Include Value with namespace', null, null),
|
|
||||||
'MainTemplate.MAINVALUE' => array('Main Value', null, null),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -309,8 +306,9 @@ SS;
|
|||||||
$c->basePath = $this->alternateBasePath;
|
$c->basePath = $this->alternateBasePath;
|
||||||
$c->baseSavePath = $this->alternateBaseSavePath;
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
||||||
|
|
||||||
$c->run('i18ntestmodule');
|
$c->run();
|
||||||
|
|
||||||
|
// i18ntestmodule
|
||||||
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
|
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
file_exists($moduleLangFile),
|
file_exists($moduleLangFile),
|
||||||
@ -328,10 +326,32 @@ global \$lang;
|
|||||||
PR_LOW,
|
PR_LOW,
|
||||||
'Comment for entity'
|
'Comment for entity'
|
||||||
);
|
);
|
||||||
\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';
|
|
||||||
\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';
|
|
||||||
\$lang['en_US']['i18nTestModule']['MAINTEMPLATE'] = 'Main Template';
|
\$lang['en_US']['i18nTestModule']['MAINTEMPLATE'] = 'Main Template';
|
||||||
\$lang['en_US']['i18nTestModule']['OTHERENTITY'] = 'Other Entity';
|
\$lang['en_US']['i18nTestModule']['OTHERENTITY'] = 'Other Entity';
|
||||||
|
\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';
|
||||||
|
\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';
|
||||||
|
|
||||||
|
?>
|
||||||
|
PHP;
|
||||||
|
$this->assertEquals(
|
||||||
|
file_get_contents($moduleLangFile),
|
||||||
|
$compareContent
|
||||||
|
);
|
||||||
|
|
||||||
|
// i18nothermodule
|
||||||
|
$moduleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php';
|
||||||
|
$this->assertTrue(
|
||||||
|
file_exists($moduleLangFile),
|
||||||
|
'Master language file can be written to modules /lang folder'
|
||||||
|
);
|
||||||
|
|
||||||
|
$compareContent = <<<PHP
|
||||||
|
<?php
|
||||||
|
|
||||||
|
global \$lang;
|
||||||
|
|
||||||
|
\$lang['en_US']['i18nOtherModule']['ENTITY'] = 'Other Module Entity';
|
||||||
|
\$lang['en_US']['i18nOtherModule']['MAINTEMPLATE'] = 'Main Template Other Module';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
PHP;
|
PHP;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user