What's the best way to have a website with multiple languages?

I'm designing a website that is already translated into Portuguese and English. In this moment, there are two different websites for them:

http://yogmel.com : English version

http://yogmel.com/pt/ : Portuguese version

I've done some research and I found out that that's not the best way to do it.

What's the best way to change a website's language? I already have the texts/pages translated and don't want it to be translated by a third party (Google Translator, Wix, Squarespace).

I'm willing to learn and program php if that's the best way.


The "best" way is too opinionated but the simplest way is basically you need some way to keep a phrase by phrase table of translations. The key field would be the phrase in the main language (or a unique identifier thereof), with other fields for the translation in each language, and you print the phrase to the page by calling a function that takes the parameters of the phrase in the main language and the target language.

<div>
  <p><?php echo translate('Welcome to the site', $targetLanguage); ?></p>
  <p><?php echo translate('Our company is committed to excellence!', $targetLanguage); ?></p>
 <!-- if using identifier approach instead: -->
 <p><?php echo translate('Paragraph_of_company_propaganda', $targetLanguage); ?></p>
</div>

The database here could be an actual database, or a big PHP array, depending on how you want to do it.

A list of languages the user's browser claims they accept can be found with $_SERVER['HTTP_ACCEPT_LANGUAGE'] which should return an array with the most acceptable language first. The languages will be represented by a two character code like EN, ES, FR....

链接地址: http://www.djcxy.com/p/37490.html

上一篇: 使用实体框架从三个连接的表中获取信息

下一篇: 拥有多种语言网站的最佳方式是什么?