Skip to content

Commit

Permalink
Lang of web site is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 20, 2020
1 parent 895503d commit 5c48f6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
13 changes: 8 additions & 5 deletions htdocs/core/class/html.formadmin.class.php
Expand Up @@ -50,17 +50,18 @@ public function __construct($db)
* @param string $selected Language pre-selected
* @param string $htmlname Name of HTML select
* @param int $showauto Show 'auto' choice
* @param array $filter Array of keys to exclude in list
* @param array $filter Array of keys to exclude in list (opposite of $onlykeys)
* @param string $showempty '1'=Add empty value or string to show
* @param int $showwarning Show a warning if language is not complete
* @param int $disabled Disable edit of select
* @param string $morecss Add more css styles
* @param int $showcode 1=Add language code into label at begining, 2=Add language code into label at end
* @param int $forcecombo Force to use combo box (so no ajax beautify effect)
* @param int $multiselect Make the combo a multiselect
* @param array $onlykeys Show only the following keys (opposite of $filter)
* @return string Return HTML select string with list of languages
*/
public function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = null, $showempty = '', $showwarning = 0, $disabled = 0, $morecss = '', $showcode = 0, $forcecombo = 0, $multiselect = 0)
public function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = null, $showempty = '', $showwarning = 0, $disabled = 0, $morecss = '', $showcode = 0, $forcecombo = 0, $multiselect = 0, $onlykeys = array())
{
// phpcs:enable
global $conf, $langs;
Expand Down Expand Up @@ -96,11 +97,13 @@ public function select_language($selected = '', $htmlname = 'lang_id', $showauto
if ($showcode == 1) $valuetoshow=$key.' - '.$value;
if ($showcode == 2) $valuetoshow=$value.' ('.$key.')';

if ($filter && is_array($filter) && array_key_exists($key, $filter))
{
if ($filter && is_array($filter) && array_key_exists($key, $filter)) {
continue;
}
if ($onlykeys && is_array($onlykeys) && ! array_key_exists($key, $onlykeys)) {
continue;
}
elseif ($selected == $key)
if ($selected == $key)
{
$out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
}
Expand Down
44 changes: 30 additions & 14 deletions htdocs/website/index.php
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2016-2018 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2016-2020 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -779,16 +779,15 @@
}
else
{
$objectpage->title = GETPOST('WEBSITE_TITLE', 'alpha');
$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
$objectpage->title = GETPOST('WEBSITE_TITLE', 'alphanohtml');
$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
$objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alpha');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'alpha');
$objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'alpha');
$objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
$objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alphanohtml');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
$objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
$objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alphanohtml');
$objectpage->htmlheader = GETPOST('htmlheader', 'none');

$substitutionarray = array();
Expand Down Expand Up @@ -1417,8 +1416,7 @@
$objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
$objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alphanohtml');
$objectpage->htmlheader = trim(GETPOST('htmlheader', 'none'));
$objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);

Expand Down Expand Up @@ -2704,7 +2702,7 @@ function switchEditorOnline(forceenable)
$htmltext='';
print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
print '</td><td>';
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'alpha') : ($object->lang ? $object->lang : $langs->defaultlang)), 'WEBSITE_LANG', 0, 0, 0, 0, 0, 'minwidth300', 2);
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2);
print '</td>';
print '</tr>';

Expand Down Expand Up @@ -2863,7 +2861,7 @@ function switchEditorOnline(forceenable)
print '<tr><td>';
print $langs->trans('MainLanguage');
print '</td><td>';
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'alpha') : $langs->defaultlang), 'WEBSITE_LANG', 0, 0, 0, 0, 0, 'minwidth300', 2);
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : '0'), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2);
print '</td></tr>';

print '<tr><td>';
Expand Down Expand Up @@ -3098,7 +3096,25 @@ function switchEditorOnline(forceenable)
print '<tr><td>';
print $langs->trans('Language');
print '</td><td>';
print $formadmin->select_language($pagelang ? $pagelang : $langs->defaultlang, 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200');
$onlykeys = array();
if ($object->lang) $onlykeys[$object->lang] = $object->lang;
else $onlykeys[$langs->defaultlang] = $langs->defaultlang;
if ($object->otherlang) {
$tmparray = explode(',', $object->otherlang);
foreach($tmparray as $key) {
$tmpkey = trim($key);
if (strlen($key) == 2) {
$tmpkey = strtolower($key).'_'.strtoupper($tmpkey);
}
$onlykeys[$tmpkey] = $tmpkey;
}
}
if (empty($object->lang) && empty($object->otherlang)) {
$onlykeys = null; // We keep full list of languages
}
print $formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys);
$htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
print $form->textwithpicto('', $htmltext);
print '</td></tr>';

// Translation of
Expand Down

0 comments on commit 5c48f6f

Please sign in to comment.