Fix set of translation of website page during cloning

This commit is contained in:
Laurent Destailleur 2020-12-06 15:59:19 +01:00
parent 6c2d520e21
commit 1f83e22aea
6 changed files with 35 additions and 23 deletions

View File

@ -4221,7 +4221,7 @@ class Form
* @param string $title Title
* @param string $question Question
* @param string $action Action
* @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , ))
* @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>))
* type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', ...
* @param string $selectedchoice '' or 'no', or 'yes' or '1' or '0'
* @param int|string $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx

View File

@ -51,14 +51,14 @@ class FormAdmin
* @param string $htmlname Name of HTML select
* @param int $showauto Show 'auto' choice
* @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 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). Example array('fr', 'es', ...)
* @param array $onlykeys Array of language keys to restrict list with the following keys (opposite of $filter). Example array('fr', 'es', ...)
* @param int $mainlangonly 1=Show only main languages ('fr_FR' no' fr_BE', 'es_ES' not 'es_MX', ...)
* @return string Return HTML select string with list of languages
*/
@ -95,9 +95,12 @@ class FormAdmin
foreach ($langs_available as $key => $value)
{
$valuetoshow = $value;
if ($showcode == 1) $valuetoshow = $key.' - '.$value;
if ($showcode == 1) {
if ($mainlangonly) $valuetoshow = '<span class="opacitymedium">'.preg_replace('/[_-].*$/', '', $key).'</span> - '.$value;
else $valuetoshow = '<span class="opacitymedium">'.$key.'</span> - '.$value;
}
if ($showcode == 2) {
if ($mainlangonly) $valuetoshow = $value.' ('.preg_replace('/[_-].*$/', '', $key).')';
if ($mainlangonly) $valuetoshow = $value.' <span class="opacitymedium">('.preg_replace('/[_-].*$/', '', $key).')</span>';
else $valuetoshow = $value.' <span class="opacitymedium">('.$key.')</span>';
}

View File

@ -794,29 +794,33 @@ class Translate
if ($mainlangonly) {
$arrayofspecialmainlanguages = array(
'en'=>'en_US',
'sq'=>'sq_AL',
'am'=>'am_ET',
'ar'=>'ar_SA',
'eu'=>'eu_ES',
'bn'=>'bn_DB',
'bs'=>'bs_BA',
'ca'=>'ca_ES',
'zh'=>'zh_TW',
'cs'=>'cs_CZ',
'da'=>'da_DK',
'et'=>'et_EE',
'ka'=>'ka_GE',
'el'=>'el_GR',
'eu'=>'eu_ES',
'fa'=>'fa_IR',
'he'=>'he_IL',
'kn'=>'kn_IN',
'ka'=>'ka_GE',
'km'=>'km_KH',
'kn'=>'kn_IN',
'ko'=>'ko_KR',
'ja'=>'ja_JP',
'lo'=>'lo_LA',
'nb'=>'nb_NO',
'fa'=>'fa_IR',
'sq'=>'sq_AL',
'sr'=>'sr_RS',
'sv'=>'sv_SE',
'sl'=>'sl_SI',
'uk'=>'uk_UA',
'vi'=>'vi_VN'
'vi'=>'vi_VN',
'zh'=>'zh_CN'
);
if (strtolower($regs[1]) != strtolower($regs[2]) && !in_array($dir, $arrayofspecialmainlanguages)) continue;
}

View File

@ -135,4 +135,5 @@ RSSFeed=RSS Feed
RSSFeedDesc=You can get a RSS feed of latest articles with type 'blogpost' using this URL
PagesRegenerated=%s page(s)/container(s) regenerated
RegenerateWebsiteContent=Regenerate web site cache files
AllowedInFrames=Allowed in Frames
AllowedInFrames=Allowed in Frames
DefineListOfAltLanguagesInWebsiteProperties=Define list of all available languages into web site properties.

View File

@ -682,6 +682,7 @@ class WebsitePage extends CommonObject
$object->author_alias = '';
$object->date_creation = $now;
$object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
$object->description = $object->title;
if (!empty($newlang)) $object->lang = $newlang;
if ($istranslation) $object->fk_page = $fromid;
else $object->fk_page = 0;

View File

@ -1824,8 +1824,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
// Protection if it is a translation page
if ($istranslation)
{
if (GETPOST('newlang', 'aZ09') == $objectpage->lang)
{
if (GETPOST('newlang', 'aZ09') == $objectpage->lang || !GETPOST('newlang', 'aZ09')) {
$error++;
setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
$action = 'preview';
@ -2631,24 +2630,28 @@ if (!GETPOST('hide_websitemenu'))
$onlylang = array();
if ($website->otherlang) {
if (!empty($website->lang)) {
$onlylang[$website->lang] = $website->lang;
$onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
}
foreach (explode(',', $website->otherlang) as $langkey) {
$onlylang[$langkey] = $langkey;
}
$textifempty = 1;
$textifempty = $langs->trans("Default");
} else {
$onlylang['none'] = '';
$onlylang['none'] = 'none';
$textifempty = $langs->trans("Default");
}
$textifempty = 1;
$formquestion = array(
array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl),
array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> ''),
array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss'=>'margintoponly'),
array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, $textifempty, 0, 0, 'minwidth200', 0, 1, 0, $onlylang, 1)),
);
array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'moreattr'=>'autofocus="autofocus"', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> '')
);
if (count($onlylang) > 1) {
$formquestion[] = array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss'=>'margintoponly');
}
$value= $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, $textifempty, 0, 0, 'minwidth200', 1, 0, 0, $onlylang, 1);
$formquestion[] = array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $value);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);