manipulate.translation.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. $options = getopt("h");
  3. if (array_key_exists('h', $options)) {
  4. help();
  5. }
  6. if (1 === $argc || 4 < $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 'duplicate_key' :
  23. $i18nData->duplicateKey($argv[2]);
  24. break;
  25. case 'delete_key' :
  26. $i18nData->removeKey($argv[2]);
  27. break;
  28. default :
  29. help();
  30. }
  31. if ($i18nData->hasChanged()) {
  32. $i18nFile->dump($i18nData);
  33. }
  34. /**
  35. * Output help message.
  36. */
  37. function help() {
  38. $help = <<<HELP
  39. NAME
  40. %s
  41. SYNOPSIS
  42. php %s [OPTION] [OPERATION] [KEY] [VALUE]
  43. DESCRIPTION
  44. Manipulate translation files. Available operations are
  45. Check if translation files have missing keys or missing translations.
  46. -h display this help and exit.
  47. OPERATION
  48. add_language
  49. add a new language by duplicating the referential. This operation
  50. needs only a KEY.
  51. add_key add a new key in the referential. This operation needs a KEY and
  52. a VALUE.
  53. duplicate_key
  54. duplicate a referential key in other languages. This operation
  55. needs only a KEY.
  56. delete_key
  57. delete a referential key from all languages. This operation needs
  58. only a KEY.
  59. HELP;
  60. $file = str_replace(__DIR__ . '/', '', __FILE__);
  61. echo sprintf($help, $file, $file);
  62. exit;
  63. }