From 429da47d68d7e6dae57ba750e5a42d33500306c2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Feb 2019 13:11:14 +0100 Subject: [PATCH] Fix default language of reminders --- htdocs/adherents/class/adherent.class.php | 6 +++++- htdocs/core/lib/functions.lib.php | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 7872ed1ca68..688b2c9741a 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2756,9 +2756,13 @@ class Adherent extends CommonObject { $adherent->fetch_thirdparty(); + // Language code to use ($languagecodeformember) is default language of thirdparty, if no thirdparty, the language found from country of member then country of thirdparty, and if still not found we use the language of company. + $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code); + $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang); + // Send reminder email $outputlangs = new Translate('', $conf); - $outputlangs->setDefaultLang(empty($adherent->thirdparty->default_lang) ? $mysoc->default_lang : $adherent->thirdparty->default_lang); + $outputlangs->setDefaultLang($languagecodeformember); $outputlangs->loadLangs(array("main", "members")); dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a593e70a7f6..0a81f729fc8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6829,7 +6829,8 @@ function picto_from_langcode($codelang, $moreatt = '') } /** - * Return default language from country code + * Return default language from country code. + * Return null if not found. * * @param string $countrycode Country code like 'US', 'FR', 'CA', ... * @return string Value of locale like 'en_US', 'fr_FR', ... @@ -6838,6 +6839,8 @@ function getLanguageCodeFromCountryCode($countrycode) { global $mysoc; + if (empty($countrycode)) return null; + if (strtoupper($countrycode) == 'MQ') return 'fr_CA'; if (strtoupper($countrycode) == 'SE') return 'sv_SE'; // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country if (strtoupper($countrycode) == 'CH')