I made a website in English, what's the most optimal way to add one more language?
So, I have created a big website (a lot of text in different files and a lot of programming). I need to add one开发者_JAVA技巧 more language, how should I do? What is the fastest way I can add second language and let my visitors to choose between them? Any ideas?
Thanks.Translation is something you have to think about from the beginning, especially with dynamic sites.
- Make sure all of your messages are split into a separate file or files which a translator can work on. There is an art form to this - you want large text blocks with formatting specifiers, as different languages don't follow the same noun/verb/adjective order. For instance, making text strings such as "Please choose" followed by "items" where the middle is a number is a bad idea, make the string "Please choose %d items" - this allows the translator to place the number in the ideal location.
- You want a strong translation tool. The fill full of string constants is acceptable, but has poor usability. Try
gettext
which is a mature tool for doing translations.
Regardless of your approach, you are going to need to store all of your outputted strings in a separate resource. Flat files with arrays would be the fastest, though an SQLite database would be more flexible.
If you were to use arrays, you would basically just make a few language files, such as english.php:
$lang = array(
'I am a language.' => 'I am a language.'
);
... and french.php:
$lang = array(
'I am a language.' => 'Je suis une langue.'
);
Then you could make a static Language class that would import the appropriate language file, and return translated strings based on the array in that file. For example:
Language::init('french');
...
echo Language::get('I am a language.'); // outputs Je suis une langue.
First you need to internationalize your entire web site, and then you need to localize it into your target language.
This is another case where the only numbers that matter are zero, one, and infinity. Either you support zero languages (there is no human interface at all), one language (which you just hardcode throughout), or any number of languages. Adding one more language is no easier than adding 10 more.
You can use gettext along with poedit, check this http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
My suggestion is: write the content in separated xml files, one for each language, and depending on the language of the user, you will load your website retrieving the content from the Xml that contains the selected language.
精彩评论