From 37e76038e5636f30fb37eb94fdbb13b9edff0d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LIBERT=20Je=CC=81re=CC=81my?= Date: Fri, 15 Feb 2019 14:17:37 +0100 Subject: [PATCH 1/3] Added start date in TextTransformer with translations --- src/Recurr/Transformer/TextTransformer.php | 6 ++++++ translations/da.php | 1 + translations/de.php | 1 + translations/el.php | 1 + translations/en.php | 1 + translations/es.php | 1 + translations/eu.php | 1 + translations/fr.php | 1 + translations/it.php | 1 + translations/nl.php | 1 + translations/no.php | 1 + translations/pt-br.php | 1 + translations/sv.php | 1 + translations/tr.php | 1 + 14 files changed, 19 insertions(+) diff --git a/src/Recurr/Transformer/TextTransformer.php b/src/Recurr/Transformer/TextTransformer.php index 0fdef0b..7c74969 100644 --- a/src/Recurr/Transformer/TextTransformer.php +++ b/src/Recurr/Transformer/TextTransformer.php @@ -39,6 +39,12 @@ public function transform(Rule $rule) return $this->translator->trans('Unable to fully convert this rrule to text.'); } + $startDate = $rule->getStartDate(); + if ($startDate instanceof \DateTimeInterface) { + $dateFormatted = $this->translator->trans('day_date', array('date' => $startDate->format('U'))); + $this->addFragment($this->translator->trans('from %date%', array('date' => $dateFormatted))); + } + $until = $rule->getUntil(); $count = $rule->getCount(); if ($until instanceof \DateTimeInterface) { diff --git a/translations/da.php b/translations/da.php index ba4d6b6..bfd1cdb 100644 --- a/translations/da.php +++ b/translations/da.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% gange', 'for one time' => 'en gang', '(~ approximate)' => '(~ cirka)', + 'from %date%' => 'fra %date%', 'until %date%' => 't.o.m. %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return date('j', $params['date']) . '. '. $months[date('n', $params['date']) - 1].date(', Y', $params['date']); diff --git a/translations/de.php b/translations/de.php index 9c836b8..ea9c1e6 100644 --- a/translations/de.php +++ b/translations/de.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% Mal', 'for one time' => 'einmal', '(~ approximate)' => '(~ ungefähr)', + 'from %date%' => 'von %date%', 'until %date%' => 'bis %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4. Juli, 2014 return date('j. ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']); diff --git a/translations/el.php b/translations/el.php index dc8c344..9103659 100644 --- a/translations/el.php +++ b/translations/el.php @@ -44,6 +44,7 @@ 'for %count% times' => 'για %count% φορές', 'for one time' => 'για μία φορά', '(~ approximate)' => '(~ κατά προσέγγιση)', + 'from %date%' => 'από το %date%', 'until %date%' => 'μέχρι %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months_genitive) { // outputs a day date, e.g. 4 Ιουλίου 2014 return date('j', $params['date']) . ' ' . $months_genitive[date('n', $params['date']) - 1] . ' '. date('Y', $params['date']); diff --git a/translations/en.php b/translations/en.php index a7c1276..c210154 100644 --- a/translations/en.php +++ b/translations/en.php @@ -30,6 +30,7 @@ 'for %count% times' => 'for %count% times', 'for one time' => 'once', '(~ approximate)' => '(~ approximate)', + 'from %date%' => 'from %date%', 'until %date%' => 'until %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']); diff --git a/translations/es.php b/translations/es.php index 991ad1d..435efb3 100644 --- a/translations/es.php +++ b/translations/es.php @@ -30,6 +30,7 @@ 'for %count% times' => 'para %count% veces', 'for one time' => 'por una vez', '(~ approximate)' => '(~ aproximado)', + 'from %date%' => 'desde %date%', 'until %date%' => 'hasta %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']); diff --git a/translations/eu.php b/translations/eu.php index 1c3adba..7bcedd4 100644 --- a/translations/eu.php +++ b/translations/eu.php @@ -5,6 +5,7 @@ 'for %count% times' => '%count% aldiz', 'for %count% time' => '%count% aldia', '(~ approximate)' => '(~ inguru)', + 'from %date%' => 'bertatik %date%', 'until %date%' => '%date% arte', // e.g. every year until July 4, 2014 'day_date' => defined('PHP_WINDOWS_VERSION_BUILD') ? '%B %#d, %Y' : '%B %e, %Y', 'and' => 'eta', diff --git a/translations/fr.php b/translations/fr.php index 6bc44a7..690fdfc 100644 --- a/translations/fr.php +++ b/translations/fr.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% fois', 'for one time' => 'une fois', '(~ approximate)' => '(~ approximation)', + 'from %date%' => 'à partir du %date%', 'until %date%' => 'jusqu\'au %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4 juillet, 2014 return date('j ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']); diff --git a/translations/it.php b/translations/it.php index 9f4d4c0..6eff984 100644 --- a/translations/it.php +++ b/translations/it.php @@ -30,6 +30,7 @@ 'for %count% times' => 'per %count% volte', 'for one time' => 'per una volta', '(~ approximate)' => '(~ approssimato)', + 'from %date%' => 'a partire dal %date%', 'until %date%' => 'fino al %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4 luglio, 2014 return date('j ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']); diff --git a/translations/nl.php b/translations/nl.php index 77b2718..6ed570e 100644 --- a/translations/nl.php +++ b/translations/nl.php @@ -30,6 +30,7 @@ 'for %count% times' => 'voor %count% keer', 'for one time' => 'eenmalig', '(~ approximate)' => '(~ ongeveer)', + 'from %date%' => 'van de %date%', 'until %date%' => 'tot en met %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return date('j', $params['date']).' '.$months[date('n', $params['date']) - 1] . ' '. date('Y', $params['date']); diff --git a/translations/no.php b/translations/no.php index e7b5c95..325b3df 100644 --- a/translations/no.php +++ b/translations/no.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% ganger', 'for one time' => 'en gang', '(~ approximate)' => '(~ omtrent)', + 'from %date%' => 'fra %date%', 'until %date%' => 'frem til %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']); diff --git a/translations/pt-br.php b/translations/pt-br.php index f731c52..e88a030 100644 --- a/translations/pt-br.php +++ b/translations/pt-br.php @@ -30,6 +30,7 @@ 'for %count% times' => 'por %count% vezes', 'for one time' => 'uma vez', '(~ approximate)' => '(~ approximado)', + 'from %date%' => 'do %date%', 'until %date%' => 'até %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return date('j', $params['date']) . ' de ' . $months[date('n', $params['date']) - 1] . ' de ' . date('Y', $params['date']); diff --git a/translations/sv.php b/translations/sv.php index 0dafeae..0e8ca5d 100644 --- a/translations/sv.php +++ b/translations/sv.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% gånger', 'for one time' => 'en gång', '(~ approximate)' => '(~ ungefärlig)', + 'until %date%' => 'från %date%', 'until %date%' => 't.o.m. %date%', // e.g. every year until July 4, 2014 'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014 return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']); diff --git a/translations/tr.php b/translations/tr.php index 33d5295..2ec23fe 100644 --- a/translations/tr.php +++ b/translations/tr.php @@ -30,6 +30,7 @@ 'for %count% times' => '%count% kez', 'for one time' => 'bir kere', '(~ approximate)' => '(~ yaklaşık)', + 'from %date%' => 'itibaren %date%', 'until %date%' => 'kadar %date%', // e.g. 4 Temmuz 2014 e kadar her yıl 'day_date' => function ($str, $params) use ($days, $months) { // tarih çıktıları, e.g. Temmuz 4, 2014 return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']); From 711845bb8e7b1c85f6a7c3c32938c2b571eb6cd0 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 4 Sep 2020 16:21:22 +0200 Subject: [PATCH 2/3] Added exclude parameter --- src/Recurr/Transformer/TextTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Recurr/Transformer/TextTransformer.php b/src/Recurr/Transformer/TextTransformer.php index 7c74969..0bce44d 100644 --- a/src/Recurr/Transformer/TextTransformer.php +++ b/src/Recurr/Transformer/TextTransformer.php @@ -14,7 +14,7 @@ public function __construct(TranslatorInterface $translator = null) $this->translator = $translator ?: new Translator('en'); } - public function transform(Rule $rule) + public function transform(Rule $rule, $exclude = array()) { $this->fragments = array(); From 9627ba1f44f5f2737921306ac09b4b81fd3f9cd7 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 4 Sep 2020 16:21:32 +0200 Subject: [PATCH 3/3] Handle excludes --- src/Recurr/Transformer/TextTransformer.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Recurr/Transformer/TextTransformer.php b/src/Recurr/Transformer/TextTransformer.php index 0bce44d..e5ca7d8 100644 --- a/src/Recurr/Transformer/TextTransformer.php +++ b/src/Recurr/Transformer/TextTransformer.php @@ -41,20 +41,26 @@ public function transform(Rule $rule, $exclude = array()) $startDate = $rule->getStartDate(); if ($startDate instanceof \DateTimeInterface) { - $dateFormatted = $this->translator->trans('day_date', array('date' => $startDate->format('U'))); - $this->addFragment($this->translator->trans('from %date%', array('date' => $dateFormatted))); + if (!in_array('startDate', $exclude)) { + $dateFormatted = $this->translator->trans('day_date', array('date' => $startDate->format('U'))); + $this->addFragment($this->translator->trans('from %date%', array('date' => $dateFormatted))); + } } $until = $rule->getUntil(); $count = $rule->getCount(); if ($until instanceof \DateTimeInterface) { - $dateFormatted = $this->translator->trans('day_date', array('date' => $until->format('U'))); - $this->addFragment($this->translator->trans('until %date%', array('date' => $dateFormatted))); + if (!in_array('until', $exclude)) { + $dateFormatted = $this->translator->trans('day_date', array('date' => $until->format('U'))); + $this->addFragment($this->translator->trans('until %date%', array('date' => $dateFormatted))); + } } else if (!empty($count)) { - if ($this->isPlural($count)) { - $this->addFragment($this->translator->trans('for %count% times', array('count' => $count))); - } else { - $this->addFragment($this->translator->trans('for one time')); + if (!in_array('count', $exclude)) { + if ($this->isPlural($count)) { + $this->addFragment($this->translator->trans('for %count% times', array('count' => $count))); + } else { + $this->addFragment($this->translator->trans('for one time')); + } } }