What is the best way to use 2 language in a website while data are taken from Database
What I searched for
I have found a Google Translate Plugin but actually I don't like google translate translation plus I have to add google banner.
Problem
I can make the website with two languages but the problem is that it is a dynamic website that users will enter data in English in database and I want to output it in two languages.
if you are doing your project with spring mvc then you can easily do localization.
They are some questions already about this on stackoverflow, but none is really clear about the 'best practice'.
For the content design, what are the options and what is the better option?
Some options I know are using folders: site.com/en/ and site.com/fr/ or redirects site.com/index.php?language=en
An even easier practice is using a new url: en.site.com and fr.site.com
But what if I want to keep site.com/index.php and nothing more ? What are my options for that?
For example, if you change the language on LinkedIn, there's nothing changing in the URL. How do they work there ?
update: in my case the website is a platform, using LAMP stack. Technical advice is also welcome (like how to store/link all the different language files)
You have some options, and each has its own advantages.
If you have a web app, which should not be indexed by search engines, then you are free to do whatever you want. You can keep a language setting in your Session and show strings in the chosen language. This will simplify URLs and management.
However, if you have a standard website which should go into Google, then your options are restricted. If you use the former approach, google will be confused and will index only one language, or, worse, make an ugly mix of the languages. Google does not keep sessions when indexing your page, so if you have two versions of the same page in two different languages, they need to have different URLs. And passing a language as a GET parameter each time is ugly, error prone, and not user friendly.
So you should either have languages as folders (eg. site.com/en/), which is the best options, or use subdomains. This can be a problem, however, because each subdomain is indexed as if it were a separate website, so things like pagerank and site reputation are split among the two.
Here are my recommendations based on multi-languages web sites experience
You can determine the language of the browser in Javascript (see this), which is a good start in having a language that likely fits the user demand
Use utf8 for encoding, everywhere (browser headers, programming, database). The only drawback I know of utf8 is that in some cases, the number of bytes it takes is bigger than another encoding matching more closely a given language (utf8 is opened to any). Big advantage, it covers any language, the ASCII part (bytes < 128) is the same as a western encoding (takes only one byte) ...
Store the user preferences (not in URL).
either in a cookie (+ : user does not have to be logged it on his computer to keep her prefs ; - : when user accesses the page from another computer, the cookie is not present and he/she has to reselect the pref).
or in a session (requires user login to deterime which user is currently using the site)
Regarding the site structure, if you don't store the user preferences, the common /us /fr /jp... solution has advantages: search engines robots will find all languages from root (the page display doesn't depend on user choice). Or you could load only a language dependent Javascript that displays the page immediately (after JS download) in the language of choice, without the need of a page reload / redirect.
You can tell Google what the parameters in the URL mean through Google's Webmaster Tools. So if you use a standard convention like index.php for the main page and a parameter like ?lang=fr for let's say French content in regard to SEO as long as it's a real translation. Likewise when Google.fr crawls the site you would present their users with the French version of the page based on their default setting in their browser. This will increase stickiness on the site and then increase the rank for the selected search terms in French. You can check their default language with this in PHP to make it less heavy on the user's end:
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
?>
Then you would simply concatenate the language selected (as an overlay) to the end of the query string (if it's not the default), bypassing the need for storing a cookie. This should also help from a user experience standpoint. It's not as "pretty" but if people aren't typing it in, it's much more user friendly in that:
People can switch languages by changing the variable
People can provide a link to a user in another country and they can be presented with the page in their native language intuitively when PHP checks their language. "Do you want to see this content in French?"
The native language could in theory be translated on the fly with something like the Google Translate Widget or Google Chrome's built-in functionality.
Content is only served on one URI per page meaning you would not have to rewrite several redirects between versions in the event of stale content. As you're not likely translating into both languages at the same time.
From Wikipedia on Chrome:
As of February 2013, according to StatCounter, Google Chrome has a 37%
worldwide usage share of web browsers making it the most widely used
web browser in the world.
As for storing the files, you can make separate tables in the database for each language, enter in the content in the native language, then duplicate that content to the other language's table. Then you could translate that content live on screen if so desired, or allow someone access to your CMS who could translate the content. Both records would have the same ID in the database so the page would be served appropriately when the language was looked up.
Large corporate sites do the handling of the URLs in a couple of ways, they would show french content at http://www.some_website.fr/ and English content at http://www.some_website.com/. Sites like wikipedia use a subdns so http://fr.wikipedia.org/ and http://en.wikipedia.org.
HTML5 supports the lang='fr' approach to declaring content on screen.
I don't know what's your situation but, imho, you shouldn't use new urls.. it would only be a useless waste of resources (all kinds of resources).. If your website's client-side is javascript-based, you could use libraries like i18next, which gives you great support in localizations.. That's a valid alternative if you agree leaving the localization at you application's client-side.
For server-side localization in php, i wouldn't be of any help..
I Wan't optimize my web-site to search engines with multi languages...
i have that structure with languages:
English - example.com/en/
Russian - example.com/ru/
Georgian - example.com/ge/
on first join to my website he automated set you language by your country.
(for Google and other bot's default language are english) and all robots searched on my site only English texts.
Anyone know how can I optimize website in search engines with languages?
E.G: Google search example result
Probably your language versions should provide links to the same content in the other languages, then google has a chance of finding out that the other versions exist. I personally also would consider it good form to provide a way for the use to chose languages by hand. You can't always trust the language preferences coming in from the browser.
Another solution could be to offer a site map that links to each and every article in every language; that way, Google can also at least find out that more stuff exists.
I have to maintain a website in three languages: Arabic, English, and Pashto.
When the users select a language, for example arabic, when he applies any search in my website, how that search will be applied in my database?
When I'm updating the website (of course in english), how those updates will be reflected for arabic and pashto languages in the database?
First you have to decide what would be you database approach. Multilingual Site in Zend Framework
Secondly you have to decide what would be the approach to translated from one language to another. There are some options regrading this.
Add translated text for each language manually.
Use some translating service like google translate. But i dont think that you can rely on that. You have to add some approval system for translated text.
You can store multiple languages in an XML file (you can use http://php.net/manual/en/simplexmlelement.xpath.php to find what language you want based on the user`s selection), maybe even caching it...my opinion
Pro: further development (more languages)
I have a site with texts in 2 languages. How should I go between the pages so that from the point that he clicked to change the language he will see it and the moment he clicks the other language, it will change back?
An option is that when the user clicks the link to change the language I will store it into the session and use it. But I've heard it won't work well with the search engines.
A second option is to pass the language variable through the URL to every page.
Third option is to smartly use the zend extension ability.
(Using PHP + Zend Framework).
SEO is very important to me.
EDIT:
The texts that are in the site(and that are in several languages), are entered by an admin. It works now with languages objects that I've created with the option for the admin to add texts in each of them. So when I'll enter the first page(of which the text can be changed) I'll see it in English and when I click the Russian flag it will display that page(and the others later) in Russian.
Using Zend_Locale or translate won't work for me(I think), and passing through the URL is an option. The question is if it is the best one?
It is best to pass it along as a parameter in the URL, google uses locale=en for this. It would also be ok to store it in the session only if the user is logged into your website and selected a preferred locale or something. That way search engines can index the different locales with different urls, but your users would see pages in whatever locale they have chosen.
Zend Framework provides a pretty solid set of tools for this.
Start with Zend_Locale and Zend_Translate
It ought to be possible to tweak ZF's routing to contain a segment that indicates the locale. So you'd end up something like /:locale/:controller/:action (or similar). Your URLs would then look like http://example.com/en/some-controller/some-action.
Note that there's more than just translation of language. You can also localize the display of numbers, currency, dates, etc.
Come back with more specific questions once you've played with those.