[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to apply multiple languages to site so that we can view site in the language which we wish

Posted on 2008-10-09
5
Medium Priority
?
224 Views
Last Modified: 2013-11-05
I came to know there is possibility of selecting particular language to view the whole site in that selected language but i want basic idea of doing this.
0
Comment
Question by:nagaphanir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 22685558
There are lots of ways to do this. The main choice is between:

a) holding translations for entire page templates in each language
b) using a single template that builds pages using libraries of language strings

a) is easier to start with, and means you can get away with not translating some stuff (meaning some things may not be available in some languages, but it won't break your layouts), but b) is mor flexible and expandable as you add more languages.

Most obvious code to help with it is gettext features in PHP, plus the PEAR Translation2 class: http://pear.php.net/package/Translation2
0
 
LVL 9

Accepted Solution

by:
lucki_luke earned 252 total points
ID: 22685567
Hi,

for this to work you could make language files for each language and define phrases that will be used on the page and set up your database to contain the content in different languages.
Then according to a get statement for example in the url you can tell the script which files to load and which content cell to retrieve.
Please have a look at big opensource projects that support multiple languages like PHPBB to get a better idea.
0
 
LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 248 total points
ID: 22685658
The normal way of selecting a language is to look at the accept_language head that every browser supplies. I use these functions to select the best language I have:


/**
* Parse an HTTP_ACCEPT_LANGUAGE header string into a simple list of languages with locale info removed
* @return array
*/
function browserLanguages() {
	$langcodes = array();
	if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
		$languages = explode(',' , $_SERVER['HTTP_ACCEPT_LANGUAGE']);
		foreach($languages as $language) {
			$langparts = explode(';', $language);
			$langcodeparts = explode('-', $langparts[0]); //Convert en-us to en etc
			$langcode = trim($langcodeparts[0]);
			if (!in_array($langcode, $langcodes)) { //Not already listed
				$langcodes[] = $langcode;
			}
		}
	}
	return $langcodes;
}
 
/**
* Pick the best available language to deliver to a browser
* @param array $browserlanguages List of languages supported by the browser - see {@link browserLanguages()}
* @param array $availablelanguages List of the languages that you support, default one first
* @return string
*/
function bestLanguage($browserlanguages, $availablelanguages) {
	foreach($browserlanguages as $browserlanguage) {
		if (in_array($browserlanguage, $availablelanguages)) {
			return $browserlanguage;
		}
	}
	//Nothing found matching browser pref, so find default
	if (count($availablelanguages) > 0) {
		return $availablelanguages[0];
	} else {
		return 'en'; //Not a lot else we can do here
	}
}

Open in new window

0
 

Author Comment

by:nagaphanir
ID: 22801805
many thanks for your inputs....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question