fix a longstanding issue in AlternC: don't show translation links for

which AlternC is not translated

this is done by checking if the locales/LANG directory exists, so it's
not foolproof, but it's better than simply checking if the locale is
configured (which is still done).

a bit of code refactoring was done while i'm here
This commit is contained in:
Antoine Beaupré 2007-10-05 18:07:02 +00:00
parent a035c95f98
commit ed96566057
2 changed files with 8 additions and 12 deletions

View File

@ -132,11 +132,7 @@ closedir($c);
/* Language */
bindtextdomain("alternc", "/var/alternc/bureau/locales");
if (!$do_not_set_lang_env) {
include("lang_env.php");
}
include_once("lang_env.php");
$mem=new m_mem();
$err=new m_err();

View File

@ -1,28 +1,28 @@
<?php
function update_locale() {
global $locales;
function update_locale($langpath) {
$locales=array();
$f=@fopen("/etc/locale.gen","rb");
if ($f) {
$locales=array();
while ($s=fgets($f,1024)) {
if (preg_match("/^([a-z][a-z]_[A-Z][A-Z])/",trim($s),$mat)) {
if (preg_match("/^([a-z][a-z]_[A-Z][A-Z])/",trim($s),$mat) && file_exists($langpath . '/' . $mat[1])) {
$locales[$mat[1]]=$mat[1];
}
}
fclose($f);
}
return $locales;
}
// setlang is on the link at the login page
if (isset($_REQUEST["setlang"])) {
$lang=$_REQUEST["setlang"];
}
$locales=array("fr_FR"=>"fr_FR","en_US"=>"en_US");
$langpath = bindtextdomain("alternc", "/var/alternc/bureau/locales");
// Create or update a locale.php file if it is outdated.
update_locale();
$locales = update_locale($langpath);
if (!(isset($lang))) { // Use the browser first preferred language
$lang=strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]),0,5));