简体   繁体   中英

Php multilingual website

I am working on a website and the requirement is to make it in two languages ie icelandic and english. just like facebook and other google, if a user selects a language, then the site is translated in that language. I am not allowed to use google translator. Any other way to do this in Php

Thanks in advance

I use an es.php (spanish not sure what icelandic is) and build all of the mod_rewrite off that. You treat it exactly same as you would if it were the index.php for english. For inputing data into the database have a column for language. All of your queries that call data will then have the language as a condition.

“ gettext”是您可以使用的方式,但是如果您和您的客户很好地理解了,请他也提供英语以外的其他语言的数据,然后在DB表中将有一个“语言”列,其中“ ic'或'en'标志将是数据,并且在获取数据的任何位置期间,根据语言,您的sql查询将包含该语言作为where条件,并将所需标志作为其值。

Well, I never did it, but i did think about it :), for me i have to do something like this from scratch,

First, do not echo your String that will be displayed to your clients hardcoded, create a dictionary, this dictionary can be in any format, be it php file, xml file, json. You can also extend the functionality by adding Database in it. The main idea is to create a dictionary having all your messages that will be displayed to the user in all the languages you want to display it

consider if you do it using normal PHP FIle, use OOP built class say known as Message, then as attribute to the class add the several languages that you have to use and also some setters and getters

eg

Message
{
   english;
   french;
   .....
}

then in PHP, when you echo your messages, try to get the language you want to use, and then do something like this

echo message.getEnglishMessage();

Look, I've been very generic, now decide on the type of file that you'll use and build the dictionary

Hopes it helps :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM