From bd1a9f0648041816725b661aae6b1832d0a85bd8 Mon Sep 17 00:00:00 2001 From: rlanvin Date: Sun, 4 Jul 2021 12:45:11 +0200 Subject: [PATCH] Update the review_translations script --- CHANGELOG.md | 5 ++ README.md | 6 +- bin/review_translations.php | 144 ++++++++++++++++++++++++++++++++++++ src/reviewTranslations.php | 92 ----------------------- 4 files changed, 152 insertions(+), 95 deletions(-) create mode 100644 bin/review_translations.php delete mode 100644 src/reviewTranslations.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c9f9b..eb1c4b8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +### Added + +- Added Swedish translation [#96](https://github.com/rlanvin/php-rrule/pull/96/) +- Added `bin/review_translations.php` as a helper for translators and contributors + ### Fixed - Fix Finnish translation [#94](https://github.com/rlanvin/php-rrule/issues/94) diff --git a/README.md b/README.md index 6a75456..d4451e4 100755 --- a/README.md +++ b/README.md @@ -59,10 +59,10 @@ Feel free to contribute! Just create a new issue or a new pull request. The coding style is (mostly) PSR-2, but with tabs. +### Translation -## Translation -Use ```php src/reviewTranslations ``` to print a list of examples using the -locale specified. The list is in no way exclusive, so add more examples to make proofing translations easier. +Use ```./bin/review_translations.php --locale ``` to print a list of examples using the locale specified (default is English). +Use ```./bin/review_translations.php --rule ""``` to test a specific rule in all available locales. ## Note diff --git a/bin/review_translations.php b/bin/review_translations.php new file mode 100644 index 0000000..fb6cf36 --- /dev/null +++ b/bin/review_translations.php @@ -0,0 +1,144 @@ +#!/usr/bin/env php + null, + 'rule' => null, + ],getopt('h',[ + 'locale:', + 'rule:', + 'help' + ]) +); + +function display_usage() { + echo << will output a set of example rules in one locale (default: en) + --rule will output a given rules in all available locales +EOF; +} + +if (isset($args['h']) || isset($args['help'])) { + display_usage(); + exit(); +} + +if (($args['locale'] && $args['rule']) || (!$args['locale'] && !$args['rule'])) { + echo "Error: choose either --locale or --rule\n"; + display_usage(); + exit(1); +} + +// display all the rules in one locale +if ($args['locale']) { + $rules = array( + array( + 'FREQ' => 'YEARLY', + 'INTERVAL' => 1, + 'DTSTART' => '2015-06-01', + 'COUNT' => 6 + ), + array( + 'FREQ' => 'MONTHLY', + 'INTERVAL' => 3, + 'DTSTART' => date_create('1997-01-01') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 2, + 'BYDAY' => 'TU', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 2, + 'BYDAY' => 'TU', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 2, + 'BYDAY' => 'TU,FR', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 1, + 'BYDAY' => 'TU', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 1, + 'BYDAY' => 'TU', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'YEARLY', + 'COUNT' => 1, + 'BYDAY' => 'TU', + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'HOURLY', + 'COUNT' => 1, + 'BYHOUR' => [21,22], + 'BYMINUTE' => [10,20,30], + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'MINUTELY', + 'COUNT' => 1, + 'BYHOUR' => 21, + 'BYMINUTE' => 01, + 'DTSTART' => date_create('1997-09-02 09:00') + ), + array( + 'FREQ' => 'MINUTELY', + 'BYHOUR' => 21, + 'BYMINUTE' => 10, + ), + array( + 'FREQ' => 'SECONDLY', + 'BYHOUR' => 21, + 'BYMINUTE' => 10, + 'BYSECOND' => 10, + ), + ); + + foreach ($rules as $index => $definition) { + $rrule = new RRule($definition); + printf( + "#%d\t%s\n", + $index, + $rrule->humanReadable(['locale' => $args['locale']]) + ); + } + + exit(); +} + +// display all the locales for one rule +if ($args['rule']) { + $rrule = new RRule($args['rule']); + $locales = glob(__DIR__."/../src/i18n/*.php"); + + foreach ($locales as $locale) { + $locale = basename($locale,'.php'); + printf( + "%s\t%s\n", + $locale, + $rrule->humanReadable(['locale' => $locale]) + ); + } + exit(); +} + +// should never reach this +display_usage(); +exit(1); \ No newline at end of file diff --git a/src/reviewTranslations.php b/src/reviewTranslations.php deleted file mode 100644 index f982b37..0000000 --- a/src/reviewTranslations.php +++ /dev/null @@ -1,92 +0,0 @@ - 'YEARLY', - 'INTERVAL' => 1, - 'DTSTART' => '2015-06-01', - 'COUNT' => 6 - ), - array( - 'FREQ' => 'MONTHLY', - 'INTERVAL' => 3, - 'DTSTART' => date_create('1997-01-01') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 2, - 'BYDAY' => 'TU', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 2, - 'BYDAY' => 'TU', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 2, - 'BYDAY' => 'TU,FR', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 1, - 'BYDAY' => 'TU', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 1, - 'BYDAY' => 'TU', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'YEARLY', - 'COUNT' => 1, - 'BYDAY' => 'TU', - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'HOURLY', - 'COUNT' => 1, - 'BYHOUR' => 21, - 'BYMINUTE' => 10, - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'MINUTELY', - 'COUNT' => 1, - 'BYHOUR' => 21, - 'BYMINUTE' => 10, - 'DTSTART' => date_create('1997-09-02 09:00') - ), - array( - 'FREQ' => 'MINUTELY', - 'BYHOUR' => 21, - 'BYMINUTE' => 10, - ), - array( - 'FREQ' => 'SECONDLY', - 'BYHOUR' => 21, - 'BYMINUTE' => 10, - 'BYSECOND' => 10, - ), -); - -foreach ($rruleExamples as $rruleExampleNr => $rruleDefinition) { - $rrule = new RRule($rruleDefinition); - echo '$rruleExamples #' . $rruleExampleNr . ': ' . $rrule->humanReadable(['locale' => $locale]) . "\n"; - - -} - -