/** * Get project config */ public function loadconfigAction() { $this->_checkLoaded(); $config = $this->_getProject()->getConfig(); if (isset($config['files']) && !empty($config['files'])) { foreach ($config['files'] as &$item) { $item = array('file' => $item); } unset($item); } else { $config['files'] = array(); } if (isset($config['langs']) && !empty($config['langs'])) { foreach ($config['langs'] as &$item) { $item = array('name' => $item); } unset($item); } else { $config['langs'] = array(); } $locManager = new Backend_Localization_Manager($this->_configMain); $langs = $locManager->getLangs(false); $paths = array(); foreach ($langs as $k => $v) { $pos = strpos($v, '/'); if (strpos($v, '/') === false) { continue; } $path = substr($v, $pos + 1); if (!isset($paths[$path])) { $paths[$path] = array('name' => $path); } } $config['langsList'] = array_values($paths); Response::jsonSuccess($config); }
/** * Create sub dictionary */ public function createsubAction() { $name = Request::post('name', Filter::FILTER_ALPHANUM, false); if (empty($name)) { Response::jsonError($this->_lang->get('INVALID_VALUE_FOR_FIELD') . ' ' . $this->_lang->get('DICTIONARY_NAME')); } if ($this->_manager->dictionaryExists($name)) { Response::jsonError($this->_lang->get('DICTIONARY_EXISTS')); } try { $this->_manager->createDictionary($name); } catch (Exception $e) { Response::jsonError($e->getMessage()); } Response::jsonSuccess(); }
/** * Compile JS Lang file (used current lang) * @return void */ public function langAction() { $langPath = $this->_configMain->get('lang_path'); $jsPath = $this->_configMain->get('js_lang_path'); $lManager = new Backend_Localization_Manager($this->_configMain); $langs = $lManager->getLangs(false); foreach ($langs as $lang) { $langFile = $langPath . $lang . '.php'; $name = $lang; $dictionary = Config::factory(Config::File_Array, $langFile, false); Lang::addDictionary($name, $dictionary); $filePath = $jsPath . $lang . '.js'; $dir = dirname($lang); if (!empty($dir) && $dir !== '.' && !is_dir($jsPath . '/' . $dir)) { mkdir($jsPath . '/' . $dir, 0755, true); } if (strpos($name, '/') === false) { $varName = 'appLang'; } else { $varName = basename($name) . 'Lang'; } if (!@file_put_contents($filePath, 'var ' . $varName . ' = ' . Lang::lang($name)->getJsObject() . ';')) { Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $filePath); } } Response::jsonSuccess(); }