autotranslator.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $file=$argv[4];
  62. print 'Argument 4='.$argv[4]."\n";
  63. }
  64. print 'Files will be generated/updated in directory '.$dir."\n";
  65. if ($argv[2] != 'all') {
  66. if (! is_dir($dir.'/'.$argv[2])) {
  67. print 'Create directory '.$dir.'/'.$argv[2]."\n";
  68. $result=mkdir($dir.'/'.$argv[2]);
  69. if (! $result) {
  70. $db->close();
  71. return -1;
  72. }
  73. }
  74. }
  75. require_once DOL_DOCUMENT_ROOT."/../dev/translation/autotranslator.class.php";
  76. $langParser = new autoTranslator($argv[2], $argv[1], $dir, $file, $argv[3]);
  77. print "***** Finished *****\n";
  78. // -------------------- END OF YOUR CODE --------------------
  79. $db->close();
  80. return $error;