Enhance multilangue support in website module

This commit is contained in:
Laurent Destailleur 2020-02-21 11:36:16 +01:00
parent 1f4b639ba0
commit 7909055ee8
12 changed files with 161 additions and 37 deletions

View File

@ -59,16 +59,17 @@ class FormAdmin
* @param int $forcecombo Force to use combo box (so no ajax beautify effect) * @param int $forcecombo Force to use combo box (so no ajax beautify effect)
* @param int $multiselect Make the combo a multiselect * @param int $multiselect Make the combo a multiselect
* @param array $onlykeys Show only the following keys (opposite of $filter) * @param array $onlykeys Show only the following keys (opposite of $filter)
* @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 * @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, $onlykeys = array()) 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(), $mainlangonly = 0)
{ {
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
if (!empty($conf->global->MAIN_DEFAULT_LANGUAGE_FILTER)) $filter[$conf->global->MAIN_DEFAULT_LANGUAGE_FILTER] = 1; if (!empty($conf->global->MAIN_DEFAULT_LANGUAGE_FILTER)) $filter[$conf->global->MAIN_DEFAULT_LANGUAGE_FILTER] = 1;
$langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT, 12, 0, $mainlangonly);
$out=''; $out='';
@ -95,21 +96,28 @@ class FormAdmin
{ {
$valuetoshow=$value; $valuetoshow=$value;
if ($showcode == 1) $valuetoshow=$key.' - '.$value; if ($showcode == 1) $valuetoshow=$key.' - '.$value;
if ($showcode == 2) $valuetoshow=$value.' ('.$key.')'; if ($showcode == 2) {
if ($mainlangonly) $valuetoshow=$value.' ('.preg_replace('/[_-].*$/', '', $key).')';
else $valuetoshow=$value.' ('.$key.')';
}
if ($filter && is_array($filter) && array_key_exists($key, $filter)) { $keytouse = $key;
if ($mainlangonly) $keytouse = preg_replace('/[_-].*$/', '', $key);
if ($filter && is_array($filter) && array_key_exists($keytouse, $filter)) {
continue; continue;
} }
if ($onlykeys && is_array($onlykeys) && ! array_key_exists($key, $onlykeys)) { if ($onlykeys && is_array($onlykeys) && ! array_key_exists($keytouse, $onlykeys)) {
continue; continue;
} }
if ($selected == $key)
if ($selected == $keytouse)
{ {
$out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>'; $out.= '<option value="'.$keytouse.'" selected>'.$valuetoshow.'</option>';
} }
else else
{ {
$out.= '<option value="'.$key.'">'.$valuetoshow.'</option>'; $out.= '<option value="'.$keytouse.'">'.$valuetoshow.'</option>';
} }
} }
$out.= '</select>'; $out.= '</select>';

View File

@ -269,7 +269,15 @@ class FormWebsite
$valueforoption = '<span class="opacitymedium">['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).']</span> '; $valueforoption = '<span class="opacitymedium">['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).']</span> ';
$valueforoption .= $valpage->pageurl.' - '.$valpage->title; $valueforoption .= $valpage->pageurl.' - '.$valpage->title;
if ($website->fk_default_home && $key == $website->fk_default_home) $valueforoption .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>'; if ($website->otherlang) { // If there is alternative lang for this web site, we show the language code
if ($valpage->lang) {
$valueforoption .= ' <span class="opacitymedium">('.$valpage->lang.')</span>';
}
}
if ($website->fk_default_home && $key == $website->fk_default_home) {
//$valueforoption .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
$valueforoption .= ' <span class="opacitymedium fa fa-home"></span>';
}
$out .= '<option value="'.$key.'"'; $out .= '<option value="'.$key.'"';
if ($pageid > 0 && $pageid == $key) $out .= ' selected'; // To preselect a value if ($pageid > 0 && $pageid == $key) $out .= ' selected'; // To preselect a value

View File

