diff --git a/src/Pluf.php b/src/Pluf.php index 62b3e3f..2b3a1ee 100644 --- a/src/Pluf.php +++ b/src/Pluf.php @@ -40,6 +40,7 @@ class Pluf $GLOBALS['_PX_starttime'] = microtime(true); $GLOBALS['_PX_uniqid'] = uniqid($GLOBALS['_PX_starttime'], true); $GLOBALS['_PX_signal'] = array(); + $GLOBALS['_PX_locale'] = array(); Pluf::loadConfig($config); date_default_timezone_set(Pluf::f('time_zone', 'Europe/Berlin')); mb_internal_encoding(Pluf::f('encoding', 'UTF-8')); diff --git a/src/Pluf/Middleware/Translation.php b/src/Pluf/Middleware/Translation.php index 8d5ce09..a48cf1a 100644 --- a/src/Pluf/Middleware/Translation.php +++ b/src/Pluf/Middleware/Translation.php @@ -58,14 +58,7 @@ class Pluf_Middleware_Translation // will default to 'en' $lang = Pluf_Translation::getAcceptedLanguage(Pluf::f('languages', array('en'))); } - $GLOBALS['_PX_current_locale'] = $lang; - $GLOBALS['_PX_locale'] = array(); - $GLOBALS['_PX_locale'][$lang] = array(); - foreach (Pluf::f('installed_apps') as $app) { - if (false != ($pofile=Pluf::fileExists($app.'/locale/'.$lang.'/'.strtolower($app).'.po'))) { - $GLOBALS['_PX_locale'][$lang] += Pluf_Translation::readPoFile($pofile); - } - } + Pluf_Translation::loadSetLocale($lang); $request->language_code = $lang; return false; } diff --git a/src/Pluf/Translation.php b/src/Pluf/Translation.php index a4ab431..8e2ede9 100644 --- a/src/Pluf/Translation.php +++ b/src/Pluf/Translation.php @@ -52,6 +52,25 @@ class Pluf_Translation 'de' => 'plural_2not1', ); + public static function loadSetLocale($lang) + { + $GLOBALS['_PX_current_locale'] = $lang; + if (isset($GLOBALS['_PX_locale'][$lang])) { + return; // We consider that it was already loaded. + } + $GLOBALS['_PX_locale'][$lang] = array(); + foreach (Pluf::f('installed_apps') as $app) { + if (false != ($pofile=Pluf::fileExists($app.'/locale/'.$lang.'/'.strtolower($app).'.po'))) { + $GLOBALS['_PX_locale'][$lang] += Pluf_Translation::readPoFile($pofile); + } + } + } + + public static function getLocale() + { + return $GLOBALS['_PX_current_locale']; + } + /** * Get the plural form for a given locale. */