Enable autotranslating of times 'after' a certain date
This commit is contained in:
parent
5e90e5d3f2
commit
c9a1a74bce
|
@ -625,6 +625,41 @@ final class NodaTimeAutotranslater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translated years or timespans below 1000 CE.
|
||||||
|
*
|
||||||
|
* @param array<integer|string> $timeInfo Time information.
|
||||||
|
*
|
||||||
|
* @return array<string>
|
||||||
|
*/
|
||||||
|
public static function translateYearsAfterStart(array $timeInfo):array {
|
||||||
|
|
||||||
|
if (empty(trim($timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
|
||||||
|
$timeInfo['zeit_beginn'] = strval(intval($timeInfo['zeit_beginn']) - 1);
|
||||||
|
}
|
||||||
|
else if (empty(trim($timeInfo['zeit_zaehlzeit_tag'], " ,.;0"))) {
|
||||||
|
$timeInfo['zeit_zaehlzeit_monat'] = strval(intval($timeInfo['zeit_zaehlzeit_monat']) - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$timeInfo['zeit_zaehlzeit_tag'] = strval(intval($timeInfo['zeit_zaehlzeit_tag']) - 1);
|
||||||
|
}
|
||||||
|
# else throw new Exception("Unhandled split case. Counting time is: " . var_export($timeInfo, true));
|
||||||
|
$innerTimeInfo = $timeInfo;
|
||||||
|
$innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn'];
|
||||||
|
$output = [];
|
||||||
|
|
||||||
|
foreach (self::LANGS_AFTER_START_FORMAT_YEAR as $tLang => $format) {
|
||||||
|
|
||||||
|
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
|
||||||
|
|
||||||
|
$timeName = sprintf($format, $dateAlone);
|
||||||
|
$output[$tLang] = $timeName;
|
||||||
|
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translated years or timespans below 1000 CE.
|
* Translated years or timespans below 1000 CE.
|
||||||
*
|
*
|
||||||
|
@ -636,6 +671,10 @@ final class NodaTimeAutotranslater {
|
||||||
|
|
||||||
$start = intval($timeInfo['zeit_beginn']);
|
$start = intval($timeInfo['zeit_beginn']);
|
||||||
|
|
||||||
|
if (substr($timeInfo['zeit_name'], 0, 5) === "Nach ") {
|
||||||
|
return self::translateYearsAfterStart($timeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
$innerTimeInfo = $timeInfo;
|
$innerTimeInfo = $timeInfo;
|
||||||
$innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn'];
|
$innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn'];
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
|
@ -578,10 +578,10 @@ final class NodaTimeSplitter {
|
||||||
$month = "0" . substr($datum, 0, 1);
|
$month = "0" . substr($datum, 0, 1);
|
||||||
return [$start, $start, $month, "00", "+", ""];
|
return [$start, $start, $month, "00", "+", ""];
|
||||||
}
|
}
|
||||||
if (preg_match("/^[0-9]{4}\.[0-9]{2}$/", $datum)) { // Hungarian Y-m
|
if (preg_match("/^[0-9]{4}\.[0-9]{2}(\.|)$/", $datum)) { // Hungarian Y-m
|
||||||
$start = substr($datum, 0, 4);
|
$start = substr($datum, 0, 4);
|
||||||
$month = substr($datum, 5, 2);
|
$month = substr($datum, 5, 2);
|
||||||
return [$start, $start, $month, "00", "+", ""];
|
if (intval($month) < 13) return [$start, $start, $month, "00", "+", ""];
|
||||||
}
|
}
|
||||||
if (preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // Time spans: 1945-46
|
if (preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // Time spans: 1945-46
|
||||||
$start = substr($datum, 0, 4);
|
$start = substr($datum, 0, 4);
|
||||||
|
|
|
@ -310,6 +310,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateCenturiesBeforeCommonEra():void {
|
public function testCanTranslateCenturiesBeforeCommonEra():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "20.-19. Jahrhundert v. Chr.",
|
||||||
"zeit_beginn" => "-2000",
|
"zeit_beginn" => "-2000",
|
||||||
"zeit_ende" => "-1801",
|
"zeit_ende" => "-1801",
|
||||||
"zeit_zaehlzeit_jahr" => "1900",
|
"zeit_zaehlzeit_jahr" => "1900",
|
||||||
|
@ -332,6 +333,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateYYYYUntilYYYY():void {
|
public function testCanTranslateYYYYUntilYYYY():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "1000-1150",
|
||||||
"zeit_beginn" => "1000",
|
"zeit_beginn" => "1000",
|
||||||
"zeit_ende" => "1150",
|
"zeit_ende" => "1150",
|
||||||
"zeit_zaehlzeit_jahr" => "1075",
|
"zeit_zaehlzeit_jahr" => "1075",
|
||||||
|
@ -354,6 +356,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateSingleYear():void {
|
public function testCanTranslateSingleYear():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "1000",
|
||||||
"zeit_beginn" => "1000",
|
"zeit_beginn" => "1000",
|
||||||
"zeit_ende" => "1000",
|
"zeit_ende" => "1000",
|
||||||
"zeit_zaehlzeit_jahr" => "1000",
|
"zeit_zaehlzeit_jahr" => "1000",
|
||||||
|
@ -376,6 +379,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateSingleThreeDigitYearBeforeCommonEra():void {
|
public function testCanTranslateSingleThreeDigitYearBeforeCommonEra():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "100 v. Chr.",
|
||||||
"zeit_beginn" => "-100",
|
"zeit_beginn" => "-100",
|
||||||
"zeit_ende" => "-100",
|
"zeit_ende" => "-100",
|
||||||
"zeit_zaehlzeit_jahr" => "100",
|
"zeit_zaehlzeit_jahr" => "100",
|
||||||
|
@ -398,6 +402,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateSingleYearBeforeCommonEra():void {
|
public function testCanTranslateSingleYearBeforeCommonEra():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "1000 v. Chr.",
|
||||||
"zeit_beginn" => "-1000",
|
"zeit_beginn" => "-1000",
|
||||||
"zeit_ende" => "-1000",
|
"zeit_ende" => "-1000",
|
||||||
"zeit_zaehlzeit_jahr" => "1000",
|
"zeit_zaehlzeit_jahr" => "1000",
|
||||||
|
@ -420,6 +425,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateYYYYUntilYYYYBefore1000():void {
|
public function testCanTranslateYYYYUntilYYYYBefore1000():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "800-850 n. Chr.",
|
||||||
"zeit_beginn" => "800",
|
"zeit_beginn" => "800",
|
||||||
"zeit_ende" => "850",
|
"zeit_ende" => "850",
|
||||||
"zeit_zaehlzeit_jahr" => "0825",
|
"zeit_zaehlzeit_jahr" => "0825",
|
||||||
|
@ -442,6 +448,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateYYYYUntilYYYYBeforeCommonEra():void {
|
public function testCanTranslateYYYYUntilYYYYBeforeCommonEra():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "1156-1102 v. Chr.",
|
||||||
"zeit_beginn" => "-1156",
|
"zeit_beginn" => "-1156",
|
||||||
"zeit_ende" => "-1102",
|
"zeit_ende" => "-1102",
|
||||||
"zeit_zaehlzeit_jahr" => "1075",
|
"zeit_zaehlzeit_jahr" => "1075",
|
||||||
|
@ -464,6 +471,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateSinceSingleDay():void {
|
public function testCanTranslateSinceSingleDay():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "Seit 01.05.1920",
|
||||||
"zeit_beginn" => "1920",
|
"zeit_beginn" => "1920",
|
||||||
"zeit_ende" => "?",
|
"zeit_ende" => "?",
|
||||||
"zeit_zaehlzeit_jahr" => "1920",
|
"zeit_zaehlzeit_jahr" => "1920",
|
||||||
|
@ -486,6 +494,7 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
public function testCanTranslateSinceSingleMonth():void {
|
public function testCanTranslateSinceSingleMonth():void {
|
||||||
|
|
||||||
$timeInfo = [
|
$timeInfo = [
|
||||||
|
"zeit_name" => "Seit Mai 1920",
|
||||||
"zeit_beginn" => "1920",
|
"zeit_beginn" => "1920",
|
||||||
"zeit_ende" => "?",
|
"zeit_ende" => "?",
|
||||||
"zeit_zaehlzeit_jahr" => "1920",
|
"zeit_zaehlzeit_jahr" => "1920",
|
||||||
|
@ -497,4 +506,73 @@ final class NodaTimeAutotranslaterTest extends TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check whether the HTML page is correctly generated.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
* @group ValidOutput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCanTranslateAfterSingleYear():void {
|
||||||
|
|
||||||
|
$timeInfo = [
|
||||||
|
"zeit_name" => "Nach 1919",
|
||||||
|
"zeit_beginn" => "1920",
|
||||||
|
"zeit_ende" => "?",
|
||||||
|
"zeit_zaehlzeit_jahr" => "1919",
|
||||||
|
"zeit_zaehlzeit_monat" => "00",
|
||||||
|
"zeit_zaehlzeit_tag" => "00",
|
||||||
|
];
|
||||||
|
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||||
|
self::assertEquals($output["de"], "Nach 1919");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check whether the HTML page is correctly generated.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
* @group ValidOutput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCanTranslateAfterSingleMonth():void {
|
||||||
|
|
||||||
|
$timeInfo = [
|
||||||
|
"zeit_name" => "Nach April 1920",
|
||||||
|
"zeit_beginn" => "1920",
|
||||||
|
"zeit_ende" => "?",
|
||||||
|
"zeit_zaehlzeit_jahr" => "1920",
|
||||||
|
"zeit_zaehlzeit_monat" => "05",
|
||||||
|
"zeit_zaehlzeit_tag" => "00",
|
||||||
|
];
|
||||||
|
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||||
|
self::assertEquals($output["de"], "Nach April 1920");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check whether the HTML page is correctly generated.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
* @group ValidOutput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCanTranslateAfterSingleDay():void {
|
||||||
|
|
||||||
|
$timeInfo = [
|
||||||
|
"zeit_name" => "Nach 01.12.1919",
|
||||||
|
"zeit_beginn" => "1919",
|
||||||
|
"zeit_ende" => "?",
|
||||||
|
"zeit_zaehlzeit_jahr" => "1919",
|
||||||
|
"zeit_zaehlzeit_monat" => "12",
|
||||||
|
"zeit_zaehlzeit_tag" => "02",
|
||||||
|
];
|
||||||
|
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||||
|
self::assertEquals($output["de"], "Nach 01.12.1919");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user