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 */ /* Language */
bindtextdomain("alternc", "/var/alternc/bureau/locales"); include_once("lang_env.php");
if (!$do_not_set_lang_env) {
include("lang_env.php");
}
$mem=new m_mem(); $mem=new m_mem();
$err=new m_err(); $err=new m_err();

View File

@ -1,28 +1,28 @@
<?php <?php
function update_locale() { function update_locale($langpath) {
global $locales; $locales=array();
$f=@fopen("/etc/locale.gen","rb"); $f=@fopen("/etc/locale.gen","rb");
if ($f) { if ($f) {
$locales=array();
while ($s=fgets($f,1024)) { 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]; $locales[$mat[1]]=$mat[1];
} }
} }
fclose($f); fclose($f);
} }
return $locales;
} }
// setlang is on the link at the login page // setlang is on the link at the login page
if (isset($_REQUEST["setlang"])) { if (isset($_REQUEST["setlang"])) {
$lang=$_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. // 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 if (!(isset($lang))) { // Use the browser first preferred language
$lang=strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]),0,5)); $lang=strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]),0,5));