1
Dylian
Possible new way of loading language files
  • 2009/8/18 1:30

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


When i was working on my website today i came across a few undefined language variables. Then i started thinking how i could ensure that a lanuage variable is always defined. Thats when i got a very simple solution, i first thought it wasn't going to work but it did (At least on my system).

So this is wat i've done. I replaced the normal if rule:
if ( file_exists"language/" $xoopsConfig['language'] . "/main.php" ) ) {
    include 
"language/" $xoopsConfig['language'] . "/main.php";
}elseif ( 
file_exists"language/english/main.php" ) ) {
    include 
"language/english/main.php";
}


with:
if ( file_exists"language/english/main.php" ) ) {
    include 
"language/english/main.php";
}
if ( 
file_exists"language/" $xoopsConfig['language'] . "/main.php" ) ) {
    include 
"language/" $xoopsConfig['language'] . "/main.php";
}


This way if a variable isn't defined in a local file, you will get the english text.

Maybe it's crazy, maybe it's not but for me this works.

Maybe if it works on every system, module and core developers could load language file's this way in the future.

Please respond, Dylian.

P.S. Sorry for my bad english.

2
iHackCode
Re: Possible new way of loading language files

isnt there the issue of redeclaration of constants?

3
ghia
Re: Possible new way of loading language files
  • 2009/8/18 7:59

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Yes, in stead of a few undefined errors, you get now a lot of double defines.
This is sure not the way to go!!

If constants are missing, you have to add them in your local language files!!

4
Dylian
Re: Possible new way of loading language files
  • 2009/8/18 9:40

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


Ok, it was just a idea . But i still think we need a way to ensure that all lnaguage variables are defined. I don't think users of a website will like to see a string like _MD_MODULE_VARIABLE. Maybe if we can do it like this.

Add this as a core function:
function define_lang($name$value$case_insensitive false) {
   if (
defined($name)) {
      
define($name$value$case_insensitive);
   }
}


Use this in the page where you want to use the language defines:
if ( file_exists"language/" $xoopsConfig['language'] . "/main.php" ) ) { 
    include 
"language/" $xoopsConfig['language'] . "/main.php"
}
if ( 
file_exists"language/english/main.php" ) ) { 
    include 
"language/english/main.php"
}


The local language files use define($name, $value, $case_insensitive); and in the english files use the define_lang($name, $value, $case_insensitive);.

Is this a better idea?

Greets Dylian.


5
ghia
Re: Possible new way of loading language files
  • 2009/8/18 10:31

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


It is a better idea, but still not a good one.
The main problem stays: the user will not see his text in his native language. And for example: an english text or _MD_MODULE_VARIABLE look both terrible in the middle of Arabic.
I prefer the first one. In that case, at least I know at what to look for, for correcting the problem.

With eg the language tool module or xtransam, you can easy correct definitions.

BTW it has to be: if (!defined(

6
Dylian
Re: Possible new way of loading language files
  • 2009/8/18 10:47

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


If you do it like this you can see if a constant is undefined in the XOOPS debug.

function define_lang($name$value$case_insensitive false) { 
   if (!
defined($name)) { 
      
define($name$value$case_insensitive); 
   } 
   
$GLOBALS['xoopsLogger']->addExtra("XOOPS language => Undefined constant"$name);
}

7
trabis
Re: Possible new way of loading language files
  • 2009/8/18 10:52

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1



8
iHackCode
Re: Possible new way of loading language files

what about the module itself has a list of language variable names that it needs and it will read the language file it is to read and loads the variables it needs. like JP and then fill the missing with EN. but the loading will be slow. to make it more efficient it should create a cached language file (an array?) of the language variables, and load that?

or..

we have the JP Language Array and EN Language Array. Load EN and then JP and the holes will be filled?


Login

Who's Online

273 user(s) are online (148 user(s) are browsing Support Forums)


Members: 0


Guests: 273


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits