$kk) self::loadFile($path); } /** * Gets the locale. * * @return string The locale with 2 digits format */ static function get() { return self::$locale; } /** * Gets the translation of a string, if no translation is found the same * string is returned. * * @param string $stringId The string to translate * @return string The translated string */ static function getString($stringId) { if (isset(self::$strings[$stringId])) return self::$strings[$stringId]; else return $stringId; } /** * Adds a path where a JSON file with translations is located. * * @param string $path The JSON file path */ static function addPath($path) { self::$paths[$path] = TRUE; if (self::$localeSet) self::loadFile($path); } /** * Loads translations from a JSON file. * * @param string $path The JSON file path */ static function loadFile($path) { $locale = self::$locale; $file = stream_resolve_include_path("$path/locale/$locale.json"); if (file_exists($file) &&($jsonString = file_get_contents($file))) self::addTranslations(json_decode($jsonString, TRUE)); } /** * Adds a set of translations to the database. * * @param array $strings Associative array of every string and its * translation */ static function addTranslations($strings) { foreach ($strings as $string => &$translation) self::$strings[$string] = &$translation; } } }