Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX Ensuring that every locale (and its lang part) are registered …

…as languages in i18n::include_by_locale() to avoid expensive re-parsing on subsequent i18n::_t() calls to the same locale
  • Loading branch information...
commit 0e0e5dd07af632d11e11541a30c8dca33a20789c 1 parent bd23a07
Ingo Schommer chillu authored
Showing with 19 additions and 4 deletions.
  1. +19 −4 i18n/i18n.php
23 i18n/i18n.php
View
@@ -1460,16 +1460,19 @@ public static function get_time_format() {
* @return string The translated string, according to the currently set locale {@link i18n::set_locale()}
*/
static function _t($entity, $string = "", $priority = 40, $context = "") {
+ // get current locale (either default or user preference)
+ $locale = i18n::get_locale();
+ $lang = i18n::get_lang_from_locale($locale);
+
foreach(self::get_translators() as $priority => $translators) {
foreach($translators as $name => $translator) {
$adapter = $translator->getAdapter();
-
- // get current locale (either default or user preference)
- $locale = i18n::get_locale();
$adapter->setLocale($locale);
// if language table isn't loaded for this locale, get it for each of the modules
- if(!$adapter->isAvailable($locale)) i18n::include_by_locale($locale);
+ if(!$adapter->isAvailable($locale) && !$adapter->isAvailable($lang)) {
+ i18n::include_by_locale($locale);
+ }
$translation = $adapter->translate($entity, $locale);
@@ -1927,6 +1930,18 @@ static function include_by_locale($locale) {
}
}
}
+
+ // Add empty translations to ensure the locales are "registered" with isAvailable(),
+ // and the next invocation of include_by_locale() doesn't cause a new reparse.
+ foreach($selectedLocales as $selectedLocale) {
+ $adapter->addTranslation(
+ array(
+ 'content' => array('_' => '_'),
+ 'locale' => $selectedLocale,
+ 'usetranslateadapter' => true
+ )
+ );
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.