本文整理汇总了PHP中Piwik\Translate::mergeTranslationArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Translate::mergeTranslationArray方法的具体用法?PHP Translate::mergeTranslationArray怎么用?PHP Translate::mergeTranslationArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Translate
的用法示例。
在下文中一共展示了Translate::mergeTranslationArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadTranslation
/**
* Load translation
*
* @param Plugin $plugin
* @param string $langCode
* @throws \Exception
* @return bool whether the translation was found and loaded
*/
private function loadTranslation($plugin, $langCode)
{
// we are in Tracker mode if Loader is not (yet) loaded
if (SettingsServer::isTrackerApiRequest()) {
return false;
}
if (is_string($plugin)) {
$pluginName = $plugin;
} else {
$pluginName = $plugin->getPluginName();
}
$path = self::getPluginsDirectory() . $pluginName . '/lang/%s.json';
$defaultLangPath = sprintf($path, $langCode);
$defaultEnglishLangPath = sprintf($path, 'en');
$translationsLoaded = false;
// merge in english translations as default first
if (file_exists($defaultEnglishLangPath)) {
$translations = $this->getTranslationsFromFile($defaultEnglishLangPath);
$translationsLoaded = true;
if (isset($translations[$pluginName])) {
// only merge translations of plugin - prevents overwritten strings
Translate::mergeTranslationArray(array($pluginName => $translations[$pluginName]));
}
}
// merge in specific language translations (to overwrite english defaults)
if (!empty($langCode) && $defaultEnglishLangPath != $defaultLangPath && file_exists($defaultLangPath)) {
$translations = $this->getTranslationsFromFile($defaultLangPath);
$translationsLoaded = true;
if (isset($translations[$pluginName])) {
// only merge translations of plugin - prevents overwritten strings
Translate::mergeTranslationArray(array($pluginName => $translations[$pluginName]));
}
}
return $translationsLoaded;
}