/    Sign up×
Community /Pin to ProfileBookmark

(Easy) help needed: php language select

Hi there,
at the moment I don’t know any php. I found a script over here: [url]http://svn.gna.org/viewcvs/clansuite/website-clansuite.com/index.php?rev=1749&view=markup[/url]

which gives me a $lang = de, or en, depending on the users browsers.
everything’s fine. it works perfectly for my needs, now i just wanted to ask – since i don’t really know php. what happens if the user has a browser with a language not being “de” or “en”?
Is there already some case in this script (making the default language “en” for example)? Or will it just give a blank field?

Thanks so much in advance for any help!!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@ht1815Jul 20.2010 — It depends on how you set up the usage of the functions. The example on that page shows this usage:

if ($lang == 'de')

{

include 'index.de.php';
}

else

{

include 'index.en.php';

}

That basically means, if it's anything other than 'de', it will display the 'en' version of the page. Does this if statement represent your usage of the code?
Copy linkTweet thisAlerts:
@GrimwoodauthorJul 20.2010 — Oh ya, sorry, forgot to mention that.

I removed that line, since it seams it already gives me the language back "internally" - meaning I use [CODE]<? echo $lang; ?>[/CODE] on different places on my page, and that does work (so if I go on the site with my english browser, it includes "en" and with my german browser "de")...

So yeah, I don't know if there is already some default set or if I have to do that manually since I don't use the code you mentioned...

Thank you!!
Copy linkTweet thisAlerts:
@ht1815Jul 20.2010 — That doesn't tell us much. Well, the simple answer is, if you encounter a browser of a language other than 'en' or 'de', you're going to echo out that other language code. How that will actually affect your site isn't clear, because it isn't clear what's being done with that echo statement.
Copy linkTweet thisAlerts:
@GrimwoodauthorJul 20.2010 — Thanks, ok, so basically the question would be how to make the language "en" by default, meaning when a browser has another language than en or de, it still will echo "en"...

What exactly do you mean by it isn't clear what's being done? I just have that code in different places, for example when an image is loaded (so it says [CODE]/img/<? echo $lang; ?>/picture.png[/CODE], so it loads an english/german image depending on what browser language the user has...

Thank you again!
Copy linkTweet thisAlerts:
@ht1815Jul 20.2010 — Ahh, okay, so you're using it to condition paths to files. That's what I meant.

What I would do then, is basically what they did on the page from which you got the code. So, something like this:

[CODE]
if ($lang == 'de')
{

$langdir = 'de';
}
else
{
$langdir = 'en';
}[/CODE]


Then, use $langdir in your echo statements, rather than $lang. That way, you'll always be using either 'de' or 'en'.
Copy linkTweet thisAlerts:
@GrimwoodauthorJul 20.2010 — ok, thank you!

but would be there a way to do that (i understand what you mean) and still have the same $lang and not have to change that, because well.. I already have a lot of $lang echos.. ? If not, ok, I'll change it, but perhaps there is a way?

Thanks so much!
Copy linkTweet thisAlerts:
@ht1815Jul 20.2010 — In that case, I'd probably do something like this:

[CODE]
$sesslang = $_SESSION['lang'];

if($sessang == 'de'){
$lang = 'de';
} else {
$lang = 'en';
}
[/CODE]


I'd use a different variable to hold the session language value, then test it and set $lang accordingly. That way you won't have to change all your embedded echo statements.
Copy linkTweet thisAlerts:
@GrimwoodauthorJul 20.2010 — Awesome, thank you very much!
×

Success!

Help @Grimwood spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...