/** * This method tries to return the translated value of a text key. * If this key is not existing, the key is returned with the language, * in which the key should exist, as prefix and with question marks surrounding it. */ public static function getTranslatedValue($key) { // if there is no language stored yet, use the default language $language = isset($_SESSION[Session::LANGUAGE]) ? $_SESSION[Session::LANGUAGE] : Config::DEFAULT_LANGUAGE; if (!self::isLoaded()) { self::loadTranslations(); } // first, lookup whether the key is in the product-specific translations $prefix = "product."; if (substr($key, 0, strlen($prefix)) === $prefix) { if (array_key_exists($key, $_SESSION[Session::PRODUCT_TRANSLATIONS])) { return $_SESSION[Session::PRODUCT_TRANSLATIONS][$key]; } return self::formatMissingKey($key, $language); } // ok, it was not... so lookup for the general key translations. // if the language is not in the stored keypairs, return the key with the unknown language as prefix if (!array_key_exists($language, $_SESSION[Session::TRANSLATIONS])) { return LanguageHelper::formatMissingKey($key, $language); } // if the key is not set in the stored keypairs, return the key if (!array_key_exists($key, $_SESSION[Session::TRANSLATIONS][$language])) { return LanguageHelper::formatMissingKey($key, $language); } // return the translated key return $_SESSION[Session::TRANSLATIONS][$language][$key]; }