mirror of
https://github.com/rlanvin/php-rrule.git
synced 2024-11-28 05:24:10 +01:00
Update the review_translations script
This commit is contained in:
parent
44a3fdc6f4
commit
bd1a9f0648
@ -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)
|
||||
|
@ -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 <locale>``` 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 <locale>``` to print a list of examples using the locale specified (default is English).
|
||||
Use ```./bin/review_translations.php --rule "<rule>"``` to test a specific rule in all available locales.
|
||||
|
||||
## Note
|
||||
|
||||
|
144
bin/review_translations.php
Normal file
144
bin/review_translations.php
Normal file
@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use RRule\RRule;
|
||||
|
||||
require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
$args = array_merge([
|
||||
'locale' => null,
|
||||
'rule' => null,
|
||||
],getopt('h',[
|
||||
'locale:',
|
||||
'rule:',
|
||||
'help'
|
||||
])
|
||||
);
|
||||
|
||||
function display_usage() {
|
||||
echo <<<EOF
|
||||
Usage:
|
||||
--locale <locale> will output a set of example rules in one locale (default: en)
|
||||
--rule <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);
|
@ -1,92 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use RRule\RRule;
|
||||
|
||||
require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
$locale = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'en';
|
||||
|
||||
|
||||
$rruleExamples = 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,
|
||||
'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";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user