language : Add a working cache management. No need to restart Apache after upgrade of .mo files if a cache directory is available
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2934 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
70
language.php
70
language.php
@@ -19,6 +19,10 @@ class language
|
|||||||
// The only available codeset is UTF8
|
// The only available codeset is UTF8
|
||||||
// The languages are always in the format fr_FR (without the codeset)
|
// The languages are always in the format fr_FR (without the codeset)
|
||||||
|
|
||||||
|
|
||||||
|
/** Language cache directory */
|
||||||
|
public $cacheDir = "data/locale";
|
||||||
|
|
||||||
/** Choose the best language in the browser list and which is available in
|
/** Choose the best language in the browser list and which is available in
|
||||||
locale path
|
locale path
|
||||||
@param string|null $repLocale Directory where are stored the translations
|
@param string|null $repLocale Directory where are stored the translations
|
||||||
@@ -210,51 +214,39 @@ class language
|
|||||||
$category = $this->languageCategoryText ($category);
|
$category = $this->languageCategoryText ($category);
|
||||||
$temporaries = glob ("$repLocale/$languageCode.$codeset/$category/*-*.mo");
|
$temporaries = glob ("$repLocale/$languageCode.$codeset/$category/*-*.mo");
|
||||||
$moFile = "$repLocale/$languageCode.$codeset/$category/$package.mo";
|
$moFile = "$repLocale/$languageCode.$codeset/$category/$package.mo";
|
||||||
$link = "$repLocale/$languageCode.$codeset/$category/$package-".
|
$linkBase = $this->cacheDir."/$languageCode.$codeset/$category/".
|
||||||
time().".mo";
|
"$package-";
|
||||||
|
$link = $linkBase.filemtime($moFile).".mo";
|
||||||
if (! file_exists ($moFile))
|
if (! file_exists ($moFile))
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
// Manage the cache directory
|
||||||
|
if (! file_exists (dirname ($link)))
|
||||||
|
{
|
||||||
|
// Try to create the cache dir. If there is an error, return the official
|
||||||
|
// moFile. Apache will need to be restarted
|
||||||
|
@mkdir (dirname ($link), 0777, true);
|
||||||
|
}
|
||||||
|
if (is_dir (dirname ($link)) && is_writeable (dirname ($link)) &&
|
||||||
|
is_readable (dirname ($link)))
|
||||||
|
{
|
||||||
|
// Manage the cache file
|
||||||
|
if (! file_exists ($link) || ! is_readable ($link) ||
|
||||||
|
filemtime ($moFile) > filemtime ($link))
|
||||||
|
{
|
||||||
|
$files = glob ("$linkBase*");
|
||||||
|
array_map ("unlink", $files);
|
||||||
|
copy ($moFile, $link);
|
||||||
|
chmod ($link, 0666);
|
||||||
|
}
|
||||||
|
if (filemtime ($moFile) <= filemtime ($link))
|
||||||
|
{
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
}
|
||||||
clearstatcache (false, $moFile);
|
clearstatcache (false, $moFile);
|
||||||
return $moFile;
|
return $moFile;
|
||||||
/* if (! is_writeable (dirname ($moFile)))
|
|
||||||
{
|
|
||||||
// Si le répertoire est protégé en écriture, on donne le fichier original.
|
|
||||||
// On devra relancer Apache pour prendre en compte une modification
|
|
||||||
return $moFile;
|
|
||||||
}
|
|
||||||
if (count ($temporaries) > 1)
|
|
||||||
{
|
|
||||||
// Too much links are available : delete all and recreate it
|
|
||||||
foreach ($temporaries as $temp)
|
|
||||||
{
|
|
||||||
unlink ($temp);
|
|
||||||
}
|
|
||||||
$temporaries = array ();
|
|
||||||
}
|
|
||||||
if (empty ($temporaries))
|
|
||||||
{
|
|
||||||
// Create the cache
|
|
||||||
copy ($moFile, $link);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The cache exists. Is it up to date ?
|
|
||||||
$cache = $temporaries[0];
|
|
||||||
if (filemtime ($cache) < filemtime ($moFile))
|
|
||||||
{
|
|
||||||
// Obsolete cache : recreate it
|
|
||||||
unlink ($cache);
|
|
||||||
copy ($moFile, $link);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Up to date cache
|
|
||||||
$link = $cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $link;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function languageActivation ($moFile, $languageCode, $category = LC_MESSAGES,
|
function languageActivation ($moFile, $languageCode, $category = LC_MESSAGES,
|
||||||
|
|||||||
Reference in New Issue
Block a user