Miglioramento localizzazione

This commit is contained in:
Thomas Zilio 2019-08-02 15:58:31 +02:00
parent 32b4d463d5
commit 395112245c
18 changed files with 1034 additions and 658 deletions

View File

@ -15,10 +15,6 @@ $(document).on('hidden.bs.modal', '.modal', function () {
}); });
$(document).ready(function () { $(document).ready(function () {
// Imposta la lingua per la gestione automatica delle date dei diversi plugin
moment.locale(globals.locale);
globals.timestampFormat = moment.localeData().longDateFormat('L') + ' ' + moment.localeData().longDateFormat('LT');
// Standard per i popup // Standard per i popup
toastr.options = { toastr.options = {
"closeButton": true, "closeButton": true,
@ -39,7 +35,7 @@ $(document).ready(function () {
}; };
// Imposta lo standard per la conversione dei numeri // Imposta lo standard per la conversione dei numeri
numeral.register('locale', 'it', { numeral.register('locale', 'current', {
delimiters: { delimiters: {
thousands: globals.thousands, thousands: globals.thousands,
decimal: globals.decimals, decimal: globals.decimals,
@ -54,12 +50,9 @@ $(document).ready(function () {
symbol: '€' symbol: '€'
} }
}); });
numeral.locale('it'); numeral.locale('current');
numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali)); numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali));
// Orologio
clock();
// Richiamo alla generazione di Datatables // Richiamo alla generazione di Datatables
start_datatables(); start_datatables();

View File

@ -3,9 +3,7 @@ function start_local_datatables(){
$('.datatables').each(function () { $('.datatables').each(function () {
if (!$.fn.DataTable.isDataTable($(this))) { if (!$.fn.DataTable.isDataTable($(this))) {
$(this).DataTable({ $(this).DataTable({
language: { language: globals.translations.datatables,
url: globals.js + "/i18n/datatables/" + globals.locale + ".min.json"
},
retrieve: true, retrieve: true,
ordering: true, ordering: true,
searching: true, searching: true,
@ -52,9 +50,7 @@ function start_datatables() {
var tempo_attesa_ricerche = (globals.tempo_attesa_ricerche * 1000); var tempo_attesa_ricerche = (globals.tempo_attesa_ricerche * 1000);
var table = $this.DataTable({ var table = $this.DataTable({
language: { language: globals.translations.datatables,
url: globals.js + '/i18n/datatables/' + globals.locale + '.min.json'
},
autoWidth: true, autoWidth: true,
dom: "ti", dom: "ti",
serverSide: true, serverSide: true,
@ -133,10 +129,9 @@ function start_datatables() {
format: { format: {
body: function(data, row, column, node) { body: function(data, row, column, node) {
data = $('<p>' + data + '</p>').text(); data = $('<p>' + data + '</p>').text();
data_edit = data.replace('.', ''); data_edit = data.toEnglish();
data_edit = data_edit.replace(',', '.');
return data_edit.match(/^[0-9\.]+$/) ? data_edit : data; return data_edit ? data_edit : data;
} }
} }
} }

View File

@ -12,9 +12,14 @@ function start_datepickers() {
close: 'fa fa-times' close: 'fa fa-times'
}; };
var date_format = dateFormatMoment(globals.date_format);
var timestamp_format = dateFormatMoment(globals.timestamp_format);
var time_format = dateFormatMoment(globals.time_format);
$('.timestamp-picker').each(function () { $('.timestamp-picker').each(function () {
$this = $(this); $this = $(this);
$this.datetimepicker({ $this.datetimepicker({
format: timestamp_format,
locale: globals.locale, locale: globals.locale,
icons: icons, icons: icons,
collapse: false, collapse: false,
@ -44,10 +49,10 @@ function start_datepickers() {
$('.datepicker').each(function () { $('.datepicker').each(function () {
$this = $(this); $this = $(this);
$this.datetimepicker({ $this.datetimepicker({
format: date_format,
locale: globals.locale, locale: globals.locale,
icons: icons, icons: icons,
useCurrent: false, useCurrent: false,
format: 'L',
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false, minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false, maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
}); });
@ -56,10 +61,10 @@ function start_datepickers() {
$('.timepicker').each(function () { $('.timepicker').each(function () {
$this = $(this); $this = $(this);
$this.datetimepicker({ $this.datetimepicker({
format: time_format,
locale: globals.locale, locale: globals.locale,
icons: icons, icons: icons,
useCurrent: false, useCurrent: false,
format: 'LT',
stepping: 5, stepping: 5,
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false, minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false, maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
@ -81,8 +86,10 @@ function start_complete_calendar(id, callback) {
ranges[globals.translations.thisYear] = [moment().startOf('year'), moment().endOf('year')]; ranges[globals.translations.thisYear] = [moment().startOf('year'), moment().endOf('year')];
ranges[globals.translations.lastYear] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')]; ranges[globals.translations.lastYear] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')];
var format = dateFormatMoment(globals.date_format);
$(id).daterangepicker({ $(id).daterangepicker({
locale: { locale: {
format: format,
customRangeLabel: globals.translations.custom, customRangeLabel: globals.translations.custom,
applyLabel: globals.translations.apply, applyLabel: globals.translations.apply,
cancelLabel: globals.translations.cancel, cancelLabel: globals.translations.cancel,

View File

@ -93,7 +93,7 @@ function getUrlVars() {
// Data e ora (orologio) // Data e ora (orologio)
function clock() { function clock() {
$('#datetime').html(moment().format(globals.timestampFormat)); $('#datetime').html(moment().formatPHP(globals.timestamp_format));
setTimeout('clock()', 1000); setTimeout('clock()', 1000);
} }
@ -436,20 +436,21 @@ function renderMessages() {
success: function (flash) { success: function (flash) {
messages = JSON.parse(flash); messages = JSON.parse(flash);
info = messages.info ? messages.info : {}; info = messages.info ? messages.info : [];
Object.keys(info).forEach(function (element) { info.forEach(function (element) {
toastr["success"](info[element]); toastr["success"](element);
}); });
warning = messages.warning ? messages.warning : {}; warning = messages.warning ? messages.warning : [];
Object.keys(warning).forEach(function (element) { warning.forEach(function (element) {
toastr["warning"](warning[element]); toastr["warning"](element);
}); });
error = messages.error ? messages.error : {}; error = messages.error ? messages.error : [];
Object.keys(error).forEach(function (element) { error.forEach(function (element) {
toastr["error"](error[element]); toastr["error"](element);
}); });
} }
}); });
} }

View File

@ -7,7 +7,7 @@ function start_inputmask(element) {
element = element + ' '; element = element + ' ';
} }
var date = moment.localeData().longDateFormat('L').toLowerCase(); var date = dateFormatMoment(globals.date_format).toLowerCase();
$(element + ".date-mask").not('.bound').inputmask(date, { $(element + ".date-mask").not('.bound').inputmask(date, {
"placeholder": date "placeholder": date

View File

@ -0,0 +1,75 @@
function dateFormatMoment(format) {
/*
* PHP => moment.js
* Will take a php date format and convert it into a JS format for moment
* http://www.php.net/manual/en/function.date.php
* http://momentjs.com/docs/#/displaying/format/
*/
var formatMap = {
d: 'DD',
D: 'ddd',
j: 'D',
l: 'dddd',
N: 'E',
S: function () {
return '[' + moment().format('Do').replace(/\d*/g, '') + ']';
},
w: 'd',
z: function () {
return moment().format('DDD') - 1;
},
W: 'W',
F: 'MMMM',
m: 'MM',
M: 'MMM',
n: 'M',
t: function () {
return moment().daysInMonth();
},
L: function () {
return moment().isLeapYear() ? 1 : 0;
},
o: 'GGGG',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: function () {
var thisUTC = moment().clone().utc(),
// Shamelessly stolen from http://javascript.about.com/library/blswatch.htm
swatch = ((thisUTC.hours() + 1) % 24) + (thisUTC.minutes() / 60) + (thisUTC.seconds() / 3600);
return Math.floor(swatch * 1000 / 24);
},
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: '[u]', // not sure if moment has this
e: '[e]', // moment does not have this
I: function () {
return moment().isDST() ? 1 : 0;
},
O: 'ZZ',
P: 'Z',
T: '[T]', // deprecated in moment
Z: function () {
return parseInt(moment().format('ZZ'), 10) * 36;
},
c: 'YYYY-MM-DD[T]HH:mm:ssZ',
r: 'ddd, DD MMM YYYY HH:mm:ss ZZ',
U: 'X'
};
var formatEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g;
return format.replace(formatEx, function (phpStr) {
return typeof formatMap[phpStr] === 'function' ? formatMap[phpStr].call(that) : formatMap[phpStr];
})
}
(function (m) {
moment.fn.formatPHP = function (format) {
return this.format(dateFormatMoment(format));
};
}(moment));

View File

@ -1,23 +0,0 @@
{
"sEmptyTable": "Nessun dato presente nella tabella",
"sInfo": "Vista da _START_ a _END_ di _TOTAL_ elementi",
"sInfoEmpty": "Vista da 0 a 0 di 0 elementi",
"sInfoFiltered": "(filtrati da _MAX_ elementi totali)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "Visualizza _MENU_ elementi",
"sLoadingRecords": " ",
"sProcessing": "Elaborazione...",
"sSearch": "Cerca:",
"sZeroRecords": "La ricerca non ha portato alcun risultato.",
"oPaginate": {
"sFirst": "Inizio",
"sPrevious": "Precedente",
"sNext": "Successivo",
"sLast": "Fine"
},
"oAria": {
"sSortAscending": ": attiva per ordinare la colonna in ordine crescente",
"sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
}
}

View File

@ -55,6 +55,9 @@ if (Auth::check()) {
$(document).ready(function() { $(document).ready(function() {
alertPush(); alertPush();
// Orologio
clock();
$.ajax({ $.ajax({
url: globals.rootdir + "/ajax.php", url: globals.rootdir + "/ajax.php",
type: "get", type: "get",
@ -78,7 +81,6 @@ if (Auth::check()) {
}, },
}); });
}); });
</script>'; </script>';
} }

View File

@ -321,11 +321,11 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
<select class="form-control hide" id="language" required="1">'; <select class="form-control hide" id="language" required="1">';
$languages = [ $languages = [
'it' => [ 'it_IT' => [
'title' => tr('Italiano'), 'title' => tr('Italiano'),
'flag' => 'IT', 'flag' => 'IT',
], ],
'en' => [ 'en_GB' => [
'title' => tr('Inglese'), 'title' => tr('Inglese'),
'flag' => 'GB', 'flag' => 'GB',
], ],

View File

@ -101,7 +101,7 @@ if (Auth::check()) {
'.$key.': "'.addslashes($value).'",'; '.$key.': "'.addslashes($value).'",';
} }
echo ' echo '
password: { password: {
"wordMinLength": "'.tr('La password è troppo corta').'", "wordMinLength": "'.tr('La password è troppo corta').'",
"wordMaxLength": "'.tr('La password è troppo lunga').'", "wordMaxLength": "'.tr('La password è troppo lunga').'",
"wordInvalidChar": "'.tr('La password contiene un carattere non valido').'", "wordInvalidChar": "'.tr('La password contiene un carattere non valido').'",
@ -118,6 +118,24 @@ if (Auth::check()) {
"strong": "'.tr('Forte').'", "strong": "'.tr('Forte').'",
"veryStrong": "'.tr('Molto forte').'", "veryStrong": "'.tr('Molto forte').'",
}, },
datatables: {
"emptyTable": "'.tr('Nessun dato presente nella tabella').'",
"info": "'.tr('Vista da _START_ a _END_ di _TOTAL_ elementi').'",
"infoEmpty": "'.tr('Vista da 0 a 0 di 0 elementi').'",
"infoFiltered": "('.tr('filtrati da _MAX_ elementi totali').')",
"infoPostFix": "",
"lengthMenu": "'.tr('Visualizza _MENU_ elementi').'",
"loadingRecords": " ",
"processing": "'.tr('Elaborazione').'...",
"search": "'.tr('Cerca').':",
"zeroRecords": "'.tr('La ricerca non ha portato alcun risultato').'.",
"paginate": {
"first": "'.tr('Inizio').'",
"previous": "'.tr('Precedente').'",
"next": "'.tr('Successivo').'",
"last": "'.tr('Fine').'"
},
},
}; };
globals = { globals = {
rootdir: "'.$rootdir.'", rootdir: "'.$rootdir.'",
@ -132,14 +150,17 @@ if (Auth::check()) {
cifre_decimali: '.setting('Cifre decimali per importi').', cifre_decimali: '.setting('Cifre decimali per importi').',
timestamp_format: "'.formatter()->getTimestampPattern().'",
date_format: "'.formatter()->getDatePattern().'",
time_format: "'.formatter()->getTimePattern().'",
decimals: "'.formatter()->getNumberSeparators()['decimals'].'", decimals: "'.formatter()->getNumberSeparators()['decimals'].'",
thousands: "'.formatter()->getNumberSeparators()['thousands'].'", thousands: "'.formatter()->getNumberSeparators()['thousands'].'",
currency: "'.currency().'", currency: "'.currency().'",
search: search, search: search,
translations: translations, translations: translations,
locale: "'.$lang.'", locale: "'.(explode('_', $lang)[0]).'",
full_locale: "'.$lang.'_'.strtoupper($lang).'", full_locale: "'.$lang.'",
start_date: "'.$_SESSION['period_start'].'", start_date: "'.$_SESSION['period_start'].'",
start_date_formatted: "'.Translator::dateToLocale($_SESSION['period_start']).'", start_date_formatted: "'.Translator::dateToLocale($_SESSION['period_start']).'",
@ -182,8 +203,12 @@ if (Auth::check()) {
}, },
}, },
locale: "'.$lang.'", timestamp_format: "'.formatter()->getTimestampPattern().'",
full_locale: "'.$lang.'_'.strtoupper($lang).'", date_format: "'.formatter()->getDatePattern().'",
time_format: "'.formatter()->getTimePattern().'",
locale: "'.(explode('_', $lang)[0]).'",
full_locale: "'.$lang.'",
}; };
</script>'; </script>';
} }

File diff suppressed because it is too large Load Diff

View File

@ -341,7 +341,8 @@ if (!empty($id_intervento)) {
// Quando modifico orario inizio, allineo anche l'orario fine // Quando modifico orario inizio, allineo anche l'orario fine
$("#bs-popup #orario_inizio").on("dp.change", function (e) { $("#bs-popup #orario_inizio").on("dp.change", function (e) {
$("#bs-popup #orario_fine").data("DateTimePicker").minDate(e.date).format(globals.timestampFormat); $("#bs-popup #orario_fine").data("DateTimePicker").minDate(e.date);
$("#bs-popup #orario_fine").change();
}); });
// Refresh modulo dopo la chiusura di una pianificazione attività derivante dalle attività // Refresh modulo dopo la chiusura di una pianificazione attività derivante dalle attività
@ -430,9 +431,9 @@ if (!empty($id_intervento)) {
if ($(this).selectData() && (($(this).selectData().tempo_standard)>0) && ('<?php echo filter('orario_fine'); ?>' == '')){ if ($(this).selectData() && (($(this).selectData().tempo_standard)>0) && ('<?php echo filter('orario_fine'); ?>' == '')){
tempo_standard = $(this).selectData().tempo_standard; tempo_standard = $(this).selectData().tempo_standard;
data = moment($('#bs-popup #orario_inizio').val(), globals.timestampFormat); data = moment($('#bs-popup #orario_inizio').val(), globals.timestamp_format);
orario_fine = data.add(tempo_standard, 'hours'); orario_fine = data.add(tempo_standard, 'hours');
$('#bs-popup #orario_fine').val(orario_fine.format(globals.timestampFormat)); $('#bs-popup #orario_fine').val(orario_fine.format(globals.timestamp_format));
} }
}); });

View File

@ -103,7 +103,8 @@ echo '
$(document).ready(function () { $(document).ready(function () {
// Quando modifico orario inizio, allineo anche l\'orario fine // Quando modifico orario inizio, allineo anche l\'orario fine
$("#orario_inizio").on("dp.change", function (e) { $("#orario_inizio").on("dp.change", function (e) {
$("#orario_fine").data("DateTimePicker").minDate(e.date).format(globals.timestampFormat); $("#orario_fine").data("DateTimePicker").minDate(e.date);
$("#orario_fine").change();
}); });
$("#idtipointerventot").change(function() { $("#idtipointerventot").change(function() {

View File

@ -66,6 +66,7 @@ class App
// Operazioni di normalizzazione sulla configurazione // Operazioni di normalizzazione sulla configurazione
$result['debug'] = isset(self::$config['debug']) ? self::$config['debug'] : !empty($result['debug']); $result['debug'] = isset(self::$config['debug']) ? self::$config['debug'] : !empty($result['debug']);
$result['lang'] = $result['lang'] == 'it' ? 'it_IT' : $result['lang'];
self::$config = $result; self::$config = $result;
} }
@ -175,6 +176,16 @@ class App
'js' => 'js', 'js' => 'js',
]; ];
$first_lang = explode('_', $lang);
$lang_replace = [
$lang,
strtolower($lang),
strtolower($first_lang[0]),
strtoupper($first_lang[0]),
str_replace('_', '-', $lang),
str_replace('_', '-', strtolower($lang)),
];
$assets = []; $assets = [];
foreach ($sections as $section => $dir) { foreach ($sections as $section => $dir) {
@ -182,7 +193,15 @@ class App
foreach ($result as $key => $element) { foreach ($result as $key => $element) {
$element = $paths[$dir].'/'.$element; $element = $paths[$dir].'/'.$element;
$element = str_replace('|lang|', $lang, $element);
foreach ($lang_replace as $replace) {
$name = str_replace('|lang|', $replace, $element);
if (file_exists(str_replace(ROOTDIR, DOCROOT, $name))) {
$element = $name;
break;
}
}
$result[$key] = $element; $result[$key] = $element;
} }
@ -190,12 +209,6 @@ class App
$assets[$section] = $result; $assets[$section] = $result;
} }
// JS aggiuntivi per gli utenti connessi
//if (Auth::check()) {
//$assets['js'][] = ROOTDIR.'/lib/functions.js';
//$assets['js'][] = ROOTDIR.'/lib/init.js';
//}
return $assets; return $assets;
} }

View File

@ -22,7 +22,7 @@ class Translator extends Util\Singleton
/** @var string Lingua selezionata */ /** @var string Lingua selezionata */
protected $locale; protected $locale;
public function __construct($default_locale = 'it', $fallback_locales = ['it']) public function __construct($default_locale = 'it_IT', $fallback_locales = ['it_IT'])
{ {
$translator = new Symfony\Component\Translation\Translator($default_locale); $translator = new Symfony\Component\Translation\Translator($default_locale);
$translator->setFallbackLocales($fallback_locales); $translator->setFallbackLocales($fallback_locales);