From 7f2f0472851a85848949f261a40d2d9bde5d66b9 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 13 Dec 2008 20:35:05 +0000 Subject: [PATCH] BUGFIX Including all translated language tables by default in i18n::_t() instead of selectively including modules based on filename. This caused bugs where entities were located in language tables in a different module than their filepath would suggest. Example: Page.SINGULARNAME is stored in sapphire/lang/en_US.php, while Page.php is stored in mysite/Page.php git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68751 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/i18n.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/i18n.php b/core/i18n.php index 26054f5c8..ee444241e 100755 --- a/core/i18n.php +++ b/core/i18n.php @@ -811,12 +811,22 @@ class i18n extends Object { */ static function _t($entity, $string = "", $priority = 40, $context = "") { global $lang; + + // get current locale (either default or user preference) $locale = i18n::get_locale(); + + // parse $entity into its parts $entityParts = explode('.',$entity); $realEntity = array_pop($entityParts); $class = implode('.',$entityParts); - if(!isset($lang[$locale][$class])) i18n::include_by_class($class); + + // if language table isn't loaded for this locale, get it for each of the modules + if(!isset($lang[$locale])) i18n::include_by_locale($locale); + + // fallback to the passed $string if no translation is present $transEntity = isset($lang[$locale][$class][$realEntity]) ? $lang[$locale][$class][$realEntity] : $string; + + // entities can be stored in both array and literal values in the language tables return (is_array($transEntity) ? $transEntity[0] : $transEntity); }