2020-09-18 18:48:40 +02:00
|
|
|
|
<?PHP
|
|
|
|
|
/**
|
|
|
|
|
* Controls automatic translation of times.
|
|
|
|
|
*
|
|
|
|
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
|
|
|
|
*/
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
require_once __DIR__ . '/inc/datesByCountry.php';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Autotranslater class for times.
|
|
|
|
|
*/
|
2020-09-18 21:38:49 +02:00
|
|
|
|
final class NodaTimeAutotranslater {
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
2020-09-18 21:24:21 +02:00
|
|
|
|
const USECASE_MONTH = 1;
|
|
|
|
|
const USECASE_DAY = 2;
|
|
|
|
|
|
2020-09-20 17:13:42 +02:00
|
|
|
|
const TRANSLATABLE_NOT = 0;
|
|
|
|
|
const TRANSLATABLE_AS_MONTH_DAY = 1;
|
|
|
|
|
const TRANSLATABLE_AS_YEAR_WITH_SUFFIX = 2;
|
2020-09-22 22:46:48 +02:00
|
|
|
|
const TRANSLATABLE_SINCE_START = 3;
|
|
|
|
|
const TRANSLATABLE_UNTIL_END = 4;
|
|
|
|
|
const TRANSLATABLE_ONLY_YEAR = 5;
|
2020-09-23 10:28:04 +02:00
|
|
|
|
const TRANSLATABLE_CENTURY = 6;
|
|
|
|
|
const TRANSLATABLE_DECADE = 7;
|
2020-09-24 11:47:54 +02:00
|
|
|
|
const TRANSLATABLE_TIMESPAN_YEARS = 8;
|
2021-01-06 23:05:26 +01:00
|
|
|
|
const TRANSLATABLE_TIMESPAN_DATES = 9;
|
2020-09-20 17:13:42 +02:00
|
|
|
|
|
2020-09-18 18:48:40 +02:00
|
|
|
|
const LANGS_TO_LOCALES = [
|
|
|
|
|
'ar' => 'ar_SY.utf8',
|
|
|
|
|
'de' => 'de_DE.utf8',
|
|
|
|
|
'en' => 'en_US.utf8',
|
|
|
|
|
'es' => 'es_ES.utf8',
|
|
|
|
|
'fa' => 'fa_IR.UTF-8',
|
|
|
|
|
'fr' => 'fr_FR.utf8',
|
|
|
|
|
'hu' => 'hu_HU.utf8',
|
|
|
|
|
'id' => 'id_ID.utf8',
|
|
|
|
|
'it' => 'it_IT.utf8',
|
|
|
|
|
'ka' => 'ka_GE.UTF-8',
|
|
|
|
|
'ko' => 'ko_KR.UTF-8',
|
|
|
|
|
'pl' => 'pl_PL.utf8',
|
|
|
|
|
'pt' => 'pt_BR.utf8',
|
|
|
|
|
'ro' => 'ro_RO.UTF-8',
|
|
|
|
|
'ru' => 'ru_RU.UTF-8',
|
|
|
|
|
'ta' => 'ta_IN.UTF-8',
|
|
|
|
|
'tl' => 'tl_PH.utf8',
|
|
|
|
|
'tr' => 'tr_TR.utf8',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => 'en_US.utf8',
|
|
|
|
|
'zh' => 'en_US.utf8',
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-20 17:13:42 +02:00
|
|
|
|
const LANGS_SINGLE_YEAR_FORMAT = [
|
|
|
|
|
'ar' => '%s',
|
|
|
|
|
'de' => '%s',
|
|
|
|
|
'en' => '%s',
|
|
|
|
|
'es' => '%s',
|
|
|
|
|
'fa' => '%s',
|
|
|
|
|
'fr' => '%s',
|
|
|
|
|
'hu' => '%s',
|
|
|
|
|
'id' => '%s',
|
|
|
|
|
'it' => '%s',
|
|
|
|
|
'ka' => '%s',
|
|
|
|
|
'ko' => '%s년',
|
|
|
|
|
'pl' => '%s',
|
|
|
|
|
'pt' => '%s',
|
|
|
|
|
'ro' => '%s',
|
|
|
|
|
'ru' => '%s',
|
|
|
|
|
'ta' => '%s',
|
|
|
|
|
'tl' => '%s',
|
|
|
|
|
'tr' => '%s',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '%s年',
|
|
|
|
|
'zh' => '%s年',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LANGS_YEARSPAN_FORMAT = [
|
|
|
|
|
'ar' => '%s-%s',
|
|
|
|
|
'de' => '%s-%s',
|
|
|
|
|
'en' => '%s-%s',
|
|
|
|
|
'es' => '%s-%s',
|
|
|
|
|
'fa' => '%s-%s',
|
|
|
|
|
'fr' => '%s-%s',
|
|
|
|
|
'hu' => '%s-%s',
|
|
|
|
|
'id' => '%s-%s',
|
|
|
|
|
'it' => '%s-%s',
|
|
|
|
|
'ka' => '%s-%s',
|
|
|
|
|
'ko' => '%s년-%s년',
|
|
|
|
|
'pl' => '%s-%s',
|
|
|
|
|
'pt' => '%s-%s',
|
|
|
|
|
'ro' => '%s-%s',
|
|
|
|
|
'ru' => '%s-%s',
|
|
|
|
|
'ta' => '%s-%s',
|
|
|
|
|
'tl' => '%s-%s',
|
|
|
|
|
'tr' => '%s-%s',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '%s年から%s年',
|
|
|
|
|
'zh' => '%s年至%s年',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LANGS_TO_BCE_FORMAT = [
|
|
|
|
|
'ar' => '-%s',
|
|
|
|
|
'de' => '%s v. Chr.',
|
|
|
|
|
'en' => '%s BC',
|
|
|
|
|
'es' => '%s a.C.',
|
|
|
|
|
'fa' => '-%s',
|
|
|
|
|
'fr' => '%s av. J.-C.',
|
|
|
|
|
'hu' => 'Kr. e. %s',
|
|
|
|
|
'id' => '%s SM',
|
|
|
|
|
'it' => '%s a.C.',
|
|
|
|
|
'ka' => 'ძვ. წ. %s წ',
|
|
|
|
|
'ko' => '기원전%s',
|
|
|
|
|
'pl' => '%s pne',
|
|
|
|
|
'pt' => '%s AC',
|
|
|
|
|
'ro' => '%s î.Hr.',
|
|
|
|
|
'ru' => '%s г. до н.э.',
|
|
|
|
|
'ta' => 'கிமு %s',
|
|
|
|
|
'tl' => '%s BC',
|
|
|
|
|
'tr' => 'MÖ %s',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '紀元前%s',
|
|
|
|
|
'zh' => '公元前%s',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LANGS_TO_CE_FORMAT = [
|
|
|
|
|
'ar' => '%s',
|
|
|
|
|
'de' => '%s n. Chr.',
|
|
|
|
|
'en' => '%s CE',
|
|
|
|
|
'es' => '%s d.C.',
|
|
|
|
|
'fa' => '%s',
|
|
|
|
|
'fr' => '%s ap. J.-C.',
|
|
|
|
|
'hu' => '%s',
|
|
|
|
|
'id' => '%s M.',
|
|
|
|
|
'it' => '%s d.C.',
|
|
|
|
|
'ka' => '%s წ',
|
|
|
|
|
'ko' => '%s',
|
|
|
|
|
'pl' => '%s n.e.',
|
|
|
|
|
'pt' => '%s dC',
|
|
|
|
|
'ro' => '%s',
|
|
|
|
|
'ru' => '%s',
|
|
|
|
|
'ta' => '%s பொ.ச.',
|
|
|
|
|
'tl' => '%s AD',
|
|
|
|
|
'tr' => '%s',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '西暦%s',
|
|
|
|
|
'zh' => '%s',
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
const LANGS_SINCE_START_FORMAT_YEAR = [
|
|
|
|
|
'ar' => '%s-',
|
|
|
|
|
'de' => 'Seit %s',
|
|
|
|
|
'en' => 'Since %s',
|
|
|
|
|
'es' => 'Desde %s',
|
|
|
|
|
'fa' => '%s-',
|
|
|
|
|
'fr' => 'Depuis %s',
|
|
|
|
|
'hu' => '%s-től',
|
|
|
|
|
'id' => 'Sejak %s',
|
|
|
|
|
'it' => 'Dal %s',
|
|
|
|
|
'ka' => '%s წლიდან',
|
|
|
|
|
'ko' => '%s부터',
|
2020-10-04 17:40:51 +02:00
|
|
|
|
'pl' => 'Od %s r.',
|
2020-09-22 22:46:48 +02:00
|
|
|
|
'pt' => '%s dC',
|
|
|
|
|
'ro' => 'Din %s',
|
|
|
|
|
'ru' => 'С %s г.',
|
|
|
|
|
'ta' => '%s முதல்',
|
|
|
|
|
'tl' => 'Mula noong %s',
|
|
|
|
|
'tr' => '%s-',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '%s以来',
|
|
|
|
|
'zh' => '自%s以來',
|
|
|
|
|
];
|
|
|
|
|
|
2020-10-04 17:40:51 +02:00
|
|
|
|
const LANGS_AFTER_START_FORMAT_YEAR = [
|
|
|
|
|
'ar' => '%s-',
|
|
|
|
|
'de' => 'Nach %s',
|
|
|
|
|
'en' => 'After %s',
|
|
|
|
|
'es' => 'Despues de %s',
|
|
|
|
|
'fa' => '%s-',
|
|
|
|
|
'fr' => 'Après %s',
|
2020-10-04 19:17:18 +02:00
|
|
|
|
'hu' => '%s után',
|
2020-10-04 17:40:51 +02:00
|
|
|
|
'id' => 'Setelah %s',
|
|
|
|
|
'it' => 'Dopo il %s',
|
|
|
|
|
'ka' => '%s წლის შემდეგ',
|
|
|
|
|
'ko' => '%s 년 이후',
|
|
|
|
|
'pl' => 'Po %s r.',
|
|
|
|
|
'pt' => 'Depois de %s',
|
|
|
|
|
'ro' => 'După %s',
|
|
|
|
|
'ru' => 'после %s г.',
|
|
|
|
|
'ta' => '%s க்குப் பிறகு',
|
|
|
|
|
'tl' => 'Pagkaraan ng %s',
|
|
|
|
|
'tr' => '%s-',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '%s以降',
|
|
|
|
|
'zh' => '%s以后',
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
const LANGS_UNTIL_START_FORMAT_YEAR = [
|
|
|
|
|
'ar' => '-%s',
|
|
|
|
|
'de' => 'Bis %s',
|
|
|
|
|
'en' => 'Until %s',
|
|
|
|
|
'es' => 'Hasta %s',
|
|
|
|
|
'fa' => '-%s',
|
|
|
|
|
'fr' => 'Jusqu\'en %s',
|
|
|
|
|
'hu' => '%s-ig',
|
|
|
|
|
'id' => 'Sampai %s',
|
|
|
|
|
'it' => 'Fino al %s',
|
|
|
|
|
'ka' => '%s წლამდე',
|
|
|
|
|
'ko' => '%s까지',
|
|
|
|
|
'pl' => 'do %s roku',
|
|
|
|
|
'pt' => 'até %s',
|
|
|
|
|
'ro' => 'până în %s',
|
|
|
|
|
'ru' => 'до %s г.',
|
|
|
|
|
'ta' => '%s வரை',
|
|
|
|
|
'tl' => 'Hanggang %s',
|
|
|
|
|
'tr' => '%s-',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
|
|
|
|
'ja' => '%sまで',
|
|
|
|
|
'zh' => '直到%s',
|
|
|
|
|
];
|
|
|
|
|
|
2020-10-04 17:40:51 +02:00
|
|
|
|
const LANGS_BEFORE_START_FORMAT_YEAR = [
|
|
|
|
|
'ar' => '-%s',
|
|
|
|
|
'de' => 'Vor %s',
|
|
|
|
|
'en' => 'Before %s',
|
|
|
|
|
'es' => 'Antes de %s',
|
|
|
|
|
'fa' => '-%s',
|
|
|
|
|
'fr' => 'Avant %s',
|
2020-10-04 19:17:18 +02:00
|
|
|
|
'hu' => '%s előtt',
|
2020-10-04 17:40:51 +02:00
|
|
|
|
'id' => 'Sebelum %s',
|
|
|
|
|
'it' => 'Prima del %s',
|
|
|
|
|
'ka' => '%s წლამდე',
|
|
|
|
|
'ko' => '%s 년 이전',
|
|
|
|
|
'pl' => 'Przed %s',
|
|
|
|
|
'pt' => 'Antes de %s',
|
|
|
|
|
'ro' => 'înainte de %s',
|
|
|
|
|
'ru' => 'до %s г.',
|
|
|
|
|
'ta' => '%s க்கு முன்',
|
|
|
|
|
'tl' => 'Bago ang %s',
|
|
|
|
|
'tr' => '%s-',
|
|
|
|
|
|
|
|
|
|
// Languages that don't really need a specific locale
|
2020-10-04 19:17:18 +02:00
|
|
|
|
'ja' => '%s以前',
|
|
|
|
|
'zh' => '%s之前',
|
2020-10-04 17:40:51 +02:00
|
|
|
|
];
|
|
|
|
|
|
2020-09-23 10:28:04 +02:00
|
|
|
|
const LANGS_CENTURY_FORMAT = [
|
|
|
|
|
'ar' => 'القرن ال %s',
|
|
|
|
|
'de' => '%s. Jahrhundert',
|
|
|
|
|
'en' => '%s. century',
|
|
|
|
|
'es' => 'Siglo %s',
|
|
|
|
|
'fa' => 'قرن %s',
|
|
|
|
|
'fr' => '%sème siècle',
|
|
|
|
|
'hu' => '%s. század',
|
2020-09-24 17:35:40 +02:00
|
|
|
|
'id' => 'Abad ke-%s',
|
2020-09-23 10:28:04 +02:00
|
|
|
|
'it' => '%sesimo secolo',
|
|
|
|
|
'ka' => 'მე -%s საუკუნე',
|
|
|
|
|
'ko' => '%s 세기',
|
|
|
|
|
'pl' => '%s wiek',
|
2020-09-24 17:35:40 +02:00
|
|
|
|
'pt' => 'Século %s',
|
|
|
|
|
'ro' => 'Secolul al %s-lea',
|
2020-09-23 10:28:04 +02:00
|
|
|
|
'ru' => '%s век',
|
|
|
|
|
'ta' => '%s ஆம் நூற்றாண்டு',
|
|
|
|
|
'tl' => 'Ika-%s na siglo',
|
|
|
|
|
'tr' => '%s. yüzyıl',
|
2020-10-04 19:17:18 +02:00
|
|
|
|
'ja' => '%s世紀',
|
|
|
|
|
'zh' => '%s世紀',
|
2020-09-23 10:28:04 +02:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LANGS_CENTURIES_FORMAT = [
|
|
|
|
|
'ar' => 'القرن ال %s-%s',
|
|
|
|
|
'de' => '%s.-%s. Jahrhundert',
|
|
|
|
|
'en' => '%s.-%s. century',
|
|
|
|
|
'es' => 'Siglo %s-%s',
|
|
|
|
|
'fa' => 'قرن %s-%s',
|
|
|
|
|
'fr' => '%s-%sème siècle',
|
|
|
|
|
'hu' => '%s.-%s. század',
|
2020-09-24 17:35:40 +02:00
|
|
|
|
'id' => 'Abad ke-%s-%s',
|
2020-09-23 10:28:04 +02:00
|
|
|
|
'it' => '%s-%sesimo secolo',
|
|
|
|
|
'ka' => 'მე -%s-%s საუკუნე',
|
|
|
|
|
'ko' => '%s-%s 세기',
|
|
|
|
|
'pl' => '%s-%s wiek',
|
2020-09-24 17:35:40 +02:00
|
|
|
|
'pt' => 'Século %s-%s',
|
|
|
|
|
'ro' => 'Secolul al %s-%s-lea',
|
2020-09-23 10:28:04 +02:00
|
|
|
|
'ru' => '%s-%s век',
|
|
|
|
|
'ta' => '%s-%s ஆம் நூற்றாண்டு',
|
|
|
|
|
'tl' => 'Ika-%s hanggang ika-%s na siglo',
|
|
|
|
|
'tr' => '%s.-%s. yüzyıl',
|
|
|
|
|
'ja' => '%s世紀-%s世紀',
|
|
|
|
|
'zh' => '%s-%s世紀',
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-24 11:47:54 +02:00
|
|
|
|
const LANGS_DECADE_FORMAT = [
|
|
|
|
|
'ar' => '%s-%s',
|
|
|
|
|
'de' => '%ser Jahre',
|
|
|
|
|
'en' => '%ss',
|
|
|
|
|
'es' => '%s-%s',
|
|
|
|
|
'fa' => 'دهه %s',
|
|
|
|
|
'fr' => 'Années %s',
|
|
|
|
|
'hu' => '%s-as évek',
|
|
|
|
|
'id' => 'Tahun %s-an',
|
|
|
|
|
'it' => '%ss',
|
|
|
|
|
'ka' => '%s-იანი წლები',
|
|
|
|
|
'ko' => '%s 년대',
|
|
|
|
|
'pl' => '%s roku',
|
|
|
|
|
'pt' => 'Década de %s',
|
|
|
|
|
'ro' => 'Anii %s',
|
|
|
|
|
'ru' => '%s-е годы',
|
|
|
|
|
'ta' => '%s கள்',
|
|
|
|
|
'tl' => '%ss',
|
|
|
|
|
'tr' => '%s\'ler',
|
|
|
|
|
'ja' => '%s年代',
|
|
|
|
|
'zh' => '%s年代',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LANGS_DECADES_FORMAT = [
|
|
|
|
|
'ar' => '%s-%s',
|
|
|
|
|
'de' => '%s-%ser Jahre',
|
|
|
|
|
'en' => '%s-%ss',
|
|
|
|
|
'es' => '%s-%s',
|
|
|
|
|
'fa' => 'دهه %s-%s',
|
|
|
|
|
'fr' => 'Années %s-%s',
|
|
|
|
|
'hu' => '%s-%s-as évek',
|
|
|
|
|
'id' => 'Tahun %s-an sampai tahun %s-an',
|
|
|
|
|
'it' => '%s-%ss',
|
|
|
|
|
'ka' => '%s-%s-იანი წლები',
|
|
|
|
|
'ko' => '%s-%s 년대',
|
|
|
|
|
'pl' => '%s-%s roku',
|
|
|
|
|
'pt' => 'Décadas de %s-%s',
|
|
|
|
|
'ro' => 'Anii %s-%s',
|
|
|
|
|
'ru' => '%s-%s-е годы',
|
|
|
|
|
'ta' => '%s-%s கள்',
|
|
|
|
|
'tl' => '%s-%ss',
|
|
|
|
|
'tr' => '%s-%s\'ler',
|
|
|
|
|
'ja' => '%s年代から%s年代',
|
|
|
|
|
'zh' => '%s年代-%s年代',
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-24 11:54:01 +02:00
|
|
|
|
const LANGS_SYLLABLE_CLEANING = [
|
|
|
|
|
"hu" => [
|
|
|
|
|
"10-as évek" => "10-es évek",
|
|
|
|
|
"40-as évek" => "40-es évek",
|
|
|
|
|
"50-as évek" => "50-es évek",
|
|
|
|
|
"70-as évek" => "70-es évek",
|
|
|
|
|
"90-as évek" => "90-es évek",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-18 18:48:40 +02:00
|
|
|
|
/** @var MDMysqli */
|
|
|
|
|
private MDMysqli $_mysqli_noda;
|
|
|
|
|
/** @var integer */
|
|
|
|
|
private int $_znum;
|
|
|
|
|
/** @var MDMysqliStmt */
|
|
|
|
|
private MDMysqliStmt $_insertStmt;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a time is translatable.
|
|
|
|
|
* Translatable times have either a counting time day and month or at least a month.
|
|
|
|
|
*
|
2020-09-20 17:13:42 +02:00
|
|
|
|
* @param string $zeit_beginn Beginn year.
|
|
|
|
|
* @param string $zeit_ende End year.
|
2020-09-18 18:48:40 +02:00
|
|
|
|
* @param string $zeit_zaehlzeit_monat Counting time month.
|
|
|
|
|
*
|
2020-09-20 17:13:42 +02:00
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public static function check_translatability(string $zeit_beginn, string $zeit_ende, string $zeit_zaehlzeit_monat):int {
|
|
|
|
|
|
2020-09-23 17:03:12 +02:00
|
|
|
|
if ($zeit_ende === "?") {
|
2020-09-22 22:46:48 +02:00
|
|
|
|
return self::TRANSLATABLE_SINCE_START;
|
|
|
|
|
}
|
2020-09-23 17:03:12 +02:00
|
|
|
|
if ($zeit_beginn === "?") {
|
2020-09-22 22:46:48 +02:00
|
|
|
|
return self::TRANSLATABLE_UNTIL_END;
|
|
|
|
|
}
|
2020-09-23 10:28:04 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\intval($zeit_ende) >= 0 && \intval($zeit_beginn) < 0) {
|
2020-09-20 17:13:42 +02:00
|
|
|
|
return self::TRANSLATABLE_NOT;
|
|
|
|
|
}
|
2020-09-23 10:28:04 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (($zeit_ende > 0 && \intval($zeit_ende) % 100 === 0 and (\intval($zeit_beginn) - 1) % 100 === 0)
|
|
|
|
|
|| (\intval($zeit_beginn) < 0 && \intval($zeit_beginn) % 100 === 0 and (\intval($zeit_ende) + 1) % 100 === 0)
|
2020-09-24 17:35:40 +02:00
|
|
|
|
) {
|
2020-09-23 10:28:04 +02:00
|
|
|
|
return self::TRANSLATABLE_CENTURY;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if ((\intval($zeit_ende) + 1) % 10 === 0 and \intval($zeit_beginn) % 10 === 0 and \intval($zeit_beginn) > 1000) {
|
2020-09-24 11:47:54 +02:00
|
|
|
|
return self::TRANSLATABLE_DECADE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\intval($zeit_ende) < 0 && \intval($zeit_beginn) < 0
|
|
|
|
|
|| (\intval($zeit_ende) < 1000 and \trim($zeit_zaehlzeit_monat, ", .0") === "")
|
2020-09-26 16:02:18 +02:00
|
|
|
|
) {
|
2020-09-20 17:13:42 +02:00
|
|
|
|
return self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX;
|
|
|
|
|
}
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if ($zeit_ende === $zeit_beginn and \trim($zeit_zaehlzeit_monat, ", .0") === "") {
|
2020-09-22 22:46:48 +02:00
|
|
|
|
return self::TRANSLATABLE_ONLY_YEAR;
|
|
|
|
|
}
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if ($zeit_ende !== $zeit_beginn and \trim($zeit_zaehlzeit_monat, ", .0") === "") {
|
2020-09-24 11:47:54 +02:00
|
|
|
|
return self::TRANSLATABLE_TIMESPAN_YEARS;
|
|
|
|
|
}
|
2020-09-20 17:13:42 +02:00
|
|
|
|
// Conditions speaking against translatability.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\trim($zeit_zaehlzeit_monat, ", .0") === "") {
|
2020-09-20 18:32:48 +02:00
|
|
|
|
return self::TRANSLATABLE_NOT;
|
2020-09-20 17:13:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::TRANSLATABLE_AS_MONTH_DAY;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-22 22:46:48 +02:00
|
|
|
|
* Gets suffix mode for years with suffix.
|
2020-09-20 17:13:42 +02:00
|
|
|
|
*
|
2020-09-22 22:46:48 +02:00
|
|
|
|
* @param integer $start Start year.
|
|
|
|
|
* @param integer $end End year.
|
2020-09-20 17:13:42 +02:00
|
|
|
|
*
|
2020-09-22 22:46:48 +02:00
|
|
|
|
* @return integer
|
2020-09-18 18:48:40 +02:00
|
|
|
|
*/
|
2020-09-22 22:46:48 +02:00
|
|
|
|
public static function getSuffixModeForYearsWSuffix(int $start, int $end):int {
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
2020-09-20 17:13:42 +02:00
|
|
|
|
if ($start < 0 && $end < 0) {
|
|
|
|
|
$suffixMode = 2; // 2; // " v. Chr.";
|
|
|
|
|
}
|
|
|
|
|
else if ($end < 1000) {
|
|
|
|
|
$suffixMode = 1; // " n. Chr.";
|
2020-09-18 18:48:40 +02:00
|
|
|
|
}
|
2020-09-22 22:46:48 +02:00
|
|
|
|
else $suffixMode = 0; // Times larger than 1000 n. Chr.
|
|
|
|
|
|
|
|
|
|
return $suffixMode;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applies suffix format to a time string.
|
|
|
|
|
*
|
|
|
|
|
* @param string $tLang Two digit ANSI language code.
|
|
|
|
|
* @param string $timeName Time name.
|
|
|
|
|
* @param integer $suffixMode Suffix mode.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function applyBcBceFormat(string $tLang, string $timeName, int $suffixMode):string {
|
|
|
|
|
|
|
|
|
|
switch ($suffixMode) {
|
|
|
|
|
case 0:
|
|
|
|
|
return $timeName;
|
|
|
|
|
case 1:
|
2020-10-23 17:03:51 +02:00
|
|
|
|
return \sprintf(self::LANGS_TO_CE_FORMAT[$tLang], $timeName);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
case 2:
|
2020-10-23 17:03:51 +02:00
|
|
|
|
return \sprintf(self::LANGS_TO_BCE_FORMAT[$tLang], $timeName);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
default:
|
|
|
|
|
throw new Exception("Unknown case encountered for time translations.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-09-20 17:13:42 +02:00
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translated years or timespans below 1000 CE.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
2020-09-23 17:03:12 +02:00
|
|
|
|
public static function translateYearsWithSuffix(array $timeInfo):array {
|
2020-09-22 22:46:48 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start = \intval($timeInfo['zeit_beginn']);
|
|
|
|
|
$end = \intval($timeInfo['zeit_ende']);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
|
|
|
|
|
$suffixMode = self::getSuffixModeForYearsWSuffix($start, $end);
|
|
|
|
|
|
2020-09-26 13:20:22 +02:00
|
|
|
|
// Time info to pass
|
|
|
|
|
if ($suffixMode === 2) {
|
|
|
|
|
$timeInfoToCopy = $timeInfo;
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$timeInfoToCopy["zeit_beginn"] = \abs($start);
|
|
|
|
|
$timeInfoToCopy["zeit_ende"] = \abs($end);
|
2020-09-26 13:20:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output = [];
|
2020-09-20 17:13:42 +02:00
|
|
|
|
foreach (self::LANGS_TO_CE_FORMAT as $tLang => $ceFormat) {
|
|
|
|
|
|
2020-09-26 15:21:32 +02:00
|
|
|
|
if ($suffixMode === 2) {
|
|
|
|
|
|
|
|
|
|
if (empty($timeInfoToCopy)) {
|
|
|
|
|
throw new Exception("No time information to copy existent");
|
|
|
|
|
}
|
2020-09-26 15:10:06 +02:00
|
|
|
|
$ceIndicatorsToRemove = explode("%s", self::LANGS_TO_CE_FORMAT[$tLang]);
|
2020-09-26 13:20:22 +02:00
|
|
|
|
$year = self::getTranslations($timeInfoToCopy)[$tLang];
|
2020-09-26 15:10:06 +02:00
|
|
|
|
foreach ($ceIndicatorsToRemove as $ceIndicatorToRemove) {
|
|
|
|
|
$year = str_replace($ceIndicatorToRemove, "", $year);
|
|
|
|
|
}
|
2020-09-26 13:20:22 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ($start === $end) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$year = \sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)\abs($start));
|
2020-09-26 13:20:22 +02:00
|
|
|
|
}
|
2020-10-23 17:03:51 +02:00
|
|
|
|
else $year = \sprintf(self::LANGS_YEARSPAN_FORMAT[$tLang], (string)\abs($start), (string)\abs($end));
|
2020-09-20 17:13:42 +02:00
|
|
|
|
}
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $year, $suffixMode);
|
2020-09-20 17:13:42 +02:00
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Translated only years: 1994.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearOnly(array $timeInfo):array {
|
2020-09-20 17:13:42 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start = \intval($timeInfo['zeit_beginn']);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
|
|
foreach (self::LANGS_SINGLE_YEAR_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$output[$tLang] = \sprintf($format, (string)\abs($start));
|
2020-09-20 17:13:42 +02:00
|
|
|
|
}
|
2020-09-22 22:46:48 +02:00
|
|
|
|
return $output;
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 11:47:54 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translated only years: 1994.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateTimespanYears(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start = \intval($timeInfo['zeit_beginn']);
|
|
|
|
|
$end = \intval($timeInfo['zeit_ende']);
|
2020-09-24 11:47:54 +02:00
|
|
|
|
$output = [];
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\abs($start) === 1102) throw new Exception(var_export($timeInfo, true));
|
2020-09-24 11:47:54 +02:00
|
|
|
|
foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$output[$tLang] = \sprintf($format, (string)\abs($start), (string)\abs($end));
|
2020-09-24 11:47:54 +02:00
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 10:28:04 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translates century names: 19. Jahrhundert.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearsAsCentury(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\intval($timeInfo['zeit_beginn']) > 0) {
|
2020-09-24 17:35:40 +02:00
|
|
|
|
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start_cen = ((\intval($timeInfo['zeit_beginn']) - 1) / 100) + 1;
|
2020-09-24 17:35:40 +02:00
|
|
|
|
// End: 1600. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$end_cen = (\intval($timeInfo['zeit_ende']) / 100);
|
2020-09-24 17:35:40 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// End: -1600. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start_cen = (\intval($timeInfo['zeit_beginn']) / 100);
|
2020-09-24 17:35:40 +02:00
|
|
|
|
// End: -1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$end_cen = ((\intval($timeInfo['zeit_ende']) + 1) / 100) - 1;
|
2020-09-24 17:35:40 +02:00
|
|
|
|
}
|
2020-09-23 10:28:04 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$suffixMode = self::getSuffixModeForYearsWSuffix((\intval($timeInfo['zeit_beginn']) - 1), \intval($timeInfo['zeit_ende']));
|
2020-09-23 10:28:04 +02:00
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
|
|
if ($start_cen === $end_cen) {
|
|
|
|
|
foreach (self::LANGS_CENTURY_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$tLangValue = \sprintf($format, (string)\abs($start_cen));
|
2020-09-23 10:28:04 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foreach (self::LANGS_CENTURIES_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$tLangValue = \sprintf($format, (string)\abs($start_cen), (string)\abs($end_cen));
|
2020-09-23 10:28:04 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 11:47:54 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translates decade names: 1920er Jahre.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearsAsDecade(array $timeInfo):array {
|
|
|
|
|
|
|
|
|
|
// Beginn: 1500. (1501 - 1) / 100 + 1 = 16. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start_cen = (\intval($timeInfo['zeit_beginn']));
|
2020-09-24 11:47:54 +02:00
|
|
|
|
// End: 1600. 16th century is the time.
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$end_cen = (\intval($timeInfo['zeit_ende']));
|
2020-09-24 11:47:54 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$suffixMode = self::getSuffixModeForYearsWSuffix((\intval($timeInfo['zeit_beginn']) - 1), \intval($timeInfo['zeit_ende']));
|
2020-09-24 11:47:54 +02:00
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
|
|
if ($start_cen === $end_cen - 9) {
|
|
|
|
|
foreach (self::LANGS_DECADE_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$tLangValue = \sprintf($format, (string)$start_cen, (string)$end_cen);
|
|
|
|
|
if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = \strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]);
|
2020-09-24 11:47:54 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foreach (self::LANGS_DECADES_FORMAT as $tLang => $format) {
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$tLangValue = \sprintf($format, (string)$start_cen, (string)($end_cen - 9));
|
|
|
|
|
if (!empty(self::LANGS_SYLLABLE_CLEANING[$tLang])) $tLangValue = \strtr($tLangValue, self::LANGS_SYLLABLE_CLEANING[$tLang]);
|
2020-09-24 11:47:54 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 18:21:33 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translated years or timespans below 1000 CE.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearsAfterStart(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (empty(\trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
|
|
|
|
|
$timeInfo['zeit_beginn'] = \strval(\intval($timeInfo['zeit_beginn']) - 1);
|
2020-10-04 18:21:33 +02:00
|
|
|
|
}
|
|
|
|
|
# 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];
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$timeName = \sprintf($format, $dateAlone);
|
2020-10-04 18:21:33 +02:00
|
|
|
|
$output[$tLang] = $timeName;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 18:48:40 +02:00
|
|
|
|
/**
|
2020-09-22 22:46:48 +02:00
|
|
|
|
* Translated years or timespans below 1000 CE.
|
2020-09-18 18:48:40 +02:00
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
2020-09-22 22:46:48 +02:00
|
|
|
|
* @return array<string>
|
2020-09-18 18:48:40 +02:00
|
|
|
|
*/
|
2020-09-22 22:46:48 +02:00
|
|
|
|
public static function translateYearsSinceStart(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$start = \intval($timeInfo['zeit_beginn']);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
|
2020-10-04 23:59:40 +02:00
|
|
|
|
if (substr((string)$timeInfo['zeit_name'], 0, 5) === "Nach ") {
|
2020-10-04 18:21:33 +02:00
|
|
|
|
return self::translateYearsAfterStart($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$innerTimeInfo = $timeInfo;
|
|
|
|
|
$innerTimeInfo['zeit_ende'] = $timeInfo['zeit_beginn'];
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
|
|
foreach (self::LANGS_SINCE_START_FORMAT_YEAR as $tLang => $format) {
|
|
|
|
|
|
|
|
|
|
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$timeName = \sprintf($format, $dateAlone);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output[$tLang] = $timeName;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 19:34:17 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translated years or timespans below 1000 CE.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearsBeforeEnd(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (empty(\trim((string)$timeInfo['zeit_zaehlzeit_monat'], " ,.;0"))) {
|
|
|
|
|
$timeInfo['zeit_ende'] = \strval(\intval($timeInfo['zeit_ende']) + 1);
|
2020-10-04 19:34:17 +02:00
|
|
|
|
}
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$end = \intval($timeInfo['zeit_ende']);
|
2020-10-04 19:34:17 +02:00
|
|
|
|
|
|
|
|
|
$innerTimeInfo = $timeInfo;
|
|
|
|
|
$innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende'];
|
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
foreach (self::LANGS_BEFORE_START_FORMAT_YEAR as $tLang => $format) {
|
|
|
|
|
|
|
|
|
|
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$timeName = \sprintf($format, $dateAlone);
|
2020-10-04 19:34:17 +02:00
|
|
|
|
$output[$tLang] = $timeName;
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
/**
|
|
|
|
|
* Translated years or timespans below 1000 CE.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function translateYearsUntilEnd(array $timeInfo):array {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$end = \intval($timeInfo['zeit_ende']);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
|
2020-10-04 23:59:40 +02:00
|
|
|
|
if (substr((string)$timeInfo['zeit_name'], 0, 4) === "Vor ") {
|
2020-10-04 19:34:17 +02:00
|
|
|
|
return self::translateYearsBeforeEnd($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$innerTimeInfo = $timeInfo;
|
|
|
|
|
$innerTimeInfo['zeit_beginn'] = $timeInfo['zeit_ende'];
|
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
foreach (self::LANGS_UNTIL_START_FORMAT_YEAR as $tLang => $format) {
|
|
|
|
|
|
|
|
|
|
$dateAlone = self::getTranslations($innerTimeInfo)[$tLang];
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$timeName = \sprintf($format, $dateAlone);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output[$tLang] = $timeName;
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets translations for a given entry type.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function getTranslations(array $timeInfo):array {
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
2021-01-31 19:39:09 +01:00
|
|
|
|
if (!empty($timeInfo['zeit_name']) and strlen((string)$timeInfo['zeit_name']) > 10 and !empty($timespanDates = NodaTimeSplitter::attempt_splitting_from_till((string)$timeInfo['zeit_name']))) {
|
2021-01-06 23:05:26 +01:00
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
|
|
$start = NodaTimeSplitter::attempt_splitting($timespanDates['start_name']);
|
|
|
|
|
$startTimeInfo = [
|
|
|
|
|
"zeit_name" => $timespanDates['start_name'],
|
|
|
|
|
"zeit_beginn" => $start[0],
|
|
|
|
|
"zeit_ende" => $start[1],
|
|
|
|
|
"zeit_zaehlzeit_jahr" => NodaTimeSplitter::timePartsToCountingYear($start),
|
|
|
|
|
"zeit_zaehlzeit_monat" => $start[2],
|
|
|
|
|
"zeit_zaehlzeit_tag" => $start[3],
|
|
|
|
|
"zeit_zaehlzeit_vorzeichen" => $start[4],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$end = NodaTimeSplitter::attempt_splitting($timespanDates['end_name']);
|
|
|
|
|
$endTimeInfo = [
|
|
|
|
|
"zeit_name" => $timespanDates['end_name'],
|
|
|
|
|
"zeit_beginn" => $end[0],
|
|
|
|
|
"zeit_ende" => $end[1],
|
|
|
|
|
"zeit_zaehlzeit_jahr" => NodaTimeSplitter::timePartsToCountingYear($end),
|
|
|
|
|
"zeit_zaehlzeit_monat" => $end[2],
|
|
|
|
|
"zeit_zaehlzeit_tag" => $end[3],
|
|
|
|
|
"zeit_zaehlzeit_vorzeichen" => $end[4],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) {
|
|
|
|
|
$start_term = self::getTranslations($startTimeInfo)[$tLang];
|
|
|
|
|
$end_term = self::getTranslations($endTimeInfo)[$tLang];
|
|
|
|
|
|
|
|
|
|
$output[$tLang] = \sprintf($format, $start_term, $end_term);
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 10:49:34 +02:00
|
|
|
|
if (!($translation_type = self::check_translatability((string)$timeInfo['zeit_beginn'], (string)$timeInfo['zeit_ende'], (string)$timeInfo['zeit_zaehlzeit_monat']))) {
|
2020-09-26 13:20:22 +02:00
|
|
|
|
throw new MDgenericInvalidInputsException("Non-translatable date: {$timeInfo['zeit_beginn']} - {$timeInfo['zeit_ende']}");
|
2020-09-18 18:48:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
if ($translation_type === self::TRANSLATABLE_ONLY_YEAR) {
|
|
|
|
|
return self::translateYearOnly($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($translation_type === self::TRANSLATABLE_SINCE_START) {
|
|
|
|
|
return self::translateYearsSinceStart($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($translation_type === self::TRANSLATABLE_UNTIL_END) {
|
|
|
|
|
return self::translateYearsUntilEnd($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 10:28:04 +02:00
|
|
|
|
if ($translation_type === self::TRANSLATABLE_CENTURY) {
|
|
|
|
|
return self::translateYearsAsCentury($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 11:47:54 +02:00
|
|
|
|
if ($translation_type === self::TRANSLATABLE_DECADE) {
|
|
|
|
|
return self::translateYearsAsDecade($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($translation_type === self::TRANSLATABLE_TIMESPAN_YEARS) {
|
|
|
|
|
return self::translateTimespanYears($timeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-20 17:13:42 +02:00
|
|
|
|
if ($translation_type === self::TRANSLATABLE_AS_YEAR_WITH_SUFFIX) {
|
2020-09-22 22:46:48 +02:00
|
|
|
|
return self::translateYearsWithSuffix($timeInfo);
|
2020-09-20 17:13:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$suffixMode = self::getSuffixModeForYearsWSuffix((\intval($timeInfo['zeit_beginn']) - 1), \intval($timeInfo['zeit_ende']));
|
2020-09-26 16:10:26 +02:00
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
if (\trim((string)$timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") {
|
2020-09-18 18:48:40 +02:00
|
|
|
|
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01";
|
2020-09-18 21:24:21 +02:00
|
|
|
|
$usecase = self::USECASE_MONTH;
|
2020-09-18 18:48:40 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-{$timeInfo['zeit_zaehlzeit_tag']} 00:00:01";
|
2020-09-18 21:24:21 +02:00
|
|
|
|
$usecase = self::USECASE_DAY;
|
2020-09-18 18:48:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$dateGeneral = \strtotime($dateStr);
|
2020-09-18 18:48:40 +02:00
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
$output = [];
|
2020-09-18 18:48:40 +02:00
|
|
|
|
foreach (self::LANGS_TO_LOCALES as $tLang => $locale) {
|
|
|
|
|
|
2020-10-23 17:03:51 +02:00
|
|
|
|
\setlocale(LC_TIME, $locale);
|
|
|
|
|
if ($locale !== \setlocale(LC_TIME, "0")) continue;
|
|
|
|
|
if ($usecase === self::USECASE_MONTH) $tLangValue = \strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0);
|
2020-09-18 21:38:49 +02:00
|
|
|
|
else { # if ($usecase === self::USECASE_DAY)
|
2020-10-23 17:03:51 +02:00
|
|
|
|
$tLangValue = \strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0);
|
2020-09-18 21:38:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-26 16:10:26 +02:00
|
|
|
|
$output[$tLang] = self::applyBcBceFormat($tLang, $tLangValue, $suffixMode);
|
2020-09-22 22:46:48 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs autotranslater.
|
|
|
|
|
*
|
|
|
|
|
* @param array<integer|string> $timeInfo Time information.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function translate(array $timeInfo):void {
|
|
|
|
|
|
|
|
|
|
$translations = self::getTranslations($timeInfo);
|
|
|
|
|
|
2021-03-08 21:23:38 +01:00
|
|
|
|
$this->_mysqli_noda->autocommit(false);
|
|
|
|
|
|
2020-09-22 22:46:48 +02:00
|
|
|
|
foreach ($translations as $tLang => $tLangValue) {
|
2020-09-18 18:48:40 +02:00
|
|
|
|
$this->_insertStmt->bind_param("iss", $this->_znum, $tLang, $tLangValue);
|
|
|
|
|
$this->_insertStmt->execute();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 21:23:38 +01:00
|
|
|
|
$this->_mysqli_noda->commit();
|
|
|
|
|
$this->_mysqli_noda->autocommit(true);
|
|
|
|
|
|
2020-09-18 18:48:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param MDMysqli $mysqli_noda Database connection.
|
|
|
|
|
* @param integer $znum Time ID.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(MDMysqli $mysqli_noda, int $znum) {
|
|
|
|
|
|
|
|
|
|
$this->_mysqli_noda = $mysqli_noda;
|
|
|
|
|
$this->_znum = $znum;
|
|
|
|
|
|
2020-09-26 12:21:00 +02:00
|
|
|
|
$this->_insertStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `zeit_translation`
|
2020-09-18 18:48:40 +02:00
|
|
|
|
(`zeit_id`, `trans_language`, `trans_name`)
|
|
|
|
|
VALUES
|
|
|
|
|
(?, ?, ?)");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __destruct() {
|
|
|
|
|
|
|
|
|
|
$this->_insertStmt->close();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|