本文整理匯總了PHP中JLanguage::getKnownLanguages方法的典型用法代碼示例。如果您正苦於以下問題:PHP JLanguage::getKnownLanguages方法的具體用法?PHP JLanguage::getKnownLanguages怎麽用?PHP JLanguage::getKnownLanguages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JLanguage
的用法示例。
在下文中一共展示了JLanguage::getKnownLanguages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: detectLanguage
/**
* Tries to detect the language.
*
* @return string locale
* @since 1.5
*/
public static function detectLanguage()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$systemLangs = JLanguage::getKnownLanguages();
$browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($browserLangs as $browserLang) {
// slice out the part before ; on first step, the part before - on second, place into array
$browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
$primary_browserLang = substr($browserLang, 0, 2);
foreach ($systemLangs as $systemLang => $metadata) {
// take off 3 letters iso code languages as they can't match browsers' languages and default them to en
$Jinstall_lang = $metadata['tag'];
if (strlen($Jinstall_lang) < 6) {
if (strtolower($browserLang) == strtolower(substr($metadata['tag'], 0, strlen($browserLang)))) {
return $systemLang;
} else {
if ($primary_browserLang == substr($metadata['tag'], 0, 2)) {
$primaryDetectedLang = $systemLang;
}
}
}
}
if (isset($primaryDetectedLang)) {
return $primaryDetectedLang;
}
}
}
return 'en-GB';
}
示例2: 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;
}
示例3: getOptions
function getOptions()
{
$languages = JLanguage::getKnownLanguages();
$fields = array();
foreach ($languages as $language) {
$options[] = JHtml::_('select.option', strtolower($language['tag']), $language['name'] . ' (' . strtolower($language['tag'] . ')'));
}
return $options;
}
示例4: zipLiveTemplate
public function zipLiveTemplate(&$model)
{
jimport('joomla.filesystem.archive');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
$item =& $model->getItem();
$item->name = strtolower($item->name);
//Create TempFolders
if (JFolder::exists($model->getTempPath(true))) {
JFolder::delete($model->getTempPath(true));
}
JFolder::create($model->getTempPath());
//Copy the template
if (JFolder::exists(JPATH_SITE . DS . 'templates' . DS . $item->name)) {
JFolder::copy(JPATH_SITE . DS . 'templates' . DS . $item->name, $model->getTempPath(), '', true);
} elseif (JFolder::exists(JPATH_ADMINISTRATOR . DS . 'templates' . DS . $item->name)) {
JFolder::copy(JPATH_ADMINISTRATOR . DS . 'templates' . DS . $item->name, $model->getTempPath(), '', true);
} else {
JFolder::delete($model->getTempPath());
return -2;
}
//Create Language Folders
if (!JFolder::exists($model->getTempPath() . DS . 'language')) {
JFolder::create($model->getTempPath() . DS . 'language');
}
//Find Language Files
$langs_site = JLanguage::getKnownLanguages(JPATH_SITE);
$langs_admin = JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR);
$langfiles_site = array();
$langfiles_admin = array();
foreach ($langs_site as $lang) {
$langfiles_site = array_merge(JFolder::files(JPATH_SITE . DS . 'language' . DS . $lang['tag'], $item->name, true, true), $langfiles_site);
}
foreach ($langs_admin as $lang) {
$langfiles_admin = array_merge(JFolder::files(JPATH_ADMINISTRATOR . DS . 'language' . DS . $lang['tag'], $item->name, true, true), $langfiles_admin);
}
//Copy Language Files
if (count($langfiles_site)) {
foreach ($langfiles_site as $file) {
JFile::copy($file, $model->getTempPath() . DS . 'language' . DS . JFile::getName($file));
}
}
if (count($langfiles_admin)) {
foreach ($langfiles_admin as $file) {
JFile::copy($file, $model->getTempPath() . DS . 'language' . DS . JFile::getName($file));
}
}
$model->readinFiles();
$model->buildArchiveContent();
//create archive
$model->createArchive();
//delete tmp folder
if (JFolder::exists(JPATH_SITE . DS . 'tmp' . DS . 'jctmp')) {
JFolder::delete(JPATH_SITE . DS . 'tmp' . DS . 'jctmp');
}
}
示例5: buildComponent
public function buildComponent($component)
{
$sides = ['admin', 'site'];
$languages = array_keys(\JLanguage::getKnownLanguages());
foreach ($sides as $side) {
$strings = $this->getStrings($side, $component);
foreach ($languages as $lang) {
$this->saveStrings($strings, $component, $lang, $side);
}
}
}
示例6: isFrontpage
function isFrontpage()
{
// get all known languages
$languages = JLanguage::getKnownLanguages();
$menu = JSite::getMenu();
foreach ($languages as $lang) {
if ($menu->getActive() == $menu->getDefault($lang['tag'])) {
return true;
}
}
return false;
}
示例7: getOptions
public function getOptions()
{
jimport('joomla.utilities.arrayhelper');
$languages = JLanguage::getKnownLanguages(JPATH_ROOT);
foreach ($languages as $index => $language) {
$language['value'] = $language['tag'];
$language['title'] = $language['name'];
$languages[$index] = JArrayHelper::toObject($language);
}
$this->options = $languages;
return $this->options;
}
示例8: fetchElement
function fetchElement($name, $value, &$node, $control_name)
{
$languages = JLanguage::getKnownLanguages();
$fields = array();
$i = 0;
foreach ($languages as $language) {
$fields[$i]['value'] = strtolower($language['tag']);
$fields[$i]['text'] = $language['name'] . ' (' . $fields[$i]['value'] . ')';
$i++;
}
//$class = 'multiple="true" size="10" ';
$class = '';
return JHTML::_('select.genericlist', $fields, $control_name . '[' . $name . ']', $class, 'value', 'text', $value, $control_name . $name);
}
示例9: getInput
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$html = '';
$langs = JLanguage::getKnownLanguages(JPATH_SITE);
JFactory::getDocument()->addScript(JUri::root() . 'administrator/components/com_dzproduct/assets/js/multilang.js');
$html .= '<div id="' . $this->id . '" class="form-horizontal field_multilang">';
foreach ($langs as $lang) {
$id = $this->id . '_' . $lang['tag'];
$html .= '<div class="input-prepend">';
$html .= '<span class="add-on">' . $lang['tag'] . '</span>';
$html .= '<input id="' . $id . '" type="text" data-lang="' . $lang['tag'] . '" class="field_child"/>';
$html .= '</div>';
$html .= '<br /><br />';
}
$html .= '<input type="hidden" name="' . $this->name . '" class="field_root" value=\'' . $this->value . '\'/>';
$html .= '</div>';
return $html;
}
示例10: onContentPrepareForm
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
* @since 2.5
*/
public function onContentPrepareForm($form, $data)
{
// Check we have a form
if (!$form instanceof JForm) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
$app = JFactory::getApplication();
if ($form->getName() != 'com_plugins.plugin' || isset($data->name) && $data->name != 'plg_system_languagecode' || empty($data) && !$app->getUserState('plg_system_language_code.edit')) {
return true;
}
// Mark the plugin as being edited
$app->setUserState('plg_system_language_code.edit', $data->name == 'plg_system_languagecode');
// Get site languages
$languages = JLanguage::getKnownLanguages(JPATH_SITE);
// Inject fields into the form
foreach ($languages as $tag => $language) {
$form->load('
<form>
<fields name="params">
<fieldset
name="languagecode"
label="PLG_SYSTEM_LANGUAGECODE_FIELDSET_LABEL"
description="PLG_SYSTEM_LANGUAGECODE_FIELDSET_DESC"
>
<field
name="' . strtolower($tag) . '"
type="text"
description="' . htmlspecialchars(JText::sprintf('PLG_SYSTEM_LANGUAGECODE_FIELD_DESC', $language['name']), ENT_COMPAT, 'UTF-8') . '"
translate_description="false"
label="' . $tag . '"
translate_label="false"
size="7"
filter="cmd"
/>
</fieldset>
</fields>
</form>
');
}
return true;
}
示例11: getOptions
/**
* Method to get the field input.
*
* @return string The field input.
*/
protected function getOptions()
{
$admin = JLanguage::getKnownLanguages(LOCALISEPATH_ADMINISTRATOR);
$site = JLanguage::getKnownLanguages(LOCALISEPATH_SITE);
if (JFolder::exists(LOCALISEPATH_INSTALLATION)) {
$installation = JLanguage::getKnownLanguages(LOCALISEPATH_INSTALLATION);
$languages = array_intersect_key($admin, $site, $installation);
} else {
$languages = array_intersect_key($admin, $site);
}
foreach ($languages as $i => $language) {
$languages[$i] = JArrayHelper::toObject($language);
}
JArrayHelper::sortObjects($languages, 'name');
$options = parent::getOptions();
foreach ($languages as $language) {
$options[] = JHtml::_('select.option', $language->tag, $language->name);
}
return $options;
}
示例12: getData
/**
* Get the necessary data for our stats report
*
* @return array
*/
public function getData()
{
$data = array();
$db = JFactory::getDbo();
$data['php'] = phpversion();
$data['mysql'] = $db->getVersion() . ' ' . $db->name;
$data['domain'] = Juri::root();
$data['joomla'] = JVERSION;
$data['os'] = php_uname();
$data['server'] = $_SERVER['SERVER_SOFTWARE'] . ' ' . (function_exists('php_sapi_name') ? php_sapi_name() : '');
$data['language'] = implode(',', array_keys(JLanguage::getKnownLanguages(JPATH_BASE)));
$data['timezone'] = JFactory::getConfig()->get('offset');
$data['extension'] = $this->extension;
$data['version'] = CompojoomComponentHelper::getManifest($this->extension)->get('version');
$data['config'] = $this->getConfig();
$customData = $this->getCustomExtensionData();
if ($customData) {
$data = array_merge($data, $customData);
}
return $data;
}
示例13: detectLanguage
/**
* Tries to detect the language
*
* @access public
* @return string locale
* @since 1.5
*/
function detectLanguage()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$systemLangs = JLanguage::getKnownLanguages();
$browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($browserLangs as $browserLang) {
// slice out the part before ; on first step, the part before - on second, place into array
$browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
$primary_browserLang = substr($browserLang, 0, 2);
foreach ($systemLangs as $systemLang => $metadata) {
if (strtolower($browserLang) == strtolower(substr($metadata['tag'], 0, strlen($browserLang)))) {
return $systemLang;
} elseif ($primary_browserLang == substr($metadata['tag'], 0, 2)) {
$primaryDetectedLang = $systemLang;
}
}
if (isset($primaryDetectedLang)) {
return $primaryDetectedLang;
}
}
}
return 'en-GB';
}
示例14: testGetKnownLanguages
/**
* Test...
*
* @covers JLanguage::getKnownLanguages
*
* @return void
*/
public function testGetKnownLanguages()
{
// This method returns a list of known languages
$basePath = __DIR__ . '/data';
$option1 = array('name' => 'English (United Kingdom)', 'tag' => 'en-GB', 'rtl' => '0', 'locale' => 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, uk, united kingdom, united-kingdom', 'firstDay' => '0');
$listCompareEqual1 = array('en-GB' => $option1);
$list = JLanguage::getKnownLanguages($basePath);
$this->assertEquals($listCompareEqual1, $list, 'Line: ' . __LINE__);
}
示例15: _buildoptions
/**
* Build the configuration options.
* @return array The Configuration in an array
*/
function _buildoptions()
{
// initialise configuration variables
global $mainframe, $task, $option;
//$task = strtolower($this->_task);
$options['config'] = JComponentHelper::getParams($option . '1');
$options['autoCorrect'] = $options['config']->get('autoCorrect', 'a^=�');
$options['backticks'] = $options['config']->get('backticks', 0);
$options['cid'] = JRequest::getVar('cid', array(''), '', 'array');
$options['client_lang'] = $mainframe->getUserStateFromRequest($option . '.client_lang', 'client_lang', '');
$options['globalChanges'] = $options['config']->get('globalChanges', 0);
$options['limitstart'] = $mainframe->getUserStateFromRequest($option . '.limitstart', 'limitstart', '');
$options['newprocess'] = JRequest::getVar('newprocess', 0, '', 'integer');
$options['refLang'] = $options['config']->get('refLanguage', 'en-GB');
$options['refLangMissing'] = false;
$options['searchStyle'] = $options['config']->get('searchStyle', 'background-color:yellow;');
$options['task'] = strtolower($task);
// initialise a list of available languages
$options['languages'] = array();
$options['clients'] = array();
$options['clients']['S'] = JText::_('Site');
foreach (JLanguage::getKnownLanguages(JPATH_SITE) as $k => $v) {
$options['languages']['S_' . $k] = $options['clients']['S'] . ' - ' . $v['name'];
}
$options['clients']['A'] = JText::_('Administrator');
foreach (JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR) as $k => $v) {
$options['languages']['A_' . $k] = $options['clients']['A'] . ' - ' . $v['name'];
}
if (JFolder::exists(JPATH_INSTALLATION)) {
$options['clients']['I'] = JText::_('Installation');
foreach (JLanguage::getKnownLanguages(JPATH_INSTALLATION) as $k => $v) {
$options['languages']['I_' . $k] = $options['clients']['I'] . ' - ' . $v['name'];
}
}
// validate client_lang (split, reassemble with cases, check against allowed values, on failure default to first allowed value)
$cl_split = preg_split("/[^a-z]/i", $options['client_lang']);
if ($options['client_lang']) {
$options['client_lang'] = strtoupper($cl_split[0]) . '_' . strtolower($cl_split[1]) . '-' . strtoupper($cl_split[2]);
}
if (!isset($options['languages'][$options['client_lang']])) {
$options['client_lang'] = key($options['languages']);
}
// set client variables
$options['client'] = $options['client_lang'][0];
if ($options['client'] == 'A') {
$options['basePath'] = JPATH_ADMINISTRATOR;
$options['clientKey'] = 'administrator';
} else {
if ($options['client'] == 'I') {
$options['basePath'] = JPATH_INSTALLATION;
$options['clientKey'] = 'installation';
} else {
$options['basePath'] = JPATH_SITE;
$options['clientKey'] = 'site';
}
}
$options['clientName'] = JText::_($options['clientKey']);
// validate that the reference language exists on this client
if (!isset($options['languages'][$options['client'] . '_' . $options['refLang']])) {
// initialise to en-GB
$use = 'en-GB';
// look for the first key index containing the reference language string
foreach ($options['languages'] as $k => $v) {
if ($k[0] == $options['client']) {
$use = substr($k, -4);
break;
}
}
// set back to $options key
$options['refLang'] = $use;
}
// set language variables
$options['lang'] = substr($options['client_lang'], 2);
$options['langLen'] = strlen($options['lang']);
$options['langName'] = $options['languages'][$options['client_lang']];
$options['langPath'] = JLanguage::getLanguagePath($options['basePath'], $options['lang']);
$options['refLangLen'] = strlen($options['refLang']);
$options['refLangPath'] = JLanguage::getLanguagePath($options['basePath'], $options['refLang']);
// set reference language variables
$options['isReference'] = intval($options['lang'] == $options['refLang']);
// validate the cid array
if (!is_array($options['cid'])) {
if (!empty($options['cid'])) {
$options['cid'] = array($options['cid']);
} else {
$options['cid'] = array('');
}
}
// process the cid array to validate filenames
foreach ($options['cid'] as $k => $v) {
if ($v) {
// strip unpublished prefix
if (substr($v, 0, 3) == 'xx.') {
$v = substr($v, 3);
}
// strip files that don't match the selected language
//.........這裏部分代碼省略.........