autotranslator.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file dev/translation/autotranslator.php
  20. * \ingroup mymodule othermodule1 othermodule2
  21. * \brief This file is an example for a command line script
  22. * \author Put author name here
  23. * \remarks Put here some comments
  24. */
  25. $sapi_type = php_sapi_name();
  26. $script_file = basename(__FILE__);
  27. $path=dirname(__FILE__).'/';
  28. // Test if batch mode
  29. if (substr($sapi_type, 0, 3) == 'cgi') {
  30. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  31. exit;
  32. }
  33. // Include Dolibarr environment
  34. require_once($path.'../../htdocs/master.inc.php');
  35. require_once($path.'../../htdocs/lib/files.lib.php');
  36. // After this $db is an opened handler to database. We close it at end of file.
  37. // Load main language strings
  38. $langs->load("main");
  39. // Global variables
  40. $version='$Revision: 1.14 $';
  41. $error=0;
  42. // -------------------- START OF YOUR CODE HERE --------------------
  43. @set_time_limit(0);
  44. print "***** ".$script_file." (".$version.") *****\n";
  45. $dir=DOL_DOCUMENT_ROOT."/langs";
  46. // Check parameters
  47. if (! isset($argv[2])) {
  48. print "Usage: ".$script_file." lang_code_src lang_code_dest|all [langfile.lang]\n";
  49. print "Example: ".$script_file." en_US pt_PT\n";
  50. print "Rem: lang_code to use can be found on http://www.google.com/language_tools\n";
  51. exit;
  52. }
  53. // Show parameters
  54. print 'Argument 1='.$argv[1]."\n";
  55. print 'Argument 2='.$argv[2]."\n";
  56. $file='';
  57. if (isset($argv[3]))
  58. {
  59. $file=$argv[3];
  60. print 'Argument 3='.$argv[3]."\n";
  61. }
  62. print 'Files will be generated/updated in directory '.$dir."\n";
  63. if ($argv[2] != 'all')
  64. {
  65. if (! is_dir($dir.'/'.$argv[2]))
  66. {
  67. print 'Create directory '.$dir.'/'.$argv[2]."\n";
  68. $result=mkdir($dir.'/'.$argv[2]);
  69. if (! $result)
  70. {
  71. $db->close();
  72. return -1;
  73. }
  74. }
  75. }
  76. // Examples for manipulating class skeleton_class
  77. require_once(DOL_DOCUMENT_ROOT."/../dev/translation/langAutoParser.class.php");
  78. $langParser = new langAutoParser($argv[2],$argv[1],$dir,$file);
  79. print "***** Finished *****\n";
  80. // -------------------- END OF YOUR CODE --------------------
  81. $db->close();
  82. return $error;
  83. ?>