autotranslator.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env php
  2. <?php
  3. /* Copyright (C) 2009-2012 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 3 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file dev/translation/autotranslator.php
  20. * \ingroup dev
  21. * \brief This script uses google language ajax api as the translator engine
  22. * The main translator function can be found at:
  23. * defunct -http://code.google.com/intl/fr/apis/language/translate/overview.html-
  24. * defunct -http://translate.google.com/translate_tools-
  25. * https://code.google.com/apis/console
  26. */
  27. $sapi_type = php_sapi_name();
  28. $script_file = basename(__FILE__);
  29. $path=dirname(__FILE__).'/';
  30. // Test if batch mode
  31. if (substr($sapi_type, 0, 3) == 'cgi') {
  32. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  33. exit;
  34. }
  35. // Include Dolibarr environment
  36. require_once $path.'../../htdocs/master.inc.php';
  37. require_once $path.'../../htdocs/core/lib/files.lib.php';
  38. // After this $db is an opened handler to database. We close it at end of file.
  39. // Load main language strings
  40. $langs->load("main");
  41. // Global variables
  42. $version='1.14';
  43. $error=0;
  44. // -------------------- START OF YOUR CODE HERE --------------------
  45. @set_time_limit(0);
  46. print "***** ".$script_file." (".$version.") *****\n";
  47. $dir=DOL_DOCUMENT_ROOT."/langs";
  48. // Check parameters
  49. if (! isset($argv[3])) {
  50. print "Usage: ".$script_file." lang_code_src lang_code_dest|all APIKEY [langfile.lang]\n";
  51. print "Example: ".$script_file." en_US pt_PT 123456\n";
  52. print "Rem: lang_code to use can be found on https://translate.google.com\n";
  53. exit;
  54. }
  55. // Show parameters
  56. print 'Argument 1='.$argv[1]."\n";
  57. print 'Argument 2='.$argv[2]."\n";
  58. print 'Argument 3='.$argv[3]."\n";
  59. $file='';
  60. if (isset($argv[4]))
  61. {
  62. $file=$argv[4];
  63. print 'Argument 4='.$argv[4]."\n";
  64. }
  65. print 'Files will be generated/updated in directory '.$dir."\n";
  66. if ($argv[2] != 'all')
  67. {
  68. if (! is_dir($dir.'/'.$argv[2]))
  69. {
  70. print 'Create directory '.$dir.'/'.$argv[2]."\n";
  71. $result=mkdir($dir.'/'.$argv[2]);
  72. if (! $result)
  73. {
  74. $db->close();
  75. return -1;
  76. }
  77. }
  78. }
  79. require_once DOL_DOCUMENT_ROOT."/../dev/translation/autotranslator.class.php";
  80. $langParser = new autoTranslator($argv[2], $argv[1], $dir, $file, $argv[3]);
  81. print "***** Finished *****\n";
  82. // -------------------- END OF YOUR CODE --------------------
  83. $db->close();
  84. return $error;