Last active
December 10, 2015 10:19
-
-
Save dropmeaword/4420340 to your computer and use it in GitHub Desktop.
Rename the domain file to prevent caching from Apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* bypass gettext caching by using a clever file-renaming | |
* mechanism described in http://blog.ghost3k.net/articles/php/11/gettext-caching-in-php | |
*/ | |
static protected function spawnUncachedDomain($locale, $domain) { | |
// path to the .MO file that we should monitor | |
$filename = "locale/{$locale}/LC_MESSAGES/{$domain}.mo"; | |
$mtime = \filemtime($filename); // check its modification time | |
// our new unique .MO file | |
$filename_new = "locale/{$locale}/LC_MESSAGES/{$domain}_{$mtime}.mo"; | |
if (!\file_exists($filename_new)) { // check if we have created it before | |
// if not, create it now, by copying the original | |
\copy($filename,$filename_new); | |
//error_log("creating new domain {$filename_new}"); | |
} | |
// compute the new domain name | |
$domain_new = "{$domain}_{$mtime}"; | |
return $domain_new; | |
} | |
// generate a new uncached domain file if caching bypass featured is enabled | |
if(true == \GOTEO_GETTEXT_BYPASS_CACHING) { | |
$domain = Lang::spawnUncachedDomain($locale, $domain); | |
//error_log("bypassing gettext caching"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment