translated string ) */ static public function loadTranslation($lang) { $translations = array(); $path = self::getTranslationPath($lang); if (!is_readable($path)) { throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($lang))); } require $path; return $translations; } /** * Output translations to string * * @param array $translations Array of translations ( key => translated string ) * @return string */ static public function outputTranslation($translations) { if (!self::$baseTranslation) { self::$baseTranslation = self::loadTranslation('en'); } $en = self::$baseTranslation; $output = array(' $en_translation) { if (isset($translations[$key]) && !empty($translations[$key])) { $tmp = self::quote($translations[$key]); $output[] = "\t'$key' => $tmp,"; } } /* write the remaining translations (that don't exist in en.php) */ foreach ($translations as $key => $translation) { if (!isset($en[$key]) && !empty($translation)) { $tmp = self::quote($translation); $deferoutput[] = "\t'$key' => $tmp,"; } } if (count($deferoutput) > 0) { $output[] = "\n\t// FOR REVIEW"; $output = array_merge($output, $deferoutput); } $output[] = ');'; return implode($output, "\n") . "\n"; } /** * Save translations to file; translations should already be cleansed. * * @param array $translations Array of translations ( key => translated string ) * @param string $destinationPath Path of file to save translations to * @return bool|int False if failure, or number of bytes written */ static public function saveTranslation($translations, $destinationPath) { return file_put_contents($destinationPath, self::outputTranslation($translations)); } }