Jump to content

Recommended Posts

Hello Dear Friends,

 

say we have 2 lang (en,ar) which can be set by following code

 

if($lang == "en") {
include_once "lang/english/co_en.php";
}  else if($lang == "ar") {
include_once "lang/arabic/co_ar.php";
}

 

and

 

if($lang == "en")
   $language="english";
else if($lang == "ar")
   $language="arabic";

 

 

what if we added es,ru so we have 4 (en,ar,es,ru)

 

how then can we rewrite the above code in case of 4 ??

 

thanks in advance

I'd use a switch.

 

switch($lang) {
case 'ar':	
	$language="arabic";
	// run an include or whatever here...
break;
case 'es':
	$langauge = 'spanish';
break;
case 'ru':
	$language = 'russian';
break;
case 'en':
default:
	$langauge = 'english';
break;
}

if all of the files follow that same format, just do something like this:

 

$lang = 'ar';
$languages = array('en','ar','ru','es'); // add languages here
$file = (in_array($lang,$languages))? 'co_'.$lang.'.php' : 'co_'.$languages[0].'.php'; // change array elem to whatever you want as default
include_once $file;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.