diff options
author | Romain d'Alverny <rda@mageia.org> | 2012-06-11 12:15:14 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2012-06-11 12:15:14 +0000 |
commit | c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6 (patch) | |
tree | 31c9cda40a6e771dbb91b9b33cf7c1aa0fe3d0e5 | |
parent | a8f8f22fb0f291fe76c2248750c81874b7572b9a (diff) | |
download | nav-c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6.tar nav-c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6.tar.gz nav-c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6.tar.bz2 nav-c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6.tar.xz nav-c8583d2ce236c7ddd8fddf5e93924d6b7e1a9bf6.zip |
cache .lang files in PHP array
-rw-r--r-- | lib.php | 43 |
1 files changed, 39 insertions, 4 deletions
@@ -118,16 +118,51 @@ class l10n * * @return void */ - function load($lang) { - $lang_file = __DIR__ . '/langs/' . $lang . '.lang'; + function load($lang) + { + global $_t; + $_t = array(); + + if ($lang == 'en') + return; + + $lang_file = __DIR__ . '/langs/' . $lang . '.lang'; + $cache_file = __DIR__ . '/var/tmp/cache/nav_lang_' . $lang . '.php'; + $lang_ts = filemtime($lang_file); + + if (file_exists($cache_file)) { + include $cache_file; + if ($_ts > $lang_ts) + return; + } + if (file_exists($lang_file)) { - global $_t; + $f = file($lang_file); + foreach ($f as $k => $v) { - if (substr($v, 0, 1) == ';' && !empty($f[$k+1])) { + + if (substr($v, 0, 1) == ';' + && !empty($f[$k+1])) + { $_t[trim(substr($v, 1))] = trim($f[$k+1]); } } + + // + $_t_data = var_export($_t, true); + $cache = <<<P +<?php +/**! Generated. Do not edit. */ + +// filemtime($lang_file) +\$_ts = $lang_ts; + +// $lang strings +global \$_t; +\$_t = $_t_data; +P; + file_put_contents($cache_file, $cache); } } |