PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/jsls.php

https://code.google.com/p/ecartcommerce/
PHP | 101 lines | 66 code | 7 blank | 28 comment | 10 complexity | 97c9b67cc624c0ad1512df31cd676852 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Ecart
  4. *
  5. * This file is part of Ecart.
  6. *
  7. * Ecart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ecart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
  19. * @copyright Copyright 2008-2009 E-Cart LLC
  20. * @license GNU Public License V3.0
  21. */
  22. /**
  23. * JavaScript localization search
  24. * This script will find all language sensitive statements, that are thanslated via js function l() and output them to $output
  25. *
  26. * @category Ecart
  27. * @package Ecart_Core
  28. * @author Ecart Core Team <core@ecartcommerce.com>
  29. */
  30. $directories = array(
  31. 'D:/www/htdocs/ecartcommerce.com/public_html/ecart/js/ecart/admin',
  32. 'D:/www/htdocs/ecartcommerce.com/public_html/ecart/app/design/admin/default'
  33. );
  34. $allowedExtensions = array('phtml', 'js');
  35. $output = 'D:/core.js';
  36. $module = 'core';
  37. $allMatches = array();
  38. function scanDirectories(array $directories){
  39. foreach ($directories as $path) {
  40. scanDirectory($path);
  41. }
  42. }
  43. function scanDirectory($path){
  44. if (strstr("$path", '/.svn')) {
  45. echo 'SKIPPING ' . $path . "\n";
  46. } elseif (is_dir($path)) {
  47. echo 'SCANNING ' . $path . "\n";
  48. $dir = dir($path);
  49. while (false !== ($file = $dir->read())) {
  50. if ($file != '.' && $file != '..') {
  51. if (!is_link("$path/$file") && is_dir("$path/$file")) {
  52. scanDirectory("$path/$file");
  53. } else {
  54. scanFile("$path/$file");
  55. }
  56. }
  57. }
  58. $dir->close();
  59. }
  60. }
  61. function scanFile($path) {
  62. global $allMatches;
  63. global $allowedExtensions;
  64. $filename = basename($path);
  65. if (!in_array(substr($filename, strrpos($filename, '.') + 1), $allowedExtensions)) {
  66. return;
  67. }
  68. echo 'PARSING ' . $path . "\n";
  69. $regex = "/([\"][^\"|.]+[\"]).l\(\)|([\'][^'|.]+[\']).l\(/";
  70. $content = file_get_contents($path);
  71. $matches = array();
  72. if (preg_match_all($regex, $content, $matches) != 0) {
  73. $matches[1] = array_filter($matches[1]);
  74. $matches[2] = array_filter($matches[2]);
  75. foreach ($matches[1] as $string) {
  76. $string = str_replace('"', "'", $string);
  77. $allMatches[$string] = $string;
  78. }
  79. foreach ($matches[2] as $string) {
  80. $allMatches[$string] = $string;
  81. }
  82. }
  83. }
  84. scanDirectories($directories);
  85. $content = "Locale.module('{$module}', {\n";
  86. foreach ($allMatches as $string) {
  87. $content .= ' ' . $string . ': ' . $string . ",\n";
  88. }
  89. if (count($allMatches)) {
  90. $content = substr($content, 0, -2);
  91. }
  92. file_put_contents($output, $content . "\n});");