Add automatic translation of month names for main time names in splitter

This commit is contained in:
Joshua Ramon Enslin 2020-09-18 21:24:21 +02:00 committed by Stefan Rohde-Enslin
parent 130140e910
commit 4aa2a5df2f
2 changed files with 21 additions and 8 deletions

View File

@ -12,6 +12,9 @@ require_once __DIR__ . '/inc/datesByCountry.php';
*/ */
class NodaTimeAutotranslater { class NodaTimeAutotranslater {
const USECASE_MONTH = 1;
const USECASE_DAY = 2;
const LANGS_TO_LOCALES = [ const LANGS_TO_LOCALES = [
'ar' => 'ar_SY.utf8', 'ar' => 'ar_SY.utf8',
'de' => 'de_DE.utf8', 'de' => 'de_DE.utf8',
@ -77,11 +80,11 @@ class NodaTimeAutotranslater {
if (trim($timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") { if (trim($timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") {
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01"; $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01";
$usecase = "month"; $usecase = self::USECASE_MONTH;
} }
else { else {
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-{$timeInfo['zeit_zaehlzeit_tag']} 00:00:01"; $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-{$timeInfo['zeit_zaehlzeit_tag']} 00:00:01";
$usecase = "day"; $usecase = self::USECASE_DAY;
} }
$dateGeneral = strtotime($dateStr); $dateGeneral = strtotime($dateStr);
@ -90,8 +93,8 @@ class NodaTimeAutotranslater {
setlocale(LC_TIME, $locale); setlocale(LC_TIME, $locale);
if ($locale !== setlocale(LC_TIME, "0")) continue; if ($locale !== setlocale(LC_TIME, "0")) continue;
if ($usecase === "month") $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0); if ($usecase === self::USECASE_MONTH) $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0);
else if ($usecase === "day") $tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0); else if ($usecase === self::USECASE_DAY) $tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0);
$this->_insertStmt->bind_param("iss", $this->_znum, $tLang, $tLangValue); $this->_insertStmt->bind_param("iss", $this->_znum, $tLang, $tLangValue);
$this->_insertStmt->execute(); $this->_insertStmt->execute();

View File

@ -171,6 +171,10 @@ final class NodaTimeSplitter {
else if ($moda[0] === $moda[1] && trim($moda[2], " 0") === "" && trim($moda[3], " 0") === "") { else if ($moda[0] === $moda[1] && trim($moda[2], " 0") === "" && trim($moda[3], " 0") === "") {
return "{$moda[0]}"; return "{$moda[0]}";
} }
else if ($moda[0] === $moda[1] && trim($moda[2], " 0") !== "" && trim($moda[3], " 0") === "") {
setlocale(LC_TIME, NodaTimeAutotranslater::LANGS_TO_LOCALES['de']);
return strftime(getMonthFormatByLang("de"), strtotime("{$moda[0]}-{$moda[2]}-01 01:01:01"));
}
return ""; return "";
@ -211,10 +215,16 @@ final class NodaTimeSplitter {
$output .= "&zeit_name_neu={$newTimeName}"; $output .= "&zeit_name_neu={$newTimeName}";
} }
$output .= '&zeit_beginn_neu=' . $moda[0] . '&zeit_ende_neu=' . $moda[1] . '&zeit_zaehlzeit_vorzeichen_neu=%2B&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda[2] . '&zeit_zaehlzeit_tag_neu=' . $moda[3] . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+'; $output .= '&zeit_beginn_neu=' . $moda[0] . '&zeit_ende_neu=' . $moda[1] . '&zeit_zaehlzeit_vorzeichen_neu=%2B&zeit_zaehlzeit_jahr_neu=' . $zaehlzeit_jahr . '&zeit_zaehlzeit_monat_neu=' . $moda[2] . '&zeit_zaehlzeit_tag_neu=' . $moda[3] . '&zeit_status_neu=%2B" class="icons iconsBell buttonLike" id="splitTimeLink">+';
if (!empty(trim($moda[3], " 0")) and !empty(trim($moda[2], " 0"))) $output .= $moda[3] . '.' . $moda[2] . '.' . $moda[0];
else if ($moda[0] !== $moda[1]) $output .= $moda[0] . "-" . $moda[1]; if (!empty($newTimeName)) {
else if (!empty(trim($moda[2], " 0"))) $output .= "{$moda[2]}.{$moda[0]}"; $output .= $newTimeName;
else $output .= $moda[0]; }
else {
if (!empty(trim($moda[3], " 0")) and !empty(trim($moda[2], " 0"))) $output .= $moda[3] . '.' . $moda[2] . '.' . $moda[0];
else if ($moda[0] !== $moda[1]) $output .= $moda[0] . "-" . $moda[1];
else if (!empty(trim($moda[2], " 0"))) $output .= "{$moda[2]}.{$moda[0]}";
else $output .= $moda[0];
}
$output .= ' - ' . $tlLoader->tl("tempi", "tempi", "time_disassemble") . '</a></td>'; $output .= ' - ' . $tlLoader->tl("tempi", "tempi", "time_disassemble") . '</a></td>';
$output .= '</tr>'; $output .= '</tr>';
$output .= '</table>'; $output .= '</table>';