js_localize.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /** This file is part of KCFinder project
  3. *
  4. * @desc Load language labels into JavaScript
  5. * @package KCFinder
  6. * @version 3.12
  7. * @author Pavel Tzonkov <sunhater@sunhater.com>
  8. * @copyright 2010-2014 KCFinder Project
  9. * @license http://opensource.org/licenses/GPL-3.0 GPLv3
  10. * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  11. * @link http://kcfinder.sunhater.com
  12. */
  13. namespace kcfinder;
  14. require "core/autoload.php";
  15. if (!isset($_GET['lng']) || ($_GET['lng'] == 'en') ||
  16. ($_GET['lng'] != basename($_GET['lng'])) ||
  17. !is_file("lang/" . $_GET['lng'] . ".php")
  18. ) {
  19. header("Content-Type: text/javascript");
  20. die;
  21. }
  22. $file = "lang/" . $_GET['lng'] . ".php";
  23. $mtime = @filemtime($file);
  24. if ($mtime)
  25. httpCache::checkMTime($mtime, "Content-Type: text/javascript");
  26. require $file;
  27. header("Content-Type: text/javascript");
  28. echo "_.labels={";
  29. $i = 0;
  30. foreach ($lang as $english => $native) {
  31. if (substr($english, 0, 1) != "_") {
  32. echo "'" . text::jsValue($english) . "':\"" . text::jsValue($native) . "\"";
  33. if (++$i < count($lang))
  34. echo ",";
  35. }
  36. }
  37. echo "}";
  38. ?>