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
|
||||
* \brief Class to manage translations
|
||||
*/
|
||||
class Translate {
|
||||
|
||||
class Translate
|
||||
{
|
||||
var $dir; // Directories that contains /langs subdirectory
|
||||
|
||||
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 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 ($dir) $this->dir=array($dir);
|
||||
@ -64,12 +64,13 @@ class Translate {
|
||||
* Set accessor for this->defaultlang
|
||||
*
|
||||
* @param string $srclang Language to use
|
||||
* @return void
|
||||
*/
|
||||
function setDefaultLang($srclang='fr_FR')
|
||||
{
|
||||
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 (! empty($conf->global->MAIN_FORCELANGDIR))
|
||||
@ -78,13 +79,13 @@ class Translate {
|
||||
$i=0;
|
||||
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))
|
||||
{
|
||||
$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;
|
||||
@ -162,7 +163,7 @@ class Translate {
|
||||
// Check parameters
|
||||
if (empty($domain))
|
||||
{
|
||||
dol_print_error('',"Translate::Load ErrorWrongParameters");
|
||||
dol_print_error('',get_class($this)."::Load ErrorWrongParameters");
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ class Translate {
|
||||
$tab=explode('=',$line,2);
|
||||
$key=trim($tab[0]);
|
||||
//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]));
|
||||
|
||||
@ -476,9 +477,9 @@ class Translate {
|
||||
/**
|
||||
* Return translation of a key depending on country
|
||||
*
|
||||
* @param str string root to translate
|
||||
* @param countrycode country code (FR, ...)
|
||||
* @return string translated string
|
||||
* @param string $str string root to translate
|
||||
* @param string $countrycode country code (FR, ...)
|
||||
* @return string translated string
|
||||
*/
|
||||
function transcountry($str, $countrycode)
|
||||
{
|
||||
@ -490,9 +491,9 @@ class Translate {
|
||||
/**
|
||||
* Retourne la version traduite du texte passe en parametre complete du code pays
|
||||
*
|
||||
* @param str string root to translate
|
||||
* @param countrycode country code (FR, ...)
|
||||
* @return string translated string
|
||||
* @param string $str string root to translate
|
||||
* @param string $countrycode country code (FR, ...)
|
||||
* @return string translated string
|
||||
*/
|
||||
function transcountrynoentities($str, $countrycode)
|
||||
{
|
||||
@ -504,9 +505,9 @@ class Translate {
|
||||
/**
|
||||
* 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 pagecodefrom Page code of src string
|
||||
* @return string Converted string
|
||||
* @param string $str String to convert
|
||||
* @param string $pagecodefrom Page code of src string
|
||||
* @return string Converted string
|
||||
*/
|
||||
function convToOutputCharset($str,$pagecodefrom='UTF-8')
|
||||
{
|
||||
@ -519,10 +520,10 @@ class Translate {
|
||||
/**
|
||||
* Return list of all available languages
|
||||
*
|
||||
* @param langdir Directory to scan
|
||||
* @param maxlength Max length for each value in combo box (will be truncated)
|
||||
* @param usecode Show code instead of country name for language variant
|
||||
* @return array List of languages
|
||||
* @param string $langdir Directory to scan
|
||||
* @param string $maxlength Max length for each value in combo box (will be truncated)
|
||||
* @param int $usecode Show code instead of country name for language variant
|
||||
* @return array List of languages
|
||||
*/
|
||||
function get_available_languages($langdir=DOL_DOCUMENT_ROOT,$maxlength=0,$usecode=0)
|
||||
{
|
||||
@ -554,9 +555,9 @@ class Translate {
|
||||
/**
|
||||
* Return if a filename $filename exists for current language (or alternate language)
|
||||
*
|
||||
* @param filename Language filename to search
|
||||
* @param searchalt Search also alernate language file
|
||||
* @return boolean true if exists and readable
|
||||
* @param string $filename Language filename to search
|
||||
* @param string $searchalt Search also alernate language file
|
||||
* @return boolean true if exists and readable
|
||||
*/
|
||||
function file_exists($filename,$searchalt=0)
|
||||
{
|
||||
@ -583,11 +584,11 @@ class Translate {
|
||||
* 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).
|
||||
*
|
||||
* @param number Number to encode in full text
|
||||
* @param isamount 1=It's an amount, 0=it's just a number
|
||||
* @return string Label translated in UTF8 (but without entities)
|
||||
* 10 if setDefaultLang was en_US => ten
|
||||
* 123 if setDefaultLang was fr_FR => cent vingt trois
|
||||
* @param int $number Number to encode in full text
|
||||
* @param int $isamount 1=It's an amount, 0=it's just a number
|
||||
* @return string Label translated in UTF8 (but without entities)
|
||||
* 10 if setDefaultLang was en_US => ten
|
||||
* 123 if setDefaultLang was fr_FR => cent vingt trois
|
||||
*/
|
||||
function getLabelFromNumber($number,$isamount=0)
|
||||
{
|
||||
@ -621,12 +622,12 @@ class Translate {
|
||||
* 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.
|
||||
*
|
||||
* @param db Database handler
|
||||
* @param key Key to get label (key in language file)
|
||||
* @param tablename Table name without prefix
|
||||
* @param fieldkey Field for key
|
||||
* @param fieldlabel Field for label
|
||||
* @return string Label in UTF8 (but without entities)
|
||||
* @param DoliBD $db Database handler
|
||||
* @param string $key Key to get label (key in language file)
|
||||
* @param string $tablename Table name without prefix
|
||||
* @param string $fieldkey Field for key
|
||||
* @param string $fieldlabel Field for label
|
||||
* @return string Label in UTF8 (but without entities)
|
||||
*/
|
||||
function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user