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
This commit is contained in:
Ingo Schommer 2008-12-13 20:35:05 +00:00 committed by Sam Minnee
parent 70e4faf63f
commit 7f2f047285

View File

@ -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);
}