Fix: If data was already found into file into MAIN_FORCELANGDIR, we must
not overwrite it with value of standard lang files.
This commit is contained in:
parent
e528ac97a8
commit
2641ec21af
@ -30,8 +30,8 @@
|
|||||||
* \class Translate
|
* \class Translate
|
||||||
* \brief Class to manage translations
|
* \brief Class to manage translations
|
||||||
*/
|
*/
|
||||||
class Translate {
|
class Translate
|
||||||
|
{
|
||||||
var $dir; // Directories that contains /langs subdirectory
|
var $dir; // Directories that contains /langs subdirectory
|
||||||
|
|
||||||
var $defaultlang; // Current language for current user
|
var $defaultlang; // Current language for current user
|
||||||
@ -52,7 +52,7 @@ class Translate {
|
|||||||
* @param string $dir Force directory that contains /langs subdirectory (value is sometine '..' like into install/* pages or support/* pages).
|
* @param string $dir Force directory that contains /langs subdirectory (value is sometine '..' like into install/* pages or support/* pages).
|
||||||
* @param Conf $conf Object with Dolibarr configuration
|
* @param Conf $conf Object with Dolibarr configuration
|
||||||
*/
|
*/
|
||||||
function Translate($dir = "",$conf)
|
function Translate($dir,$conf)
|
||||||
{
|
{
|
||||||
if (! empty($conf->file->character_set_client)) $this->charset_output=$conf->file->character_set_client; // If charset output is forced
|
if (! empty($conf->file->character_set_client)) $this->charset_output=$conf->file->character_set_client; // If charset output is forced
|
||||||
if ($dir) $this->dir=array($dir);
|
if ($dir) $this->dir=array($dir);
|
||||||
@ -64,12 +64,13 @@ class Translate {
|
|||||||
* Set accessor for this->defaultlang
|
* Set accessor for this->defaultlang
|
||||||
*
|
*
|
||||||
* @param string $srclang Language to use
|
* @param string $srclang Language to use
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setDefaultLang($srclang='fr_FR')
|
function setDefaultLang($srclang='fr_FR')
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
//dol_syslog("Translate::setDefaultLang srclang=".$srclang,LOG_DEBUG);
|
//dol_syslog(get_class($this)."::setDefaultLang srclang=".$srclang,LOG_DEBUG);
|
||||||
|
|
||||||
// If a module ask to force a priority on langs directories (to use its own lang files)
|
// If a module ask to force a priority on langs directories (to use its own lang files)
|
||||||
if (! empty($conf->global->MAIN_FORCELANGDIR))
|
if (! empty($conf->global->MAIN_FORCELANGDIR))
|
||||||
@ -78,13 +79,13 @@ class Translate {
|
|||||||
$i=0;
|
$i=0;
|
||||||
foreach($conf->file->dol_document_root as $dir)
|
foreach($conf->file->dol_document_root as $dir)
|
||||||
{
|
{
|
||||||
$newdir=$dir.$conf->global->MAIN_FORCELANGDIR;
|
$newdir=$dir.$conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX'
|
||||||
if (! in_array($newdir,$this->dir))
|
if (! in_array($newdir,$this->dir))
|
||||||
{
|
{
|
||||||
$more['module_'.$i]=$newdir; $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir.
|
$more['module_'.$i]=$newdir; $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->dir=array_merge($more,$this->dir);
|
$this->dir=array_merge($more,$this->dir); // Forced dir ($more) are before standard dirs ($this->dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->origlang=$srclang;
|
$this->origlang=$srclang;
|
||||||
@ -162,7 +163,7 @@ class Translate {
|
|||||||
// Check parameters
|
// Check parameters
|
||||||
if (empty($domain))
|
if (empty($domain))
|
||||||
{
|
{
|
||||||
dol_print_error('',"Translate::Load ErrorWrongParameters");
|
dol_print_error('',get_class($this)."::Load ErrorWrongParameters");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +250,7 @@ class Translate {
|
|||||||
$tab=explode('=',$line,2);
|
$tab=explode('=',$line,2);
|
||||||
$key=trim($tab[0]);
|
$key=trim($tab[0]);
|
||||||
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
|
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
|
||||||
if ((! empty($conf->global->MAIN_FORCELANGDIR) || empty($this->tab_translate[$key])) && isset($tab[1]))
|
if (empty($this->tab_translate[$key]) && isset($tab[1])) // If data was already found, we must not enter here, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite)
|
||||||
{
|
{
|
||||||
$value=trim(preg_replace('/\\n/',"\n",$tab[1]));
|
$value=trim(preg_replace('/\\n/',"\n",$tab[1]));
|
||||||
|
|
||||||
@ -476,8 +477,8 @@ class Translate {
|
|||||||
/**
|
/**
|
||||||
* Return translation of a key depending on country
|
* Return translation of a key depending on country
|
||||||
*
|
*
|
||||||
* @param str string root to translate
|
* @param string $str string root to translate
|
||||||
* @param countrycode country code (FR, ...)
|
* @param string $countrycode country code (FR, ...)
|
||||||
* @return string translated string
|
* @return string translated string
|
||||||
*/
|
*/
|
||||||
function transcountry($str, $countrycode)
|
function transcountry($str, $countrycode)
|
||||||
@ -490,8 +491,8 @@ class Translate {
|
|||||||
/**
|
/**
|
||||||
* Retourne la version traduite du texte passe en parametre complete du code pays
|
* Retourne la version traduite du texte passe en parametre complete du code pays
|
||||||
*
|
*
|
||||||
* @param str string root to translate
|
* @param string $str string root to translate
|
||||||
* @param countrycode country code (FR, ...)
|
* @param string $countrycode country code (FR, ...)
|
||||||
* @return string translated string
|
* @return string translated string
|
||||||
*/
|
*/
|
||||||
function transcountrynoentities($str, $countrycode)
|
function transcountrynoentities($str, $countrycode)
|
||||||
@ -504,8 +505,8 @@ class Translate {
|
|||||||
/**
|
/**
|
||||||
* Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client)
|
* Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client)
|
||||||
*
|
*
|
||||||
* @param str String to convert
|
* @param string $str String to convert
|
||||||
* @param pagecodefrom Page code of src string
|
* @param string $pagecodefrom Page code of src string
|
||||||
* @return string Converted string
|
* @return string Converted string
|
||||||
*/
|
*/
|
||||||
function convToOutputCharset($str,$pagecodefrom='UTF-8')
|
function convToOutputCharset($str,$pagecodefrom='UTF-8')
|
||||||
@ -519,9 +520,9 @@ class Translate {
|
|||||||
/**
|
/**
|
||||||
* Return list of all available languages
|
* Return list of all available languages
|
||||||
*
|
*
|
||||||
* @param langdir Directory to scan
|
* @param string $langdir Directory to scan
|
||||||
* @param maxlength Max length for each value in combo box (will be truncated)
|
* @param string $maxlength Max length for each value in combo box (will be truncated)
|
||||||
* @param usecode Show code instead of country name for language variant
|
* @param int $usecode Show code instead of country name for language variant
|
||||||
* @return array List of languages
|
* @return array List of languages
|
||||||
*/
|
*/
|
||||||
function get_available_languages($langdir=DOL_DOCUMENT_ROOT,$maxlength=0,$usecode=0)
|
function get_available_languages($langdir=DOL_DOCUMENT_ROOT,$maxlength=0,$usecode=0)
|
||||||
@ -554,8 +555,8 @@ class Translate {
|
|||||||
/**
|
/**
|
||||||
* Return if a filename $filename exists for current language (or alternate language)
|
* Return if a filename $filename exists for current language (or alternate language)
|
||||||
*
|
*
|
||||||
* @param filename Language filename to search
|
* @param string $filename Language filename to search
|
||||||
* @param searchalt Search also alernate language file
|
* @param string $searchalt Search also alernate language file
|
||||||
* @return boolean true if exists and readable
|
* @return boolean true if exists and readable
|
||||||
*/
|
*/
|
||||||
function file_exists($filename,$searchalt=0)
|
function file_exists($filename,$searchalt=0)
|
||||||
@ -583,8 +584,8 @@ class Translate {
|
|||||||
* This function need module "numberwords" to be installed. If not it will return
|
* This function need module "numberwords" to be installed. If not it will return
|
||||||
* same number (this module is not provided by default as it use non GPL source code).
|
* same number (this module is not provided by default as it use non GPL source code).
|
||||||
*
|
*
|
||||||
* @param number Number to encode in full text
|
* @param int $number Number to encode in full text
|
||||||
* @param isamount 1=It's an amount, 0=it's just a number
|
* @param int $isamount 1=It's an amount, 0=it's just a number
|
||||||
* @return string Label translated in UTF8 (but without entities)
|
* @return string Label translated in UTF8 (but without entities)
|
||||||
* 10 if setDefaultLang was en_US => ten
|
* 10 if setDefaultLang was en_US => ten
|
||||||
* 123 if setDefaultLang was fr_FR => cent vingt trois
|
* 123 if setDefaultLang was fr_FR => cent vingt trois
|
||||||
@ -621,11 +622,11 @@ class Translate {
|
|||||||
* Return a label for a key. Store key-label into cache variable $this->cache_labels to save SQL requests to get labels.
|
* Return a label for a key. Store key-label into cache variable $this->cache_labels to save SQL requests to get labels.
|
||||||
* This function can be used to get label in database but more often to get code from key id.
|
* This function can be used to get label in database but more often to get code from key id.
|
||||||
*
|
*
|
||||||
* @param db Database handler
|
* @param DoliBD $db Database handler
|
||||||
* @param key Key to get label (key in language file)
|
* @param string $key Key to get label (key in language file)
|
||||||
* @param tablename Table name without prefix
|
* @param string $tablename Table name without prefix
|
||||||
* @param fieldkey Field for key
|
* @param string $fieldkey Field for key
|
||||||
* @param fieldlabel Field for label
|
* @param string $fieldlabel Field for label
|
||||||
* @return string Label in UTF8 (but without entities)
|
* @return string Label in UTF8 (but without entities)
|
||||||
*/
|
*/
|
||||||
function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel)
|
function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user