/** * This is the main method to build the master string tables with the original strings. * It will search for existent modules that use the i18n feature, parse the _t() calls * and write the resultant files in the lang folder of each module. * * @uses DataObject->collectI18nStatics() */ public function run($request) { increase_time_limit_to(); $c = new i18nTextCollector($request->getVar('locale')); $writer = $request->getVar('writer'); if ($writer) { $c->setWriter(new $writer()); } $restrictModules = $request->getVar('module') ? explode(',', $request->getVar('module')) : null; return $c->run($restrictModules, (bool) $request->getVar('merge')); }
function testCollectFromFilesystemAndWriteMasterTables() { $defaultlocal = i18n::default_locale(); $local = i18n::get_locale(); i18n::set_locale('en_US'); //set the locale to the US locale expected in the asserts i18n::set_default_locale('en_US'); $c = new i18nTextCollector(); $c->setWriter(new i18nTextCollector_Writer_Php()); $c->basePath = $this->alternateBasePath; $c->baseSavePath = $this->alternateBaseSavePath; $c->run(); // i18ntestmodule $moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php'; $this->assertTrue( file_exists($moduleLangFile), 'Master language file can be written to modules /lang folder' ); $moduleLangFileContent = file_get_contents($moduleLangFile); $this->assertContains( "\$lang['en']['i18nTestModule']['ADDITION'] = 'Addition';", $moduleLangFileContent ); $this->assertContains( "\$lang['en']['i18nTestModule']['ENTITY'] = array ( 0 => 'Entity with \"Double Quotes\"', 1 => 'Comment for entity', );", $moduleLangFileContent ); $this->assertContains( "\$lang['en']['i18nTestModule']['MAINTEMPLATE'] = 'Main Template';", $moduleLangFileContent ); $this->assertContains( "\$lang['en']['i18nTestModule']['OTHERENTITY'] = 'Other Entity';", $moduleLangFileContent ); $this->assertContains( "\$lang['en']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';", $moduleLangFileContent ); $this->assertContains( "\$lang['en']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';", $moduleLangFileContent ); // i18nothermodule $otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php'; $this->assertTrue( file_exists($otherModuleLangFile), 'Master language file can be written to modules /lang folder' ); $otherModuleLangFileContent = file_get_contents($otherModuleLangFile); $this->assertContains( "\$lang['en']['i18nOtherModule']['ENTITY'] = 'Other Module Entity';", $otherModuleLangFileContent ); $this->assertContains( "\$lang['en']['i18nOtherModule']['MAINTEMPLATE'] = 'Main Template Other Module';", $otherModuleLangFileContent ); // testtheme1 $theme1LangFile = "{$this->alternateBaseSavePath}/themes/testtheme1/lang/" . $c->getDefaultLocale() . '.php'; $this->assertTrue( file_exists($theme1LangFile), 'Master theme language file can be written to themes/testtheme1 /lang folder' ); $theme1LangFileContent = file_get_contents($theme1LangFile); $this->assertContains( "\$lang['en']['i18nTestTheme1']['MAINTEMPLATE'] = 'Theme1 Main Template';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1']['LAYOUTTEMPLATE'] = 'Theme1 Layout Template';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1']['SPRINTFNAMESPACE'] = 'Theme1 My replacement: %s';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1.ss']['LAYOUTTEMPLATENONAMESPACE'] = 'Theme1 Layout Template no namespace';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1.ss']['SPRINTFNONAMESPACE'] = 'Theme1 My replacement no namespace: %s';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1Include']['SPRINTFINCLUDENAMESPACE'] = 'Theme1 My include replacement: %s';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1Include']['WITHNAMESPACE'] = 'Theme1 Include Entity with Namespace';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1Include.ss']['NONAMESPACE'] = 'Theme1 Include Entity without Namespace';", $theme1LangFileContent ); $this->assertContains( "\$lang['en']['i18nTestTheme1Include.ss']['SPRINTFINCLUDENONAMESPACE'] = 'Theme1 My include replacement no namespace: %s';", $theme1LangFileContent ); // testtheme2 $theme2LangFile = "{$this->alternateBaseSavePath}/themes/testtheme2/lang/" . $c->getDefaultLocale() . '.php'; $this->assertTrue( file_exists($theme2LangFile), 'Master theme language file can be written to themes/testtheme2 /lang folder' ); $theme2LangFileContent = file_get_contents($theme2LangFile); $this->assertContains( "\$lang['en']['i18nTestTheme2']['MAINTEMPLATE'] = 'Theme2 Main Template';", $theme2LangFileContent ); i18n::set_locale($local); //set the locale to the US locale expected in the asserts + i18n::set_default_locale($defaultlocal); }