2005-01-31 20:32:49 +00:00
< ? php
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
$lang_language_dir = " ../languages/ " ;
$lang_translations_dir = " translations/ " ;
2005-02-17 12:26:04 +00:00
$lang_prj_translations_dir = " project_specific_translations/ " ;
2005-01-31 20:32:49 +00:00
$lang_compiled_dir = " compiled/ " ;
$lang_project_default = " en " ;
2005-02-24 18:48:12 +00:00
$lang_log_level = 0 ;
$lang_log_file = $lang_language_dir . " translator.log " ;
2005-01-31 20:32:49 +00:00
2007-05-06 22:38:43 +00:00
/**
* Fetches a list of compiled languages from the directory
* set to contain such files .
*/
2005-04-02 15:49:30 +00:00
function getSupportedLanguages (){
global $lang_language_dir , $lang_compiled_dir ;
if ( is_dir ( $lang_language_dir . $lang_compiled_dir )) {
2005-04-02 18:37:22 +00:00
if ( $dh = opendir ( $lang_language_dir . $lang_compiled_dir )) { //If dir exists
while (( $file = readdir ( $dh )) !== false ) {
//read contents
2005-10-29 04:56:33 +00:00
if ( substr ( $file , - 7 ) != " .po.inc " ) continue ;
if ( is_numeric ( substr ( $file , 0 , 5 ))) continue ;
$list [] = substr ( $file , 0 , - 7 );
2005-04-02 18:37:22 +00:00
}
}
2007-05-06 22:38:43 +00:00
} else {
echo " \" " . $lang_language_dir . $lang_compiled_dir . " \" is not a directory. Please consult the documentation for correctly setting up the translation system. " ;
exit ;
}
2005-04-02 15:49:30 +00:00
return $list ;
}
function trSpecific ( $tokennumber , $language = " " ){
global $lang_language_dir , $lang_compiled_dir ;
$language = substr ( $language , 0 , 5 );
2005-04-02 18:37:22 +00:00
if ( $language != " " && file_exists ( $lang_language_dir . $lang_compiled_dir . $language . " .po.inc " )){
//If we have the language, include it
//echo "[$language]";
require ( $lang_language_dir . $lang_compiled_dir . $language . " .po.inc " );
return stripslashes ( $language_lookup_array [ $tokennumber ]);
2005-04-02 15:49:30 +00:00
} else {
2005-04-02 18:37:22 +00:00
return false ;
2005-04-02 15:49:30 +00:00
}
}
2005-01-31 20:32:49 +00:00
/*************************
2005-02-17 12:26:04 +00:00
* Parses the language interface file containing the tokens ( can parse . po - style files )
2005-01-31 20:32:49 +00:00
************************/
function parseLanguageInterface ( $file ){
2005-02-17 12:26:04 +00:00
$translation_file = file ( $file );
for ( $i = 0 ; $i < sizeof ( $translation_file ); $i ++ ){
2005-04-02 18:37:22 +00:00
$entry = ltrim ( trim ( $translation_file [ $i ]));
if (( $pos = strpos ( $entry , " msgid " )) !== false ){
//If found msgid entry
$token = getPOLineContent ( $entry );
if ( ltrim ( trim ( $token )) != " " ){
$interface [] = $token ;
}
}
2005-01-31 20:32:49 +00:00
}
return $interface ;
}
/***************************
* Builds the lookup arrays from the language interface file
* and the language files found in the $dir directory subtree
***************************/
2005-02-17 12:26:04 +00:00
function buildLanguages ( $langdir , $transdir , $prjtransdir , $compdir ){
global $lang_project_default ;
2005-03-02 13:33:07 +00:00
2005-10-29 05:30:57 +00:00
$actual_compdir = $compdir ;
// Store the actual compile dir, we want to use a temporary addition
$randomness = rand ( 10000 , 99999 ) . " _ " ;
//Concat some randomness to the temporary dir, we'll rename files later
$compdir .= $randomness ;
// This is to ensure that no problems arise even when
// the filesystem fails to ensure mutual exclusion for
// compile timer tests. This way a new file will simply
// overwrite the old one instead of garbling it if 2 processes
// of this compiler runs concurrently.
// The reason why we are using filename prefixes here
// is that on some installations PHP isn't allowed
// to create and use new directories
// (due to wrong permissions or SELinux restrictions).
// Touch compile timer
//
2005-04-02 18:37:22 +00:00
$fh = fopen ( $langdir . " last_compile_timer " , " w " );
2005-03-02 13:33:07 +00:00
fwrite ( $fh , time ());
fclose ( $fh );
2005-10-29 05:30:57 +00:00
// First build the list of defines for the tokens
// and place it in an include file in the directory
2005-04-02 18:37:22 +00:00
//
2006-05-09 18:25:15 +00:00
$interface = parseLanguageInterface (
$langdir . $transdir . $lang_project_default . " .po "
);
2005-04-02 18:37:22 +00:00
if ( ! $fh = fopen ( $langdir . $compdir . " language_interface.inc " , " w " )) {
2006-05-09 18:25:15 +00:00
language_log (
" Could not access $langdir $compdir - please check permissions " , 2
);
2005-04-02 18:37:22 +00:00
exit ;
2005-10-29 05:30:57 +00:00
}
2005-01-31 20:32:49 +00:00
fwrite ( $fh , " <?php \n " );
for ( $i = 0 ; $i < sizeof ( $interface ); $i ++ ){
2005-04-02 18:37:22 +00:00
//Translate to PHP
2005-10-01 18:19:28 +00:00
fwrite ( $fh , " define( \" " . $interface [ $i ] . " \" , " . $i . " ); \n " );
2007-08-25 13:28:01 +00:00
fwrite ( $fh , " \$ translation_strings[ \" " . $interface [ $i ] . " \" ] = " . $i . " ; \n " );
2005-01-31 20:32:49 +00:00
}
fwrite ( $fh , '?>' );
fclose ( $fh );
2005-02-17 12:26:04 +00:00
$real_interface_size = sizeof ( $interface );
2005-01-31 20:32:49 +00:00
2005-10-29 05:30:57 +00:00
// Now run through each language and recompile their lookup arrays.
2005-04-02 18:37:22 +00:00
//
2005-01-31 20:32:49 +00:00
if ( is_dir ( $langdir . $transdir )) {
2005-04-02 18:37:22 +00:00
if ( $dh = opendir ( $langdir . $transdir )) {
//If dir exists
while (( $file = readdir ( $dh )) !== false ) {
//read contents
2005-01-31 20:32:49 +00:00
if ( $file == " .. " or $file == " . " ){
2005-04-02 18:37:22 +00:00
} else if ( substr ( $file , - 3 ) == " .po " ){
//only files ending in .po
2006-05-09 18:25:15 +00:00
language_log ( " -------------Compiling $file ------------ " , 0 );
$language = parseLanguage (
$langdir . $transdir . $file , $interface
);
2005-04-02 18:37:22 +00:00
if ( ! $fh = fopen ( $langdir . $compdir . $file . " .inc " , " w " )) {
2006-05-09 18:25:15 +00:00
language_log (
" ERROR: could not access $langdir $compdir - please check permissions " , 2
);
2005-04-02 18:37:22 +00:00
exit ;
2005-10-29 05:30:57 +00:00
}
2005-04-02 18:37:22 +00:00
fwrite ( $fh , " <?php \n " );
2007-05-15 21:41:59 +00:00
fwrite ( $fh , '$s = \'$s\'' . " ; \n " ); // Quick Kludge
2005-04-02 18:37:22 +00:00
$keys = array_keys ( $language );
for ( $i = 0 ; $i < sizeof ( $interface ); $i ++ ){
2007-11-23 19:11:42 +00:00
if ( isset ( $keys [ $i ]) && isset ( $language [ $keys [ $i ]])) {
if ( $language [ $keys [ $i ]] == " " ) {
//If the msgstr is empty, use the msgid instead
2008-01-15 22:22:08 +00:00
fwrite ( $fh , " \$ language_lookup_array[ " . $keys [ $i ] . " ] = \" " . $interface [ $keys [ $i ]] . " \" ; \n " );
2007-11-23 19:11:42 +00:00
} else {
2008-01-15 22:22:08 +00:00
fwrite ( $fh , " \$ language_lookup_array[ " . $keys [ $i ] . " ] = \" " . $language [ $keys [ $i ]] . " \" ; \n " );
2007-11-23 19:11:42 +00:00
}
2005-04-02 18:37:22 +00:00
}
}
fwrite ( $fh , '?>' );
fclose ( $fh );
2005-01-31 20:32:49 +00:00
} else {
2005-04-02 18:37:22 +00:00
//debug("File $file with unknown extension found in $info_dir");
}
2005-01-31 20:32:49 +00:00
}
closedir ( $dh );
} else {
2005-04-02 18:37:22 +00:00
//debug("$info_dir could not be opened - check permissions?");
}
2005-01-31 20:32:49 +00:00
} else {
2005-04-02 18:37:22 +00:00
//debug("$info_dir not found or is not a directory");
2005-01-31 20:32:49 +00:00
}
2005-02-17 12:26:04 +00:00
2005-04-02 18:37:22 +00:00
//Do the same again, this time for the project specific language files
// and instead of creating new compiled files
// just add to whatever existing ones
//
2005-02-17 12:26:04 +00:00
if ( is_dir ( $langdir . $prjtransdir )) {
2005-04-02 18:37:22 +00:00
$interface = parseLanguageInterface ( $langdir . $prjtransdir . $lang_project_default . " .po " );
if ( ! $fh = fopen ( $langdir . $compdir . " language_interface.inc " , " a " )) {
language_log ( " ERROR: could not access $langdir $compdir - please check permissions " , 2 );
exit ;
2005-10-29 05:30:57 +00:00
}
2005-04-02 18:37:22 +00:00
fwrite ( $fh , " <?php \n " );
for ( $i = 0 ; $i < sizeof ( $interface ); $i ++ ){
2005-10-01 18:19:28 +00:00
fwrite ( $fh , " define( \" " . $interface [ $i ] . " \" , " . ( $i + $real_interface_size ) . " ); \n " );
2007-08-25 13:30:08 +00:00
fwrite ( $fh , " \$ translation_strings[ \" " . $interface [ $i ] . " \" ] = " . $i + $real_interface_size . " ; \n " );
2005-04-02 18:37:22 +00:00
}
fwrite ( $fh , '?>' );
fclose ( $fh );
if ( $dh = opendir ( $langdir . $prjtransdir )) {
//If dir exists
while (( $file = readdir ( $dh )) !== false ) {
//read contents
2005-10-29 05:30:57 +00:00
if ( $file == " .. " or $file == " . " ) continue ;
if ( substr ( $file , - 3 ) == " .po " ){
2005-04-02 18:37:22 +00:00
//only files ending in .po
language_log ( " ----------------Compiling project specific $file --------------- " , 0 );
$language = parseLanguage ( $langdir . $prjtransdir . $file , $interface );
if ( ! $fh = fopen ( $langdir . $compdir . $file . " .inc " , " a " )) {
language_log ( " ERROR: could not access $langdir $compdir - please check permissions " , 2 );
exit ;
2005-10-29 05:30:57 +00:00
}
2005-04-02 18:37:22 +00:00
fwrite ( $fh , " <?php \n " );
2007-05-15 21:41:59 +00:00
fwrite ( $fh , '$s = \'$s\'' . " ; \n " ); // Quick Kludge
2005-04-02 18:37:22 +00:00
$keys = array_keys ( $language );
for ( $i = 0 ; $i < sizeof ( $interface ); $i ++ ){
if ( $language [ $keys [ $i ]] != " " ) {
2008-01-15 22:22:08 +00:00
fwrite ( $fh , " \$ language_lookup_array[ " . ( $real_interface_size + $keys [ $i ]) . " ] = \" " . $language [ $keys [ $i ]] . " \" ; \n " ); //Translate to PHP
2005-04-02 18:37:22 +00:00
}
}
fwrite ( $fh , '?>' );
fclose ( $fh );
2005-02-17 12:26:04 +00:00
} else {
2005-04-02 18:37:22 +00:00
//debug("File $file with unknown extension found in $info_dir");
}
2005-02-17 12:26:04 +00:00
}
closedir ( $dh );
} else {
2005-04-02 18:37:22 +00:00
//debug("$info_dir could not be opened - check permissions?");
}
2005-02-17 12:26:04 +00:00
} else {
2005-04-02 18:37:22 +00:00
//debug("$info_dir not found or is not a directory");
2005-02-17 12:26:04 +00:00
}
2005-09-07 15:54:35 +00:00
//Lastly we will rename the files to their real names (remove the random prefix):
2005-10-29 05:30:57 +00:00
if ( $dh = opendir ( $langdir . $actual_compdir )) {
while (( $file = readdir ( $dh )) !== false ) {
if ( $file == " .. " or $file == " . " or ( substr ( $file , 0 , strlen ( $randomness )) != $randomness )) continue ;
if ( substr ( $file , - 4 ) == " .inc " ) {
//only files ending in .inc
rename ( $langdir . $actual_compdir . $file , $langdir . $actual_compdir . substr ( $file , strlen ( $randomness )));
2005-09-07 15:54:35 +00:00
}
2005-10-29 05:30:57 +00:00
}
2005-09-07 15:54:35 +00:00
} else {
2005-10-29 05:30:57 +00:00
echo " no compile dir?! " ;
2005-09-07 15:54:35 +00:00
}
2005-01-31 20:32:49 +00:00
}
2005-09-07 15:54:35 +00:00
2005-01-31 20:32:49 +00:00
/***************************
* Have some of the files changed ?
**************************/
2005-02-17 12:26:04 +00:00
function languagesNeedsRebuild ( $langdir , $transdir , $prjtransdir , $compdir ){
2005-04-02 15:49:30 +00:00
2005-04-02 18:37:22 +00:00
if ( ! file_exists ( $langdir . $compdir )){
//This directory does not exist - try to create one
2007-05-01 21:21:13 +00:00
mkdir ( $langdir . $compdir , 0773 );
2005-04-02 18:37:22 +00:00
return true ;
//and force an update since we need it
2005-04-02 15:49:30 +00:00
}
2006-11-10 17:55:22 +00:00
// Uncomment the following to speed up things when you know
// that you will manually recompile the languages when updated...
//
// return false;
2005-02-08 12:18:02 +00:00
2006-05-09 18:25:15 +00:00
$last_compile = 0 ;
if ( file_exists ( $langdir . " last_compile_timer " )) {
$last_compile = filemtime ( $langdir . " last_compile_timer " );
}
2005-04-02 18:37:22 +00:00
//This file gets touched each time a compile finishes
2005-02-17 12:26:04 +00:00
2005-01-31 20:32:49 +00:00
if ( is_dir ( $langdir . $transdir )) {
2005-04-02 18:37:22 +00:00
if ( $dh = opendir ( $langdir . $transdir )) {
while (( $file = readdir ( $dh )) !== false ) {
2005-10-29 05:30:57 +00:00
if ( $file == " .. " or $file == " . " ) continue ;
if ( substr ( $file , - 3 ) == " .po " ){
2005-04-02 18:37:22 +00:00
//only files ending in .po
2006-08-09 19:12:54 +00:00
if ( filemtime ( $langdir . $transdir . $file ) > $last_compile ) {
closedir ( $dh );
return true ;
}
2005-04-02 18:37:22 +00:00
}
2005-01-31 20:32:49 +00:00
}
closedir ( $dh );
}
}
2005-02-17 12:26:04 +00:00
if ( is_dir ( $langdir . $prjtransdir )) {
2005-04-02 18:37:22 +00:00
if ( $dh = opendir ( $langdir . $prjtransdir )) {
while (( $file = readdir ( $dh )) !== false ) {
2005-10-29 05:30:57 +00:00
if ( $file == " .. " or $file == " . " ) continue ;
if ( substr ( $file , - 3 ) == " .po " ){
2005-04-02 18:37:22 +00:00
//only files ending in .po
2006-11-10 17:55:22 +00:00
if ( filemtime ( $langdir . $prjtransdir . $file ) > $last_compile ) {
closedir ( $dh );
return true ;
}
2005-04-02 18:37:22 +00:00
}
2005-02-17 12:26:04 +00:00
}
closedir ( $dh );
}
}
2005-04-02 18:37:22 +00:00
return false ;
//All checks say that nothing has changed.
2005-01-31 20:32:49 +00:00
}
/**************************
* Parses a gettext . po - file into an indexed PHP array ,
* checking for inconsistencies if needed .
* The $file is parsed and validated against $interface
*************************/
function parseLanguage ( $file , $interface ){
2005-04-02 18:37:22 +00:00
if ( sizeof ( $interface ) < 1 ){
language_log ( " No interface defined for 'compileLanguages()' " , 2 );
exit ;
}
2005-01-31 20:32:49 +00:00
$translation_file = file ( $file );
$first_entry = true ;
2007-04-23 16:14:47 +00:00
$current_token_text = " " ;
2005-01-31 20:32:49 +00:00
for ( $i = 0 ; $i < sizeof ( $translation_file ); $i ++ ){
2005-04-02 18:37:22 +00:00
$entry = ltrim ( trim ( $translation_file [ $i ]));
//echo $entry;
if (( $pos = strpos ( $entry , " msgid " )) !== false ){
//If found msgid entry
if ( ! $first_entry ){
//If this is not the first, save the previous entry
//Does token msgid entry exist in interface?
//If so, add to output
2007-04-23 16:14:47 +00:00
$id = checkToken ( $current_token , $interface , $i , $file );
2005-04-02 18:37:22 +00:00
if ( $id !== false ){
$output [ $id ] = $current_token_text ;
}
}
$current_token = getPOLineContent ( $entry );
$current_token_text = " " ;
$first_entry = false ;
2006-11-10 17:55:22 +00:00
// Now it is no longer the first entry
2005-04-02 18:37:22 +00:00
} elseif ( substr ( $translation_file [ $i ], 0 , 1 ) != " # " ) {
//echo "Else";
$current_token_text .= getPOLineContent ( $entry );
}
2005-01-31 20:32:49 +00:00
}
2007-04-23 16:14:47 +00:00
$id = checkToken ( $current_token , $interface , $i , $file );
2005-01-31 20:32:49 +00:00
if ( $id !== false ){
$output [ $id ] = $current_token_text ;
}
checkMissingTokens ( $output , $interface );
return $output ;
}
/*********************
* Checks if token is in interface .
* Displays error if not
**********************/
2007-04-23 16:14:47 +00:00
function checkToken ( $current_token , $interface , $line , $file ){
2005-01-31 20:32:49 +00:00
$id = array_search ( $current_token , $interface );
2005-10-16 10:11:19 +00:00
if ( $id === false ){
2005-02-24 18:48:12 +00:00
language_log ( " Above line " . $line . " : Language file $file has a token ( " . $current_token . " ) that is not defined in the interface. " , 1 );
2005-04-02 18:37:22 +00:00
return false ;
2005-01-31 20:32:49 +00:00
} else {
2005-04-02 18:37:22 +00:00
return $id ;
2005-01-31 20:32:49 +00:00
}
}
/*****************
* This function prints any missing tokens as errors
*****************/
function checkMissingTokens ( $language_array , $interface ){
$diff = array_values ( array_diff ( array_keys ( $interface ), array_keys ( $language_array )));
for ( $i = 0 ; $i < sizeof ( $diff ); $i ++ ){
2005-04-02 18:37:22 +00:00
language_log ( " Language file is missing token ( " . $interface [ $diff [ $i ]] . " ) " , 1 );
2005-01-31 20:32:49 +00:00
}
}
/***********************
* Returns the contents of a line ( ie removes " " from start and end )
*********************/
function getPOLineContent ( $line ){
$start = strpos ( $line , '"' ) + 1 ;
$stop = strrpos ( $line , '"' );
return substr ( $line , $start , $stop - $start );
}
/************************
* Translate token
* Use the token name as a constant - like echo tr ( MENU_ABOUT );
************************/
function tr ( $tokennumber ){
2005-04-02 15:49:30 +00:00
global $language_lookup_array ;
2005-01-31 20:32:49 +00:00
if ( strval ( intval ( $tokennumber )) != $tokennumber ){
2005-04-02 18:37:22 +00:00
language_log ( " token $tokennumber missing from language interface. " );
2006-07-22 18:24:01 +00:00
//print_r($language_lookup_array);
2005-01-31 20:32:49 +00:00
}
2005-02-08 12:18:02 +00:00
2005-04-02 18:37:22 +00:00
if ( array_key_exists ( $tokennumber , $language_lookup_array )){
//If language has got the token
//If found in client language, return that
return stripslashes ( $language_lookup_array [ $tokennumber ]);
2005-02-08 12:18:02 +00:00
}
2006-07-22 18:24:01 +00:00
return " [translation missing for $tokennumber ] " ;
2005-01-31 20:32:49 +00:00
}
2007-08-25 13:28:01 +00:00
/************************
* Translate string
************************/
2007-08-25 14:45:15 +00:00
function tra ( $string , $s1 = null , $s2 = null , $s3 = null , $s4 = null , $s5 = null ){
2007-08-25 13:28:01 +00:00
global $language_lookup_array ;
global $translation_strings ;
2007-10-26 21:14:35 +00:00
$key = $translation_strings [ $string ];
if ( array_key_exists ( $key , $language_lookup_array )) {
$string = $language_lookup_array [ $key ];
2007-08-25 13:28:01 +00:00
}
2007-08-25 14:45:15 +00:00
$string = str_replace ( '%1' , $s1 , $string );
$string = str_replace ( '%2' , $s2 , $string );
$string = str_replace ( '%3' , $s3 , $string );
$string = str_replace ( '%4' , $s4 , $string );
$string = str_replace ( '%5' , $s5 , $string );
return $string ;
2007-08-25 13:28:01 +00:00
}
2005-02-24 18:48:12 +00:00
function language_log ( $message , $loglevel = 0 ){
global $lang_log_level , $lang_log_file ;
if ( $loglevel == 0 ) $msg = " [ Debug ] " ;
if ( $loglevel == 1 ) $msg = " [ Warning ] " ;
if ( $loglevel == 2 ) $msg = " [ CRITICAL ] " ;
if ( $loglevel >= $lang_log_level ){
2005-04-02 18:37:22 +00:00
$fh = fopen ( $lang_log_file , " a " );
fwrite ( $fh , date ( " Y-m-d H:i:s " , time ()) . " " . $msg . " " . $message . " \n " );
fclose ( $fh );
2005-02-24 18:48:12 +00:00
}
}
2008-03-14 21:40:18 +00:00
$compile_languages = false ;
if ( isset ( $_GET [ 'compile_languages' ])) $compile_languages = true ;
if ( languagesNeedsRebuild ( $lang_language_dir , $lang_translations_dir , $lang_prj_translations_dir , $lang_compiled_dir ) || $compile_languages ){
2005-02-17 12:26:04 +00:00
buildLanguages ( $lang_language_dir , $lang_translations_dir , $lang_prj_translations_dir , $lang_compiled_dir );
2005-01-31 20:32:49 +00:00
}
2006-08-21 01:44:03 +00:00
// Define some variables (from constants) that the language files
// can use in the translation:
2005-01-31 20:32:49 +00:00
$PROJECT = PROJECT ;
2006-08-21 01:44:03 +00:00
if ( ! file_exists ( $lang_language_dir . $lang_compiled_dir . " language_interface.inc " )){
language_log ( " Could not load language interface. " , 2 );
echo " ERROR: Could not load language interface.
This is a fatal error , exiting .
" ;
flush ;
exit ;
}
require_once ( $lang_language_dir . $lang_compiled_dir . " language_interface.inc " );
// Make a list of languages which the user prefers
// (by looking at cookies and browser settings)
// cookies have highest priority.
2005-04-02 15:49:30 +00:00
2006-08-21 01:44:03 +00:00
if ( isset ( $_COOKIE [ 'lang' ])){
$language_string = $_COOKIE [ 'lang' ] . " , " ;
} else {
$language_string = '' ;
}
2007-04-27 16:27:12 +00:00
if ( isset ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ])) {
$language_string .= strtolower ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ]);
2006-08-21 01:44:03 +00:00
}
2005-04-02 15:49:30 +00:00
2006-09-26 17:02:46 +00:00
// Find out which language to use by iterating through list
// The list is comma-separated, so split it into an array of the following type:
2006-08-21 01:44:03 +00:00
// Array (
// [0] => da
// [1] => en-us;q=0.7
// [2] => en;q=0.3
// )
$client_languages = explode ( " , " , $language_string );
2006-09-26 17:02:46 +00:00
// A language is either defined as primary-secondary or primary.
2006-08-21 01:44:03 +00:00
// It can also have a quality attribute set,
// which orders the languages in a user preferred ordering.
// Since this is usally the same order as the array indices
// we just ignore this attribute (TODO: don't ignore this attribute)
// A missing quality attribute means q=1
// Always include the project default as fallback
//
require_once (
$lang_language_dir . $lang_compiled_dir . $lang_project_default . " .po.inc "
);
$language_in_use = $lang_project_default ;
// loop over languages that the client requests
//
for ( $i = sizeof ( $client_languages ) - 1 ; $i >= 0 ; $i -- ) {
if (( strlen ( $client_languages [ $i ]) > 2 )
&& ( substr ( $client_languages [ $i ], 2 , 1 ) == " _ " || substr ( $client_languages [ $i ], 2 , 1 ) == " - " ))
{
// If this is defined as primary-secondary, represent it as xx_YY
//
$language = substr (
$client_languages [ $i ], 0 , 2 ) . " _ " . strtoupper ( substr ( $client_languages [ $i ], 3 , 2 )
);
2006-09-26 17:02:46 +00:00
// And also check for the primary language
//
$language2 = substr ( $client_languages [ $i ], 0 , 2 );
2005-10-01 17:10:31 +00:00
} else {
2006-08-21 01:44:03 +00:00
// else just use xx
//
$language = substr ( $client_languages [ $i ], 0 , 2 );
2006-09-26 17:02:46 +00:00
$language2 = null ;
2005-10-01 17:50:15 +00:00
}
2006-09-26 17:02:46 +00:00
2006-08-21 01:44:03 +00:00
// If we have a translation for the language, include it
//
2006-09-26 17:02:46 +00:00
$file_name = $lang_language_dir . $lang_compiled_dir . $language . " .po.inc " ;
if ( file_exists ( $file_name )) {
require ( $file_name );
2006-08-21 01:44:03 +00:00
$language_in_use = $language ;
2005-04-02 15:49:30 +00:00
2005-01-31 20:32:49 +00:00
}
2006-09-26 17:02:46 +00:00
if ( $language2 ) {
$file_name = $lang_language_dir . $lang_compiled_dir . $language2 . " .po.inc " ;
if ( file_exists ( $file_name )) {
require ( $file_name );
$language_in_use = $language2 ;
}
}
2005-10-29 05:30:57 +00:00
}
2005-01-31 20:32:49 +00:00
2006-08-21 01:44:03 +00:00
// If you include this file, $language_in_use is now set
// to the language actually being used
2005-03-03 19:36:32 +00:00
?>