🐛 Fix datepicker locale not set correctly for ZH CN and PT BR

Reused code made by @annProg in PR #40, many thanks !
This commit is contained in:
Pierre Goiffon
2019-02-27 12:36:29 +01:00
parent 49e31ddb3d
commit 06592d7d37
3 changed files with 17 additions and 8 deletions

View File

@@ -219,7 +219,6 @@ EOF;
);
$sTimeFormat = AttributeDateTime::GetFormat()->ToTimeFormat();
$oTimeFormat = new DateTimeFormat($sTimeFormat);
$sJSLangShort = json_encode(strtolower(substr(Dict::GetUserLanguage(), 0, 2)));
// Date picker options
$aPickerOptions = array(
@@ -237,21 +236,23 @@ EOF;
$sJSDatePickerOptions = json_encode($aPickerOptions);
// Time picker additional options
$sUserLang = Dict::GetUserLanguage();
$sTimePickerLang = json_encode(Dict::S('INTERNAL:JQuery-DatePicker:LangCode', $sUserLang));
$aPickerOptions['showOn'] = '';
$aPickerOptions['buttonImage'] = null;
$aPickerOptions['timeFormat'] = $oTimeFormat->ToDatePicker();
$aPickerOptions['controlType'] = 'select';
$aPickerOptions['closeText'] = Dict::S('UI:Button:Ok');
$sJSDateTimePickerOptions = json_encode($aPickerOptions);
if ($sJSLangShort != '"en"')
if ($sTimePickerLang != '"en"')
{
// More options that cannot be passed via json_encode since they must be evaluated client-side
$aMoreJSOptions = ",
'timeText': $.timepicker.regional[$sJSLangShort].timeText,
'hourText': $.timepicker.regional[$sJSLangShort].hourText,
'minuteText': $.timepicker.regional[$sJSLangShort].minuteText,
'secondText': $.timepicker.regional[$sJSLangShort].secondText,
'currentText': $.timepicker.regional[$sJSLangShort].currentText
'timeText': $.timepicker.regional[$sTimePickerLang].timeText,
'hourText': $.timepicker.regional[$sTimePickerLang].hourText,
'minuteText': $.timepicker.regional[$sTimePickerLang].minuteText,
'secondText': $.timepicker.regional[$sTimePickerLang].secondText,
'currentText': $.timepicker.regional[$sTimePickerLang].currentText
}";
$sJSDateTimePickerOptions = substr($sJSDateTimePickerOptions, 0, -1).$aMoreJSOptions;
}
@@ -259,7 +260,7 @@ EOF;
<<< EOF
function GetUserLanguage()
{
return $sJSLangShort;
return $sTimePickerLang;
}
function PrepareWidgets()
{

View File

@@ -21,6 +21,10 @@
* @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
Dict::Add('PT BR', 'Brazilian', 'Brazilian', array(
'INTERNAL:JQuery-DatePicker:LangCode' => 'pt-BR',
));
Dict::Add('PT BR', 'Brazilian', 'Brazilian', array(
'Core:DeletedObjectLabel' => '%1s (excluído)',
'Core:DeletedObjectTip' => 'O objeto foi excluído em %1$s (%2$s)',

View File

@@ -21,6 +21,10 @@
* along with iTop. If not, see <http://www.gnu.org/licenses/>
*/
Dict::Add('ZH CN', 'Chinese', '简体中文', array(
'INTERNAL:JQuery-DatePicker:LangCode' => 'zh-CN',
));
Dict::Add('ZH CN', 'Chinese', '简体中文', array(
'Core:DeletedObjectLabel' => '%1s (已删除)',
'Core:DeletedObjectTip' => 'The object has been deleted on %1$s (%2$s)',