本文整理汇总了PHP中Pimcore\Tool\Admin::getLanguages方法的典型用法代码示例。如果您正苦于以下问题:PHP Admin::getLanguages方法的具体用法?PHP Admin::getLanguages怎么用?PHP Admin::getLanguages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool\Admin
的用法示例。
在下文中一共展示了Admin::getLanguages方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByKeyLocalized
/**
* @param $id
* @param bool $create
* @param bool $returnIdIfEmpty
* @param null $language
* @return array
* @throws \Exception
* @throws \Zend_Exception
*/
public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null)
{
if ($user = Tool\Admin::getCurrentUser()) {
$language = $user->getLanguage();
} elseif ($user = Tool\Authentication::authenticateSession()) {
$language = $user->getLanguage();
} elseif (\Zend_Registry::isRegistered("Zend_Locale")) {
$language = (string) \Zend_Registry::get("Zend_Locale");
}
if (!in_array($language, Tool\Admin::getLanguages())) {
$config = \Pimcore\Config::getSystemConfig();
$language = $config->general->language;
}
return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language);
}
示例2: initTranslations
/**
* @param $instance
* @throws \Zend_Exception
*/
public static function initTranslations($instance)
{
$language = "en";
$locale = $instance->getLanguage();
if ($locale) {
$locale = new \Zend_Locale($locale);
foreach ([(string) $locale, $locale->getLanguage()] as $localeVariant) {
if (in_array($localeVariant, AdminTool::getLanguages())) {
$language = $localeVariant;
break;
}
}
}
//add translations to registry
$coreLanguageFile = AdminTool::getLanguageFile($language);
$translator = new \Zend_Translate('Pimcore\\Translate\\Adapter\\Json', $coreLanguageFile, $language);
$languageFile = AdminTool::getLanguageFile($language);
$translator->addTranslation($languageFile, $language);
if (\Zend_Registry::isRegistered("Zend_Locale")) {
$locale = \Zend_Registry::get("Zend_Locale");
@$translator->setLocale($locale);
}
\Zend_Registry::set("Zend_Translate", $translator);
if ($instance) {
$instance->setTranslator($translator);
}
}
示例3: initTranslations
/**
* @param $instance
* @throws \Zend_Exception
*/
public static function initTranslations($instance)
{
//add translations to registry
$coreLanguageFile = AdminTool::getLanguageFile("en");
$translator = new \Zend_Translate('Pimcore\\Translate\\Adapter\\Json', $coreLanguageFile, 'en');
$availableLanguages = AdminTool::getLanguages();
foreach ($availableLanguages as $lang) {
if ($lang != "en") {
$languageFile = AdminTool::getLanguageFile($lang);
$translator->addTranslation($languageFile, $lang);
}
}
if (\Zend_Registry::isRegistered("Zend_Locale")) {
$locale = \Zend_Registry::get("Zend_Locale");
@$translator->setLocale($locale);
}
\Zend_Registry::set("Zend_Translate", $translator);
if ($instance) {
$instance->setTranslator($translator);
}
}
示例4: getByKey
/**
* @param $id
* @param bool $create
* @param bool $returnIdIfEmpty
* @return static
* @throws \Exception
* @throws \Zend_Exception
*/
public static function getByKey($id, $create = false, $returnIdIfEmpty = false)
{
$cacheKey = "translation_" . $id;
if (\Zend_Registry::isRegistered($cacheKey)) {
return \Zend_Registry::get($cacheKey);
}
$translation = new static();
$idOriginal = $id;
$id = mb_strtolower($id);
if ($translation instanceof Model\Translation\Admin) {
$languages = Tool\Admin::getLanguages();
} else {
$languages = Tool::getValidLanguages();
}
try {
$translation->getDao()->getByKey(self::getValidTranslationKey($id));
} catch (\Exception $e) {
if (!$create) {
throw new \Exception($e->getMessage());
} else {
$translation->setKey($id);
$translation->setCreationDate(time());
$translation->setModificationDate(time());
$translations = [];
foreach ($languages as $lang) {
$translations[$lang] = "";
}
$translation->setTranslations($translations);
$translation->save();
}
}
if ($returnIdIfEmpty) {
$translations = $translation->getTranslations();
foreach ($languages as $language) {
if (!array_key_exists($language, $translations) || empty($translations[$language])) {
$translations[$language] = $idOriginal;
}
}
$translation->setTranslations($translations);
}
// add to key cache
\Zend_Registry::set($cacheKey, $translation);
return $translation;
}
示例5: getAvailableAdminLanguagesAction
public function getAvailableAdminLanguagesAction()
{
$langs = array();
$availableLanguages = Tool\Admin::getLanguages();
$locales = Tool::getSupportedLocales();
foreach ($availableLanguages as $lang) {
if (array_key_exists($lang, $locales)) {
$langs[] = array("language" => $lang, "display" => $locales[$lang]);
}
}
$this->_helper->json($langs);
}
示例6: addAdminTranslationKeysAction
public function addAdminTranslationKeysAction()
{
$this->removeViewRenderer();
$keys = $this->getParam("keys");
if ($keys) {
$availableLanguages = Tool\Admin::getLanguages();
$data = \Zend_Json_Decoder::decode($keys);
foreach ($data as $translationData) {
$t = null;
// reset
try {
$t = Translation\Admin::getByKey($translationData);
} catch (\Exception $e) {
\Logger::log($e);
}
if (!$t instanceof Translation\Admin) {
$t = new Translation\Admin();
$t->setKey($translationData);
$t->setCreationDate(time());
$t->setModificationDate(time());
foreach ($availableLanguages as $lang) {
$t->addTranslation($lang, "");
}
try {
$t->save();
} catch (\Exception $e) {
\Logger::log($e);
}
}
}
}
}
示例7: installAdminTranslations
public function installAdminTranslations()
{
$csv = PIMCORE_PLUGINS_PATH . '/Toolbox/install/translations/data.csv';
Admin::importTranslationsFromFile($csv, true, \Pimcore\Tool\Admin::getLanguages());
}