manipulate.translation.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. $options = getopt("h");
  3. if (array_key_exists('h', $options)) {
  4. help();
  5. }
  6. if (1 === $argc || 5 < $argc) {
  7. help();
  8. }
  9. require_once __DIR__ . '/i18n/I18nFile.php';
  10. $i18nFile = new I18nFile();
  11. $i18nData = $i18nFile->load();
  12. switch ($argv[1]) {
  13. case 'add_language' :
  14. $i18nData->addLanguage($argv[2]);
  15. break;
  16. case 'add_key' :
  17. if (3 === $argc) {
  18. help();
  19. }
  20. $i18nData->addKey($argv[2], $argv[3]);
  21. break;
  22. case 'add_value':
  23. if (4 === $argc) {
  24. help();
  25. }
  26. $i18nData->addValue($argv[2], $argv[3], $argv[4]);
  27. break;
  28. case 'duplicate_key' :
  29. $i18nData->duplicateKey($argv[2]);
  30. break;
  31. case 'delete_key' :
  32. $i18nData->removeKey($argv[2]);
  33. break;
  34. case 'format' :
  35. $i18nFile->dump($i18nData);
  36. break;
  37. default :
  38. help();
  39. }
  40. if ($i18nData->hasChanged()) {
  41. $i18nFile->dump($i18nData);
  42. }
  43. /**
  44. * Output help message.
  45. */
  46. function help() {
  47. $help = <<<HELP
  48. NAME
  49. %s
  50. SYNOPSIS
  51. php %s [OPTION] [OPERATION] [KEY] [VALUE] [LANGUAGE]
  52. DESCRIPTION
  53. Manipulate translation files. Available operations are
  54. Check if translation files have missing keys or missing translations.
  55. -h display this help and exit.
  56. OPERATION
  57. add_language
  58. add a new language by duplicating the referential. This operation
  59. needs only a KEY.
  60. add_key add a new key in the referential. This operation needs a KEY and
  61. a VALUE.
  62. add_value
  63. add a value in the referential. This operation needs a KEY, a
  64. VALUE, and a LANGUAGE.
  65. duplicate_key
  66. duplicate a referential key in other languages. This operation
  67. needs only a KEY.
  68. delete_key
  69. delete a referential key from all languages. This operation needs
  70. only a KEY.
  71. format format i18n files.
  72. HELP;
  73. $file = str_replace(__DIR__ . '/', '', __FILE__);
  74. echo sprintf($help, $file, $file);
  75. exit;
  76. }