Jump to content

function to load different language files


Recommended Posts

I have a function to read terms from an array stored in language file as

function _language($term) {
if(!empty($lang[$term])) {
} else { $lterm = $term;}
return $lterm;


The problem is that I get the language code from url as ?lang=en or ?lang=fr; but I cannot bring this string into the function. How I can tell the function to read appropriate language file (fr.php or en.php or es.php) upon choosing language in ?lang=XX

Link to comment
Share on other sites

Thanks but you did not get my problem. I get language by $_GET; but how to load corresponding language file.

$language = $_GET['lang'];

Now I need something like this within the function



My problem is how to run the function for each language (e.g. 50 languages).

Link to comment
Share on other sites

Assuming that you want all references to the language file to occur through that function, you should probably use a class, but you could (probably, this is untested) do this using a function and a static variable to prevent the code from including the language file every time the function is called.


On the first call to the function, you would detect that the static variable holding the $lang array has not been initialized and then validate the $_GET (the $_GET array is a super global and is automatically available inside of functions) variable and include the correct language file, assigning the $lang array to the function's statically defined variable.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.