Enable automatic translations of times "before" a given date
This commit is contained in:
parent
1685d78f65
commit
1f4d692fb5
|
@ -685,6 +685,35 @@ final class NodaTimeAutotranslater {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Translated years or timespans below 1000 CE.
|
||||
*
|
||||
* @param array<integer|string> $timeInfo Time information.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function translateYearsBeforeEnd(array $timeInfo):array {
|
||||
|
||||
if (empty(trim($timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
|
||||
$timeInfo['zeit_ende'] = strval(intval($timeInfo['zeit_ende']) + 1);
|
||||
}
|
||||
$end = intval($timeInfo['zeit_ende']);
|
||||
|
||||
$innerTimeInfo = $timeInfo;
|
||||
$innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende'];
|
||||
|
||||
$output = [];
|
||||
foreach (self::LANGS_BEFORE_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.
|
||||
*
|
||||
|
@ -696,6 +725,10 @@ final class NodaTimeAutotranslater {
|
|||
|
||||
$end = intval($timeInfo['zeit_ende']);
|
||||
|
||||
if (substr($timeInfo['zeit_name'], 0, 4) === "Vor ") {
|
||||
return self::translateYearsBeforeEnd($timeInfo);
|
||||
}
|
||||
|
||||
$innerTimeInfo = $timeInfo;
|
||||
$innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende'];
|
||||
|
||||
|
|
|
@ -575,4 +575,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 testCanTranslateBeforeSingleYear():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_name" => "Vor 1919",
|
||||
"zeit_beginn" => "?",
|
||||
"zeit_ende" => "1918",
|
||||
"zeit_zaehlzeit_jahr" => "1919",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Vor 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 testCanTranslateBeforeSingleMonth():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_name" => "Vor Mai 1920",
|
||||
"zeit_beginn" => "?",
|
||||
"zeit_ende" => "1920",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "05",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Vor Mai 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 testCanTranslateBeforeSingleDay():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_name" => "Vor 01.12.1919",
|
||||
"zeit_beginn" => "?",
|
||||
"zeit_ende" => "1919",
|
||||
"zeit_zaehlzeit_jahr" => "1919",
|
||||
"zeit_zaehlzeit_monat" => "12",
|
||||
"zeit_zaehlzeit_tag" => "01",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Vor 01.12.1919");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user