From eb45e6ec6d5fcde2e77c3f86126594bfef04e01a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 25 Sep 2007 22:14:48 +0000 Subject: [PATCH] added $default_locale and get_translatable_modules() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42578 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/i18n.php | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/core/i18n.php b/core/i18n.php index f84ad5599..4ff5fc39d 100755 --- a/core/i18n.php +++ b/core/i18n.php @@ -12,6 +12,13 @@ class i18n extends Controller { * This static variable is used to store the current defined locale. Default value is 'en_US' */ static $currentlocale = 'en_US'; + + /** + * This is the locale in which generated language files are (we assume US English) + * + * @var string + */ + static $default_locale = 'en_US'; /** * An exhaustive list of possible locales (code => language and country) @@ -743,7 +750,7 @@ class i18n extends Controller { */ static function get_locale_name($code) { $langs = i18n::get_locale_list(); - return $langs[$code]; + return isset($langs[$code]) ? $langs[$code] : false; } /** @@ -757,6 +764,30 @@ class i18n extends Controller { return ($code ? $code : $name); } + /** + * Searches the root-directory for module-directories + * (identified by having a _config.php on their first directory-level + * and a language-file with the default locale in the /lang-subdirectory). + * + * @return array + */ + static function get_translatable_modules() { + $translatableModules = array(); + + $baseDir = Director::baseFolder(); + $modules = scandir($baseDir); + foreach($modules as $module) { + $moduleDir = $baseDir . DIRECTORY_SEPARATOR . $module; + if( + is_dir($moduleDir) + && is_file($moduleDir . DIRECTORY_SEPARATOR . "_config.php") + && is_file($moduleDir . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . i18n::$default_locale . ".php") + ) { + $translatableModules[] = $module; + } + } + return $translatableModules; + } /** * Searches for all the files in a given module @@ -1010,11 +1041,7 @@ class i18n extends Controller { } echo "Done!"; - - } - } - ?> \ No newline at end of file