本文整理汇总了PHP中JLanguage类的典型用法代码示例。如果您正苦于以下问题:PHP JLanguage类的具体用法?PHP JLanguage怎么用?PHP JLanguage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: switchAdminLanguage
/**
* Task to switch the administrator language.
*
* @return void
*/
public function switchAdminLanguage()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$cid = $this->input->get('cid', '');
$model = $this->getModel('installed');
// Fetching the language name from the xx-XX.xml
$file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml';
$info = JInstaller::parseXMLInstallFile($file);
$languageName = $info['name'];
if ($model->switchAdminLanguage($cid)) {
// Switching to the new language for the message
$language = JFactory::getLanguage();
$newLang = JLanguage::getInstance($cid);
JFactory::$language = $newLang;
JFactory::getApplication()->loadLanguage($language = $newLang);
$newLang->load('com_languages', JPATH_ADMINISTRATOR);
$msg = JText::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName);
$type = 'message';
} else {
$msg = $model->getError();
$type = 'error';
}
$this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type);
}
示例2: getInput
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
$thisid = $this->id;
$values = $this->value;
$class = $this->class;
$languages = JLanguageHelper::getLanguages();
foreach ($languages as $lang) {
$language = new JLanguage($lang->lang_code);
$this->class = $class . ($language->isRTL() ? ' rtl' : ' ltr');
$this->element['label'] = $lang->title;
$this->name = 'jform[' . $this->fieldname . '][' . $lang->lang_code . ']';
$this->id = $thisid . '_' . $lang->lang_code;
$this->value = array_key_exists($lang->lang_code, $values) ? $values[$lang->lang_code] : '';
$html[] = '<div class="control-group">';
$html[] = '<div class="control-label">';
$html[] = parent::getLabel();
$html[] = '</div>';
$html[] = '<div class="controls">';
$html[] = parent::getInput();
$html[] = '</div>';
$html[] = '</div>';
}
return implode($html);
}
示例3: testGetPaths
/**
* @todo Implement testGetPaths().
*/
public function testGetPaths()
{
$extension1 = '';
$extension2 = 'com_sobi2';
$extension3 = 'joomla';
$lang = new JLanguage('');
// extension = joomla, returns array with language path
$this->assertNotNull($lang->getPaths($extension3));
// No call parameter, returns array with language path
$this->assertNotNull($lang->getPaths());
}
示例4: getItems
/**
* Gets menu items by attribute
*
* @param string $attributes The field name
* @param string $values The value of the field
* @param boolean $firstonly If true, only returns the first item found
*
* @return array
*
* @since 1.6
*/
public function getItems($attributes, $values, $firstonly = false)
{
$attributes = (array) $attributes;
$values = (array) $values;
if ($this->app->isSite()) {
// Filter by language if not set
if (($key = array_search('language', $attributes)) === false) {
if (JLanguageMultilang::isEnabled()) {
$attributes[] = 'language';
$values[] = array($this->language->getTag(), '*');
}
} elseif ($values[$key] === null) {
unset($attributes[$key]);
unset($values[$key]);
}
// Filter by access level if not set
if (($key = array_search('access', $attributes)) === false) {
$attributes[] = 'access';
$values[] = $this->user->getAuthorisedViewLevels();
} elseif ($values[$key] === null) {
unset($attributes[$key]);
unset($values[$key]);
}
}
// Reset arrays or we get a notice if some values were unset
$attributes = array_values($attributes);
$values = array_values($values);
return parent::getItems($attributes, $values, $firstonly);
}
示例5: initialise
/**
* Initialise the application.
*
* @access public
*/
function initialise( $options = array())
{
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language']))
{
$user = & JFactory::getUser();
$lang = $user->getParam( 'language' );
// Make sure that the user's language exists
if ( $lang && JLanguage::exists($lang) ) {
$options['language'] = $lang;
}
else
{
$params = JComponentHelper::getParams('com_extensions');
$client =& JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get('language_'.$client->name, 'en-GB');
}
}
// One last check to make sure we have something
if ( ! JLanguage::exists($options['language']) ) {
$options['language'] = 'en-GB';
}
parent::initialise($options);
}
示例6: listslanguagesType
function listslanguagesType()
{
jimport('joomla.filesystem.folder');
$path = JLanguage::getLanguagePath(JPATH_ROOT);
$dirs = JFolder::folders($path);
$this->languages = array();
foreach ($dirs as $dir) {
if (strlen($dir) != 5 || $dir == "xx-XX") {
continue;
}
$xmlFiles = JFolder::files($path . DS . $dir, '^([-_A-Za-z]*)\\.xml$');
$xmlFile = reset($xmlFiles);
if (empty($xmlFile)) {
continue;
}
$data = JApplicationHelper::parseXMLLangMetaFile($path . DS . $dir . DS . $xmlFile);
$oneLanguage = new stdClass();
$oneLanguage->language = strtolower($dir);
$oneLanguage->name = empty($data['name']) ? $dir : $data['name'];
$this->languages[] = $oneLanguage;
}
if (count($this->languages) < 2) {
return;
}
$this->multipleLang = true;
$this->choice = array();
$this->choice[] = JHTML::_('select.option', 'all', JText::_('ACY_ALL'));
$this->choice[] = JHTML::_('select.option', 'special', JText::_('ACY_CUSTOM'));
$js = "function updateLanguages(){\n\t\t\tchoice = eval('document.adminForm.choice_languages');\n\t\t\tchoiceValue = 'special';\n\t\t\tfor (var i=0; i < choice.length; i++){\n\t\t\t\t if (choice[i].checked){\n\t\t\t\t\t choiceValue = choice[i].value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thiddenVar = document.getElementById('hidden_languages');\n\t\t\tif(choiceValue != 'special'){\n\t\t\t\thiddenVar.value = choiceValue;\n\t\t\t\tdocument.getElementById('div_languages').style.display = 'none';\n\t\t\t}else{\n\t\t\t\tdocument.getElementById('div_languages').style.display = 'block';\n\t\t\t\tspecialVar = eval('document.adminForm.special_languages');\n\t\t\t\tfinalValue = '';\n\t\t\t\tfor (var i=0; i < specialVar.length; i++){\n\t\t\t\t\tif (specialVar[i].checked){\n\t\t\t\t\t\t\t finalValue += specialVar[i].value+',';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thiddenVar.value = finalValue;\n\t\t\t}\n\n\t\t}";
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
}
示例7: getItem
public function getItem($id = 'en-GB', $refresh = false, $emptyState = true)
{
if (empty($this->_item)) {
$lang = JLanguage::getInstance($id);
// Load only site language (Email language costants should be only there)
$lang->load('com_citruscart', JPATH_ADMINISTRATOR, $id, true);
$temp_paths = $lang->getPaths('com_citruscart');
foreach ($temp_paths as $p => $k) {
$path = $p;
}
$result = new JObject();
$result->name = $lang->getName();
$result->code = $lang->getTag();
$result->path = $path;
$result->strings = array();
// Load File and Take only the constants that contains "EMAIL_"
$file = new DSCParameter();
$file->loadFile($path);
$strings = $file->toArray();
$result_strings = array();
foreach ($strings as $k => $v) {
// Only if it is a prefix!
if (stripos($k, $this->email_prefix) === 0) {
$result_strings[$k] = $v;
}
}
$result->strings = array('file' => $path, 'strings' => $result_strings);
JFactory::getApplication()->triggerEvent('onPrepare' . $this->getTable()->get('_suffix'), array(&$result));
$this->_item = $result;
}
return $this->_item;
}
示例8: convertLng
function convertLng($data)
{
session_cache_expire(1800000);
$path = JLanguage::getLanguagePath(JPATH_COMPONENT_ADMINISTRATOR) . DS . $data['lng'] . DS . '*.ini';
$dirs = glob($path);
foreach ($dirs as $file) {
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=" . basename($file));
header("Pragma: no-cache");
header("Expires: 0");
$arr = file($file);
foreach ($arr as $line) {
$line = str_replace('"', "'", $line);
// dmp($line);
$ex = explode("=", $line);
// dmp($ex);
if (count($ex) > 1) {
echo $ex[0] . "=";
if (count($ex) > 2) {
unset($ex[0]);
$str = '"' . implode("=", $ex);
$str = str_replace("\r\n", "\"\r\n", $str);
echo $str;
} else {
$str = '"' . $ex[1];
$str = str_replace("\r\n", "\"\r\n", $str);
echo $str;
}
}
}
}
}
示例9: getList
public static function getList(&$params)
{
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages();
$db = JFactory::getDBO();
$app = JFactory::getApplication();
$query = $db->getQuery(true);
$query->select('id');
$query->select('language');
$query->from($db->nameQuote('#__menu'));
$query->where('home=1');
$db->setQuery($query);
$homes = $db->loadObjectList('language');
foreach ($languages as $i => &$language) {
// Do not display language without frontend UI
if (!JLanguage::exists($language->lang_code)) {
unset($languages[$i]);
} elseif (!isset($homes[$language->lang_code])) {
unset($languages[$i]);
} else {
if ($app->getLanguageFilter()) {
$language->active = $language->lang_code == $lang->getTag();
if ($app->getCfg('sef') == '1') {
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef;
}
} else {
$language->link = 'index.php';
}
}
}
return $languages;
}
示例10: initialise
/**
* Initialise the application.
*
* @param array An optional associative array of configuration settings.
*/
function initialise($options = array())
{
$config =& JFactory::getConfig();
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language'])) {
$user =& JFactory::getUser();
$lang = $user->getParam('admin_language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$params = JComponentHelper::getParams('com_languages');
$client =& JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->getValue('config.language', 'en-GB'));
}
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->getValue('config.language', 'en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$options['language'] = 'en-GB';
// as a last ditch fail to english
}
}
parent::initialise($options);
}
示例11: getInput
/**
* Method to get the field input.
*
* @return string The field input.
*/
protected function getInput()
{
$attributes = '';
if ($v = (string) $this->element['onchange']) {
$attributes .= ' onchange="' . $v . '"';
}
$params = JComponentHelper::getParams('com_localise');
$reference = $params->get('reference', 'en-GB');
$admin = JLanguage::getKnownLanguages(LOCALISEPATH_ADMINISTRATOR);
$site = JLanguage::getKnownLanguages(LOCALISEPATH_SITE);
if (JFolder::exists(LOCALISEPATH_INSTALLATION)) {
$install = JLanguage::getKnownLanguages(LOCALISEPATH_INSTALLATION);
} else {
$install = array();
}
$languages = array_merge($admin, $site, $install);
$attributes .= ' class="' . (string) $this->element['class'] . ($this->value == $reference ? ' iconlist-16-reference"' : '"');
foreach ($languages as $i => $language) {
$languages[$i] = JArrayHelper::toObject($language);
}
JArrayHelper::sortObjects($languages, 'name');
$options = array();
foreach ($this->element->children() as $option) {
$options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => ''));
}
foreach ($languages as $language) {
$options[] = JHtml::_('select.option', $language->tag, $language->name, array('option.attr' => 'attributes', 'attr' => 'class="' . ($language->tag == $reference ? 'iconlist-16-reference" title="' . JText::_('COM_LOCALISE_TOOLTIP_FIELD_LANGUAGE_REFERENCE') . '"' : '"')));
}
$return = JHtml::_('select.genericlist', $options, $this->name, array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes));
return $return;
}
示例12: setFile
/**
*
*
*
*/
protected function setFile()
{
$params = JComponentHelper::getParams('com_languages');
$frontend_lang = $params->get('site', 'en-GB');
$language = JLanguage::getInstance($frontend_lang);
// get language file for edit
$language = JFactory::getLanguage();
$language->load('com_jdownloads');
$lang_file = JLanguage::getLanguagePath(JPATH_SITE);
$lang_file .= DS . $frontend_lang . DS . $frontend_lang . '.com_jdownloads.ini';
@chmod($lang_file, 0755);
clearstatcache();
if (is_writable($lang_file) == false) {
$language_writable = false;
} else {
$language_writable = true;
}
if ($language_writable) {
$f = fopen($lang_file, "r");
$language_text = fread($f, filesize($lang_file));
$this->languagetext = htmlspecialchars($language_text);
} else {
$this->languagetext = '';
}
$this->languagefile = $lang_file;
$this->languagefile_writable = $language_writable;
}
示例13: language
function language()
{
$this->setLayout('default');
$code = JRequest::getString('code');
if (empty($code)) {
acymailing::display('Code not specified', 'error');
return;
}
$file = null;
$file->name = $code;
$path = JLanguage::getLanguagePath(JPATH_ROOT) . DS . $code . DS . $code . '.com_acymailing.ini';
$file->path = $path;
jimport('joomla.filesystem.file');
$showLatest = true;
$loadLatest = false;
if (JFile::exists($path)) {
$file->content = JFile::read($path);
if (empty($file->content)) {
acymailing::display('File not found : ' . $path, 'error');
}
} else {
$loadLatest = true;
acymailing::display(JText::_('LOAD_ENGLISH_1') . '<br/>' . JText::_('LOAD_ENGLISH_2') . '<br/>' . JText::_('LOAD_ENGLISH_3'), 'info');
$file->content = JFile::read(JLanguage::getLanguagePath(JPATH_ROOT) . DS . 'en-GB' . DS . 'en-GB.com_acymailing.ini');
}
if ($loadLatest or JRequest::getString('task') == 'latest') {
$doc =& JFactory::getDocument();
$doc->addScript(ACYMAILING_UPDATEURL . 'languageload&code=' . JRequest::getString('code'));
$showLatest = false;
} elseif (JRequest::getString('task') == 'save') {
$showLatest = false;
}
$this->assignRef('showLatest', $showLatest);
$this->assignRef('file', $file);
}
示例14: parseLang
public function parseLang($vars)
{
if (Mijosef::getConfig()->multilang == 0) {
return;
}
if (empty($vars['lang'])) {
$lang = JRequest::getWord('lang', '');
if (empty($lang)) {
return;
}
$vars['lang'] = $lang;
}
$languages = JLanguageHelper::getLanguages('sef');
$lang_code = $languages[$vars['lang']]->lang_code;
// if current language, don't bother
if ($lang_code == JFactory::getLanguage()->getTag()) {
//self::checkHomepage($vars['lang']);
return;
}
// Create a cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie(JUtility::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
// set the request var
JRequest::setVar('language', $lang_code);
// set current language
jimport('joomla.language.language');
$conf = JFactory::getConfig();
$debug = $conf->get('debug_lang');
$lang = JLanguage::getInstance($lang_code, $debug);
JFactory::$language = $lang;
self::$_lang = $vars['lang'];
}
示例15: initialise
/**
* Initialise the application.
*
* @param array $options An optional associative array of configuration settings.
*
* @return void
* @since 1.5
*/
public function initialise($options = array())
{
$config = JFactory::getConfig();
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language'])) {
$user = JFactory::getUser();
$lang = $user->getParam('admin_language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$params = JComponentHelper::getParams('com_languages');
$client = JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->get('language', 'es-LA'));
}
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->get('language', 'es-LA');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$options['language'] = 'es-LA';
// as a last ditch fail to english
}
}
// Execute the parent initialise method.
parent::initialise($options);
// Load Library language
$lang = JFactory::getLanguage();
$lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, true);
}