From 4aa2a5df2fe04bc77b5a1a06b9b41025884b137a Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Fri, 18 Sep 2020 21:24:21 +0200 Subject: [PATCH] Add automatic translation of month names for main time names in splitter --- src/NodaTimeAutotranslater.php | 11 +++++++---- src/NodaTimeSplitter.php | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/NodaTimeAutotranslater.php b/src/NodaTimeAutotranslater.php index ddc0ea2..9c9e805 100644 --- a/src/NodaTimeAutotranslater.php +++ b/src/NodaTimeAutotranslater.php @@ -12,6 +12,9 @@ require_once __DIR__ . '/inc/datesByCountry.php'; */ class NodaTimeAutotranslater { + const USECASE_MONTH = 1; + const USECASE_DAY = 2; + const LANGS_TO_LOCALES = [ 'ar' => 'ar_SY.utf8', 'de' => 'de_DE.utf8', @@ -77,11 +80,11 @@ class NodaTimeAutotranslater { if (trim($timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") { $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01"; - $usecase = "month"; + $usecase = self::USECASE_MONTH; } else { $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); @@ -90,8 +93,8 @@ class NodaTimeAutotranslater { setlocale(LC_TIME, $locale); if ($locale !== setlocale(LC_TIME, "0")) continue; - if ($usecase === "month") $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0); - else if ($usecase === "day") $tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0); + if ($usecase === self::USECASE_MONTH) $tLangValue = strftime(getMonthFormatByLang($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->execute(); diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 9e235ee..db2326d 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -171,6 +171,10 @@ final class NodaTimeSplitter { else if ($moda[0] === $moda[1] && trim($moda[2], " 0") === "" && trim($moda[3], " 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 ""; @@ -211,10 +215,16 @@ final class NodaTimeSplitter { $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">+'; - 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]; + + if (!empty($newTimeName)) { + $output .= $newTimeName; + } + 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") . ''; $output .= ''; $output .= '';