@ -764,28 +764,37 @@ class Translate
* @param string $langdir Directory to scan * @param string $langdir Directory to scan
* @param integer $maxlength Max length for each value in combo box (will be truncated) * @param integer $maxlength Max length for each value in combo box (will be truncated)
* @param int $usecode 1=Show code instead of country name for language variant, 2=Show only code * @param int $usecode 1=Show code instead of country name for language variant, 2=Show only code
* @param int $mainlangonly 1=Show only main languages ('fr_FR' no' fr_BE', 'es_ES' not 'es_MX', ...)
* @return array List of languages * @return array List of languages
*/ */
public function get_available_languages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 0, $usecode = 0) public function get_available_languages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 0, $usecode = 0, $mainlangonly = 0)
{ {
// phpcs:enable // phpcs:enable
global $conf; global $conf;
$this->load("languages");
// We scan directory langs to detect available languages // We scan directory langs to detect available languages
$handle = opendir($langdir."/langs"); $handle = opendir($langdir."/langs");
$langs_available = array(); $langs_available = array();
while ($dir = trim(readdir($handle))) while ($dir = trim(readdir($handle)))
{ {
if (preg_match('/^[a-z]+_[A-Z]+/i', $dir)) $regs = array();
if (preg_match('/^([a-z]+)_([A-Z]+)/i', $dir, $regs))
{ {
$this->load("languages"); // We must keep only main languages
if ($mainlangonly) {
$arrayofspecialmainlanguages = array('en_US', 'sq_AL', 'ar_SA', 'eu_ES', 'bn_DB', 'bs_BA', 'ca_ES', 'zh_TW', 'cs_CZ', 'da_DK', 'et_EE', 'ka_GE', 'el_GR', 'he_IL', 'kn_IN', 'km_KH', 'ko_KR', 'lo_LA', 'nb_NO', 'fa_IR', 'sr_RS', 'sl_SI', 'uk_UA', 'vi_VN');
if (strtolower($regs[1]) != strtolower($regs[2]) && ! in_array($dir, $arrayofspecialmainlanguages)) continue;
}
// We must keep only languages into MAIN_LANGUAGES_ALLOWED
if (!empty($conf->global->MAIN_LANGUAGES_ALLOWED) && !in_array($dir, explode(',', $conf->global->MAIN_LANGUAGES_ALLOWED))) continue; if (!empty($conf->global->MAIN_LANGUAGES_ALLOWED) && !in_array($dir, explode(',', $conf->global->MAIN_LANGUAGES_ALLOWED))) continue;
if ($usecode == 2) if ($usecode == 2)
{ {
$langs_available[$dir] = $dir; $langs_available[$dir] = $dir;
} }
if ($usecode == 1 || !empty($conf->global->MAIN_SHOW_LANGUAGE_CODE)) if ($usecode == 1 || !empty($conf->global->MAIN_SHOW_LANGUAGE_CODE))
{ {
$langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir), $maxlength); $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir), $maxlength);
@ -794,6 +803,9 @@ class Translate
{ {
$langs_available[$dir] = $this->trans('Language_'.$dir); $langs_available[$dir] = $this->trans('Language_'.$dir);
} }
if ($mainlangonly) {
$langs_available[$dir] = str_replace(' (United States)', '', $langs_available[$dir]);
}
} }
} }
return $langs_available; return $langs_available;

View File

@ -239,15 +239,15 @@ function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '')
{ {
global $website; global $website;
$content = str_replace('<link rel="stylesheet" href="/styles.css', '<link rel="stylesheet" href="styles.css', $content);
// Protect the link styles.css.php to any replacement that we make after. // Protect the link styles.css.php to any replacement that we make after.
$content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content); $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
$content = str_replace('href="http', 'href="!~!~!~http', $content); $content = str_replace('href="http', 'href="!~!~!~http', $content);
$content = str_replace('href="//', 'href="!~!~!~//', $content); $content = str_replace('href="//', 'href="!~!~!~//', $content);
$content = str_replace('src="viewimage.php', 'src="!~!~!~/viewimage.php', $content); $content = str_replace(array('src="viewimage.php', 'src="/viewimage.php'), 'src="!~!~!~/viewimage.php', $content);
$content = str_replace('src="/viewimage.php', 'src="!~!~!~/viewimage.php', $content);
$content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content); $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
$content = str_replace('href="document.php', 'href="!~!~!~/document.php', $content); $content = str_replace(array('href="document.php','href="/document.php'), 'href="!~!~!~/document.php', $content);
$content = str_replace('href="/document.php', 'href="!~!~!~/document.php', $content);
$content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content); $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
// Replace relative link / with dolibarr URL: ...href="/"... // Replace relative link / with dolibarr URL: ...href="/"...
@ -286,6 +286,7 @@ function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '')
// Fix relative URL // Fix relative URL
$content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content); $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
$content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content); $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
// Remove the protection tag !~!~!~ // Remove the protection tag !~!~!~
$content = str_replace('!~!~!~', '', $content); $content = str_replace('!~!~!~', '', $content);
} }

