Droppped momentjs in favor of Intl

Uses a fallback for Intl.RelativeTimeFormat in Date.prototype.fromNow
This commit is contained in:
djmaze 2020-10-15 10:45:18 +02:00
parent 6f585e1f1d
commit 3bfe2c67d1
17 changed files with 478 additions and 97 deletions

View file

@ -1071,17 +1071,16 @@ class ServiceActions
$sLanguage = strtr($sLanguage, '_', '-');
$sMoment = 'window.moment && window.moment.locale && window.moment.locale(\'en\');';
$options = [$sLanguage, \substr($sLanguage, 0, 2)];
$sTimeFormat = '';
$options = [$sLanguage, \substr($sLanguage, 0, 2), 'en'];
foreach ($options as $lang) {
$sMomentFileName = APP_VERSION_ROOT_PATH.'app/localization/moment/'.$lang.'.js';
if (\is_file($sMomentFileName)) {
$sMoment = \file_get_contents($sMomentFileName);
$sMoment = \preg_replace('/\/\/[^\n]+\n/', '', $sMoment);
$sFileName = APP_VERSION_ROOT_PATH.'app/localization/relativetimeformat/'.$lang.'.json';
if (\is_file($sFileName)) {
$sTimeFormat = \preg_replace('/^\\s+/', '', \file_get_contents($sFileName));
break;
}
}
return 'document.documentElement.lang = "'.$sLanguage.'";window.rainloopI18N='.$sResult.';'.$sMoment;
return "document.documentElement.lang = '{$sLanguage}';\nwindow.rainloopI18N={$sResult};\nDate.defineRelativeTimeFormat({$sTimeFormat});";
}
}