简体   繁体   中英

How to make a small website multilingual?

I have this really tiny (static) site, that is basically just my online business card and I want to have it in English and German. I detect the browser language and also let the user chose manually; so I have the right $lang variable ready.

My question is how are the multiple languages best implemented (or loaded)? Right now I do this with PHP switch statements but I feel this is not proper at all. My next guess is to use XMLs, one for every language, then load the right one but I wonder if there is a more clean, simple and proper way to do this; meaning easy to maintain and extend, easy to understand, compliant with standards and fast.

Thanks for the help!

Have an array with all the texts, and place them in seperate files (one for German, one for English):

<? return array(
       'contact' => 'Kontakt'
);

Load that array and use it to display the text.

If you're using a CMS (content management system) there are other options.

标准的PHP方式是使用gettext的功能作为解释和的.po /的.mo文件在这里

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