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 () {
// 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
toastr.options = {
"closeButton": true,
@ -39,7 +35,7 @@ $(document).ready(function () {
};
// Imposta lo standard per la conversione dei numeri
numeral.register('locale', 'it', {
numeral.register('locale', 'current', {
delimiters: {
thousands: globals.thousands,
decimal: globals.decimals,
@ -54,12 +50,9 @@ $(document).ready(function () {
symbol: '€'
}
});
numeral.locale('it');
numeral.locale('current');
numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali));
// Orologio
clock();
// Richiamo alla generazione di Datatables
start_datatables();

View File

@ -3,9 +3,7 @@ function start_local_datatables(){
$('.datatables').each(function () {
if (!$.fn.DataTable.isDataTable($(this))) {
$(this).DataTable({
language: {
url: globals.js + "/i18n/datatables/" + globals.locale + ".min.json"
},
language: globals.translations.datatables,
retrieve: true,
ordering: true,
searching: true,
@ -52,9 +50,7 @@ function start_datatables() {
var tempo_attesa_ricerche = (globals.tempo_attesa_ricerche * 1000);
var table = $this.DataTable({
language: {
url: globals.js + '/i18n/datatables/' + globals.locale + '.min.json'
},
language: globals.translations.datatables,
autoWidth: true,
dom: "ti",
serverSide: true,
@ -133,10 +129,9 @@ function start_datatables() {
format: {
body: function(data, row, column, node) {
data = $('<p>' + data + '</p>').text();
data_edit = data.replace('.', '');
data_edit = data_edit.replace(',', '.');
data_edit = data.toEnglish();
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'
};
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 () {
$this = $(this);
$this.datetimepicker({
format: timestamp_format,
locale: globals.locale,
icons: icons,
collapse: false,
@ -44,10 +49,10 @@ function start_datepickers() {
$('.datepicker').each(function () {
$this = $(this);
$this.datetimepicker({
format: date_format,
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'L',
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
});
@ -56,10 +61,10 @@ function start_datepickers() {
$('.timepicker').each(function () {
$this = $(this);
$this.datetimepicker({
format: time_format,
locale: globals.locale,
icons: icons,
useCurrent: false,
format: 'LT',
stepping: 5,
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-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.lastYear] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')];
var format = dateFormatMoment(globals.date_format);
$(id).daterangepicker({
locale: {
format: format,
customRangeLabel: globals.translations.custom,
applyLabel: globals.translations.apply,
cancelLabel: globals.translations.cancel,

View File

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

View File

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

@ -54,6 +54,9 @@ if (Auth::check()) {
<script>
$(document).ready(function() {
alertPush();
// Orologio
clock();
$.ajax({
url: globals.rootdir + "/ajax.php",
@ -78,7 +81,6 @@ if (Auth::check()) {
},
});
});
</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">';
$languages = [
'it' => [
'it_IT' => [
'title' => tr('Italiano'),
'flag' => 'IT',
],
'en' => [
'en_GB' => [
'title' => tr('Inglese'),
'flag' => 'GB',
],

View File

@ -101,7 +101,7 @@ if (Auth::check()) {
'.$key.': "'.addslashes($value).'",';
}
echo '
password: {
password: {
"wordMinLength": "'.tr('La password è troppo corta').'",
"wordMaxLength": "'.tr('La password è troppo lunga').'",
"wordInvalidChar": "'.tr('La password contiene un carattere non valido').'",
@ -118,6 +118,24 @@ if (Auth::check()) {
"strong": "'.tr('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 = {
rootdir: "'.$rootdir.'",
@ -132,14 +150,17 @@ if (Auth::check()) {
cifre_decimali: '.setting('Cifre decimali per importi').',
timestamp_format: "'.formatter()->getTimestampPattern().'",
date_format: "'.formatter()->getDatePattern().'",
time_format: "'.formatter()->getTimePattern().'",
decimals: "'.formatter()->getNumberSeparators()['decimals'].'",
thousands: "'.formatter()->getNumberSeparators()['thousands'].'",
currency: "'.currency().'",
search: search,
translations: translations,
locale: "'.$lang.'",
full_locale: "'.$lang.'_'.strtoupper($lang).'",
locale: "'.(explode('_', $lang)[0]).'",
full_locale: "'.$lang.'",
start_date: "'.$_SESSION['period_start'].'",
start_date_formatted: "'.Translator::dateToLocale($_SESSION['period_start']).'",
@ -182,8 +203,12 @@ if (Auth::check()) {
},
},
locale: "'.$lang.'",
full_locale: "'.$lang.'_'.strtoupper($lang).'",
timestamp_format: "'.formatter()->getTimestampPattern().'",
date_format: "'.formatter()->getDatePattern().'",
time_format: "'.formatter()->getTimePattern().'",
locale: "'.(explode('_', $lang)[0]).'",
full_locale: "'.$lang.'",
};
</script>';
}
@ -274,13 +299,13 @@ if (Auth::check()) {
<li><a href="#" id="daterange" style="color:'.$calendar.';" role="button" >
<i class="fa fa-calendar" style="color:inherit"></i> <i class="fa fa-caret-down" style="color:inherit"></i>
</a></li>
<li><a style="color:'.$calendar.';background:inherit;cursor:default;">
'.Translator::dateToLocale($_SESSION['period_start']).' - '.Translator::dateToLocale($_SESSION['period_end']).'
</a></li>
</ul>
</div>
<!-- Navbar Right Menu -->
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
@ -296,33 +321,33 @@ if (Auth::check()) {
<ul class="dropdown-menu">
<li class="header"><span class="small" id="hooks-header"></span></li>
<li><ul class="menu" id="hooks">
</ul></li>
</ul>
</li>
<li><a href="#" onclick="window.print()" class="tip" title="'.tr('Stampa').'">
<i class="fa fa-print"></i>
</a></li>
<li><a href="'.$rootdir.'/bug.php" class="tip"title="'.tr('Segnalazione bug').'">
<i class="fa fa-bug"></i>
</a></li>
<li><a href="'.$rootdir.'/log.php" class="tip"title="'.tr('Log accessi').'">
<i class="fa fa-book"></i>
</a></li>
<li><a href="'.$rootdir.'/info.php" class="tip"title="'.tr('Informazioni').'">
<i class="fa fa-info"></i>
</a></li>
<li><a href="'.$rootdir.'/index.php?op=logout" onclick="sessionStorage.clear()" class="bg-red tip" title="'.tr('Esci').'">
<i class="fa fa-power-off"></i>
</a></li>
</ul>
</div>
</nav>
</header>

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
$("#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à
@ -430,9 +431,9 @@ if (!empty($id_intervento)) {
if ($(this).selectData() && (($(this).selectData().tempo_standard)>0) && ('<?php echo filter('orario_fine'); ?>' == '')){
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');
$('#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 () {
// Quando modifico orario inizio, allineo anche l\'orario fine
$("#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() {

View File

@ -66,6 +66,7 @@ class App
// Operazioni di normalizzazione sulla configurazione
$result['debug'] = isset(self::$config['debug']) ? self::$config['debug'] : !empty($result['debug']);
$result['lang'] = $result['lang'] == 'it' ? 'it_IT' : $result['lang'];
self::$config = $result;
}
@ -175,6 +176,16 @@ class App
'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 = [];
foreach ($sections as $section => $dir) {
@ -182,7 +193,15 @@ class App
foreach ($result as $key => $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;
}
@ -190,12 +209,6 @@ class App
$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;
}

View File

@ -22,7 +22,7 @@ class Translator extends Util\Singleton
/** @var string Lingua selezionata */
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->setFallbackLocales($fallback_locales);