protected function getHelp()\r
{\r
$help = <<<HELP\r
-console php2po - Generate a messages.po file from a string.php file\r
+console php2po - Generate a messages.po file from a strings.php file\r
Usage\r
- bin/console php2po [-p <n>] <path/to/strings.php> [-h|--help|-?] [-v]\r
-\r
-Options:\r
- -p <n> Number of plural forms/ Default: 2\r
+ bin/console php2po [-p <n>] [--base <file>] <path/to/strings.php> [-h|--help|-?] [-v]\r
\r
Description\r
Read a strings.php file and create the according messages.po in the same directory\r
\r
Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
+ -p <n> Number of plural forms. Default: 2\r
+ --base <file> Path to base messages.po file. Default: util/messages.po\r
+ -h|--help|-? Show help information\r
+ -v Show more debug information.\r
HELP;\r
return $help;\r
}\r
throw new \RuntimeException('Supplied directory isn\'t writable.');\r
}\r
\r
- $pofile = dirname($phpfile) . '/messages.po';\r
+ $pofile = dirname($phpfile) . DIRECTORY_SEPARATOR . 'messages.po';\r
\r
// start !\r
include_once($phpfile);\r
// search for plural info\r
$lang = "";\r
$lang_logic = "";\r
- $lang_pnum = 2;\r
-\r
- $_idx = array_search('-p', $argv);\r
- if ($_idx !== false) {\r
- $lang_pnum = $argv[$_idx + 1];\r
- }\r
+ $lang_pnum = $this->getOption('p', 2);\r
\r
$infile = file($phpfile);\r
foreach ($infile as $l) {\r
$out .= sprintf('"Plural-Forms: nplurals=%s; plural=%s;\n"', $lang_pnum, $lang_logic) . "\n";\r
$out .= "\n";\r
\r
- $this->out('Loading base message.po...');\r
+ $base_path = $this->getOption('base', 'util' . DIRECTORY_SEPARATOR . 'messages.po');\r
\r
// load base messages.po and extract msgids\r
$base_msgids = [];\r
- $base_f = file("util/messages.po");\r
+ $base_f = file($base_path);\r
if (!$base_f) {\r
- throw new \RuntimeException('The base util/messages.po file is missing.');\r
+ throw new \RuntimeException('The base ' . $base_path . ' file is missing or unavailable to read.');\r
}\r
\r
+ $this->out('Loading base file ' . $base_path . '...');\r
+\r
$_f = 0;\r
$_mid = "";\r
$_mids = [];\r
}\r
}\r
\r
- $this->out('Done.');\r
$this->out('Creating ' . $pofile . '...');\r
\r
// create msgid and msgstr\r
$out .= "\n";\r
}\r
\r
- file_put_contents($pofile, $out);\r
-\r
- $this->out('Done.');\r
+ if (!file_put_contents($pofile, $out)) {\r
+ throw new \RuntimeException('Unable to write to ' . $pofile);\r
+ }\r
\r
- if ($warnings == "") {\r
- $this->out('No warnings.');\r
- } else {\r
+ if ($warnings != '') {\r
$this->out($warnings);\r
}\r
\r