View File

@ -55,6 +55,7 @@ function dolSaveMasterFile($filemaster)
* @param Website $object Object website * @param Website $object Object website
* @param WebsitePage $objectpage Object websitepage * @param WebsitePage $objectpage Object websitepage
* @return boolean True if OK * @return boolean True if OK
* @see dolSavePageContent()
*/ */
function dolSavePageAlias($filealias, $object, $objectpage) function dolSavePageAlias($filealias, $object, $objectpage)
{ {
@ -74,6 +75,24 @@ function dolSavePageAlias($filealias, $object, $objectpage)
@chmod($filealias, octdec($conf->global->MAIN_UMASK)); @chmod($filealias, octdec($conf->global->MAIN_UMASK));
} }
// Save also alias into language subdirectory if we have to
if ($objectpage->lang && in_array($objectpage->lang, explode(',', $object->otherlang))) {
$dirname = dirname($filealias);
$filename = basename($filealias);
$filealias = $dirname.'/'.$objectpage->lang.'/'.$filename;
$aliascontent = '<?php'."\n";
$aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n";
$aliascontent .= 'global $dolibarr_main_data_root;'."\n";
$aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'../page'.$objectpage->id.'.tpl.php\'; ';
$aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
$aliascontent .= '?>'."\n";
$result = file_put_contents($filealias, $aliascontent);
if (!empty($conf->global->MAIN_UMASK)) {
@chmod($filealias, octdec($conf->global->MAIN_UMASK));
}
}
return ($result ?true:false); return ($result ?true:false);
} }
@ -85,6 +104,7 @@ function dolSavePageAlias($filealias, $object, $objectpage)
* @param Website $object Object website * @param Website $object Object website
* @param WebsitePage $objectpage Object websitepage * @param WebsitePage $objectpage Object websitepage
* @return boolean True if OK * @return boolean True if OK
* @see dolSavePageAlias()
*/ */
function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage) function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
{ {
@ -101,7 +121,10 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
$tplcontent = ''; $tplcontent = '';
$tplcontent .= "<?php // BEGIN PHP\n"; $tplcontent .= "<?php // BEGIN PHP\n";
$tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; $tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
$tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n"; $tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {\n";
$tplcontent .= ' $pathdepth = count(explode(\'/\', $_SERVER[\'SCRIPT_NAME\'])) - 2;'."\n";
$tplcontent .= ' require_once ($pathdepth ? str_repeat(\'../\', $pathdepth) : \'./\').\'master.inc.php\';'."\n";
$tplcontent .= "} // Not already loaded"."\n";
$tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$tplcontent .= "ob_start();\n"; $tplcontent .= "ob_start();\n";
@ -125,7 +148,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
// Add translation reference (main language) // Add translation reference (main language)
if ($object->isMultiLang()) { if ($object->isMultiLang()) {
// Add myself // Add myself
$tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="'.($object->fk_default_home == $objectpage->id ? '/' : '/'.$objectpage->pageurl.'.php').'" />'."\n"; $tplcontent .= '<link rel="alternate" hreflang="'.$shortlangcode.'" href="'.($object->fk_default_home == $objectpage->id ? '/' : '/'.$shortlangcode.'/'.$objectpage->pageurl.'.php').'" />'."\n";
// Add page "translation of" // Add page "translation of"
$translationof = $objectpage->fk_page; $translationof = $objectpage->fk_page;
if ($translationof) { if ($translationof) {
@ -135,7 +158,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
$tmpshortlangcode = ''; $tmpshortlangcode = '';
if ($tmppage->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en if ($tmppage->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
if ($tmpshortlangcode != $shortlangcode) { if ($tmpshortlangcode != $shortlangcode) {
$tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : '/'.$tmppage->pageurl.'.php').'" />'."\n"; $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $tmppage->id ? '/' : '/'.$tmpshortlangcode.'/'.$tmppage->pageurl.'.php').'" />'."\n";
} }
} }
} }
@ -152,7 +175,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
$tmpshortlangcode = ''; $tmpshortlangcode = '';
if ($obj->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $obj->lang); // en_US or en-US -> en if ($obj->lang) $tmpshortlangcode = preg_replace('/[_-].*$/', '', $obj->lang); // en_US or en-US -> en
if ($tmpshortlangcode != $shortlangcode) { if ($tmpshortlangcode != $shortlangcode) {
$tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $obj->id ? '/' : '/'.$obj->pageurl.'.php').'" />'."\n"; $tplcontent .= '<link rel="alternate" hreflang="'.$tmpshortlangcode.'" href="'.($object->fk_default_home == $obj->id ? '/' : '/'.$tmpshortlangcode.'/'.$obj->pageurl.'.php').'" />'."\n";
} }
} }
} }
@ -160,11 +183,11 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
else dol_print_error($db); else dol_print_error($db);
} }
// Add canonical reference // Add canonical reference
$tplcontent .= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : ($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n"; $tplcontent .= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : $shortlangcode.'/'.($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n";
// Add manifest.json on homepage // Add manifest.json on homepage
$tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n"; $tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>'."\n";
$tplcontent .= '<!-- Include link to CSS file -->'."\n"; $tplcontent .= '<!-- Include link to CSS file -->'."\n";
$tplcontent .= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; $tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n";
$tplcontent .= '<!-- Include HTML header from common file -->'."\n"; $tplcontent .= '<!-- Include HTML header from common file -->'."\n";
$tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n"; $tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n";
$tplcontent .= '<!-- Include HTML header from page header block -->'."\n"; $tplcontent .= '<!-- Include HTML header from page header block -->'."\n";

View File

@ -44,6 +44,19 @@ ALTER TABLE llx_commande_fournisseur_dispatch_extrafields ADD INDEX idx_commande
-- For v12 -- For v12
UPDATE llx_website SET lang = 'en' WHERE lang like 'en_%';
UPDATE llx_website SET lang = 'fr' WHERE lang like 'fr_%';
UPDATE llx_website SET lang = 'es' WHERE lang like 'es_%';
UPDATE llx_website SET lang = 'de' WHERE lang like 'de_%';
UPDATE llx_website SET lang = 'it' WHERE lang like 'it_%';
UPDATE llx_website SET lang = 'pt' WHERE lang like 'pt_%';
UPDATE llx_website_page SET lang = 'en' WHERE lang like 'en_%';
UPDATE llx_website_page SET lang = 'fr' WHERE lang like 'fr_%';
UPDATE llx_website_page SET lang = 'es' WHERE lang like 'es_%';
UPDATE llx_website_page SET lang = 'de' WHERE lang like 'de_%';
UPDATE llx_website_page SET lang = 'it' WHERE lang like 'it_%';
UPDATE llx_website_page SET lang = 'pt' WHERE lang like 'pt_%';
ALTER TABLE llx_website ADD COLUMN lang varchar(8); ALTER TABLE llx_website ADD COLUMN lang varchar(8);
ALTER TABLE llx_website ADD COLUMN otherlang varchar(255); ALTER TABLE llx_website ADD COLUMN otherlang varchar(255);

View File

@ -228,6 +228,8 @@ ErrorFieldRequiredForProduct=Field '%s' is required for product %s
ProblemIsInSetupOfTerminal=Problem is in setup of terminal %s. ProblemIsInSetupOfTerminal=Problem is in setup of terminal %s.
ErrorAddAtLeastOneLineFirst=Add at least one line first ErrorAddAtLeastOneLineFirst=Add at least one line first
ErrorRecordAlreadyInAccountingDeletionNotPossible=Error, record is already transferred in accounting, deletion is not possible. ErrorRecordAlreadyInAccountingDeletionNotPossible=Error, record is already transferred in accounting, deletion is not possible.
ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother=Error, language is mandatory if you set the page as a translation of another one.
ErrorLanguageOfTranslatedPageIsSameThanThisPage=Error, language of translated page is same than this one.
# Warnings # Warnings
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.

View File

@ -65,7 +65,7 @@ Language_mk_MK=Macedonian
Language_mn_MN=Mongolian Language_mn_MN=Mongolian
Language_nb_NO=Norwegian (Bokmål) Language_nb_NO=Norwegian (Bokmål)
Language_nl_BE=Dutch (Belgium) Language_nl_BE=Dutch (Belgium)
Language_nl_NL=Dutch (Netherlands) Language_nl_NL=Dutch
Language_pl_PL=Polish Language_pl_PL=Polish
Language_pt_BR=Portuguese (Brazil) Language_pt_BR=Portuguese (Brazil)
Language_pt_PT=Portuguese Language_pt_PT=Portuguese

View File

@ -13,6 +13,15 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Note about $_SERVER:
* REQUEST_URI: /test/before_rewrite/script.php/path/info?q=helloword
* PHP_SELF: /test/after_rewrite/script.php/path/info
* QUERY_STRING: q=helloword
* SCRIPT_NAME: /test/after_rewrite/script.php
* PATH_INFO: /path/info
* SCRIPT_FILENAME: /var/www/test/php/script.php
* __FILE__ : /var/www/test/php/script_included.php
*/ */
/** /**
@ -110,7 +119,7 @@ if (empty($pageid))
if (empty($pageid)) if (empty($pageid))
{ {
$array=$objectpage->fetchAll($object->id); $array=$objectpage->fetchAll($object->id); // TODO Can filter on container of type pages only ?
if (is_array($array) && count($array) > 0) if (is_array($array) && count($array) > 0)
{ {
$firstrep=reset($array); $firstrep=reset($array);

View File

@ -170,6 +170,15 @@ class Website extends CommonObject
if (empty($this->date_modification)) { if (empty($this->date_modification)) {
$this->date_modification = $now; $this->date_modification = $now;
} }
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
$tmparray = explode(',', $this->otherlang);
if (is_array($tmparray)) {
foreach($tmparray as $key => $val) {
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
}
$this->otherlang = join(',', $tmparray);
}
// Check parameters // Check parameters
if (empty($this->entity)) { if (empty($this->entity)) {
@ -456,6 +465,16 @@ class Website extends CommonObject
$this->status = (int) $this->status; $this->status = (int) $this->status;
} }
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
$tmparray = explode(',', $this->otherlang);
if (is_array($tmparray)) {
foreach($tmparray as $key => $val) {
$tmparray[$key] = preg_replace('/[_-].*$/', '', trim($val)); // en_US or en-US -> en
}
$this->otherlang = join(',', $tmparray);
}
// Check parameters // Check parameters
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
@ -837,7 +856,7 @@ class Website extends CommonObject
$this->ref = 'myspecimenwebsite'; $this->ref = 'myspecimenwebsite';
$this->description = 'A specimen website'; $this->description = 'A specimen website';
$this->lang = 'en'; $this->lang = 'en';
$this->otherlang = 'fr,es_MX'; $this->otherlang = 'fr,es';
$this->status = ''; $this->status = '';
$this->fk_default_home = null; $this->fk_default_home = null;
$this->virtualhost = 'http://myvirtualhost'; $this->virtualhost = 'http://myvirtualhost';
@ -1178,7 +1197,11 @@ class Website extends CommonObject
// The move is not enough, so we regenerate page // The move is not enough, so we regenerate page
$filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php'; $filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php';
dolSavePageContent($filetpl, $object, $objectpagestatic); $result = dolSavePageContent($filetpl, $object, $objectpagestatic);
if (!$result) {
$this->errors[] = 'Failed to write file '.basename($filetpl);
$error++;
}
// Regenerate alternative aliases pages // Regenerate alternative aliases pages
if (is_array($aliasesarray)) if (is_array($aliasesarray))
@ -1188,7 +1211,11 @@ class Website extends CommonObject
if (trim($aliasshortcuttocreate)) if (trim($aliasshortcuttocreate))
{ {
$filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php'; $filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php';
dolSavePageAlias($filealias, $object, $objectpagestatic); $result = dolSavePageAlias($filealias, $object, $objectpagestatic);
if (!$result) {
$this->errors[] = 'Failed to write file '.basename($filealias);
$error++;
}
} }
} }
} }

View File

@ -158,6 +158,9 @@ class WebsitePage extends CommonObject
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1); $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
return $this->createCommon($user, $notrigger); return $this->createCommon($user, $notrigger);
} }
@ -377,6 +380,22 @@ class WebsitePage extends CommonObject
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1); $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
if ($this->fk_page > 0) {
if (empty($this->lang)) {
$this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
return -1;
}
$tmppage = new WebsitePage($this->db);
$tmppage->fetch($this->fk_page);
if ($tmppage->lang == $this->lang) {
$this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
return -1;
}
}
return $this->updateCommon($user, $notrigger); return $this->updateCommon($user, $notrigger);
} }
@ -513,7 +532,8 @@ class WebsitePage extends CommonObject
$label .= '<br>'; $label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>'; $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
$label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>'; $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
$label .= '<b>'.$langs->trans('Title').':</b> '.$this->title; $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
$label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
$url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id; $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;

View File

@ -860,7 +860,7 @@ if ($action == 'addcontainer')
$result = dolSavePageAlias($filealias, $object, $objectpage); $result = dolSavePageAlias($filealias, $object, $objectpage);
if (!$result) if (!$result)
{ {
setEventMessages('Failed to write file '.$filealias, null, 'errors'); setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
} }
// Save page of content // Save page of content
@ -1499,8 +1499,9 @@ if ($action == 'updatemeta')
{ {
if (trim($tmpaliasalt)) if (trim($tmpaliasalt))
{ {
$result = dolSavePageAlias($pathofwebsite.'/'.trim($tmpaliasalt).'.php', $object, $objectpage); $filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
if (!$result) setEventMessages('Failed to write file '.$pathofwebsite.'/'.trim($tmpaliasalt).'.php', null, 'errors'); $result = dolSavePageAlias($filealias, $object, $objectpage);
if (!$result) setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
} }
} }
} }
@ -1756,7 +1757,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
// Save page alias // Save page alias
$result = dolSavePageAlias($filealias, $object, $objectpage); $result = dolSavePageAlias($filealias, $object, $objectpage);
if (!$result) setEventMessages('Failed to write file '.$filealias, null, 'errors'); if (!$result) setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
// Save page content // Save page content
$result = dolSavePageContent($filetpl, $object, $objectpage); $result = dolSavePageContent($filetpl, $object, $objectpage);
@ -2702,7 +2703,7 @@ if ($action == 'editcss')
$htmltext=''; $htmltext='';
print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG'); print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
print '</td><td>'; print '</td><td>';
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 $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -2861,7 +2862,7 @@ if ($action == 'createsite')
print '<tr><td>'; print '<tr><td>';
print $langs->trans('MainLanguage'); print $langs->trans('MainLanguage');
print '</td><td>'; print '</td><td>';
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : '0'), 'WEBSITE_LANG', 0, null, 1, 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, 0, 0, array(), 1);
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'; print '<tr><td>';
@ -3104,7 +3105,7 @@ if ($action == 'editmeta' || $action == 'createcontainer')
foreach($tmparray as $key) { foreach($tmparray as $key) {
$tmpkey = trim($key); $tmpkey = trim($key);
if (strlen($key) == 2) { if (strlen($key) == 2) {
$tmpkey = strtolower($key).'_'.strtoupper($tmpkey); $tmpkey = strtolower($key);
} }
$onlykeys[$tmpkey] = $tmpkey; $onlykeys[$tmpkey] = $tmpkey;
} }
@ -3112,7 +3113,7 @@ if ($action == 'editmeta' || $action == 'createcontainer')
if (empty($object->lang) && empty($object->otherlang)) { if (empty($object->lang) && empty($object->otherlang)) {
$onlykeys = null; // We keep full list of languages $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); print $formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
$htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties"); $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
print $form->textwithpicto('', $htmltext); print $form->textwithpicto('', $htmltext);
print '</td></tr>'; print '</td></tr>';