今日推薦英文原文：《How to Pick the Right Language to Display on Your Website》
推薦理由：不要把所有的雞蛋放在一個籃子里，為日常使用的各種工具準備替代品能讓你不會在出錯時手忙腳亂——也可以讓你的選擇不會被限制。這個項目收集了一系列能夠代替 Google 服務的替代品，不管是希望在 Google 壞掉的時候尋找 Plan B，還是不再信任 Google 而希望尋找新服務，這都能派上用場。
今日推薦英文原文：《How to Pick the Right Language to Display on Your Website》作者：Tom Feron
How to Pick the Right Language to Display on Your WebsiteLocalisation on the web can be frustrating sometimes. Sadly, this is a problem you only encounter if you travel, you live abroad, or if you live in a multi-lingual country. That covers a lot of people but not necessarily those in charge of a web project.
It seems that the default choice made is to select a language based on the country the user is in — this, in turn, is based on their IP address. Even though this works if you』re an English-speaker living in Palo Alto, it fails miserably in a lot of other cases.
Indeed, it relies on the assumption that countries have one language and all people in said country speak that language as their primary language (or at all). This is utterly wrong. For example, in the U.S., only about 80% of the population uses English as their first language and about 13% uses Spanish instead. In Belgium, we have three official languages, namely Dutch (55% of the population), French (38%), and German (0.4%).
Not only does the default choice gives wrong answers, but it』s also overly complicated. In order to implement it, you would probably have to integrate with an external API, making your application more complex than it has to be and maybe less responsive. All of that for a suboptimal solution.
HTTP Has You CoveredThe HTTP protocol specifies the header Accept-Language for that specific purpose. With every request, the browser sends a list of languages with optional weights representing the preferences of the user.
Here are some examples from MDN』s documentation:
It』s not a silver bullet, though, and should be used as a last resort when we have no other ways of knowing the user』s preference in this particular instance. For example, my browser is in English but I would rather see the website in French, my mother tongue, when I log in to the Belgian tax website.
So how else could we know what language to choose?
Explicit and Implicit ChoicesOf course, if the user made an explicit choice by picking a language in a menu or in their settings if they』re logged in, then this must be the language they』re shown. But there are also implicit choices.
Most of the time, traffic is coming from somewhere else rather than having the visitor type the URL in the address bar. This can give you a clue as to the language preferred by the user. If I Google something and see a result in English, I want to see the English version when I click on the link.
Some websites hide the language in a cookie or in the session. It』s better to put it straight into the URL. That way, any link already contains an implicit choice. Search results will lead to the correct version and so will links on social media or any other pages.
Fallback StrategyOK, but maybe someone actually types the domain name in the address bar and has changed the browser』s settings to send Accept-Language: * or something like that. What do you do then?
It might be tempting to guess based on IP geolocation, but there is another dead-simple solution. So simple and obvious, in fact, that I don』t understand why more websites don』t use it.
You might not know what language the user speaks and might not be able to make a good guess, but the user knows.
After all this, there is still a possibility that you made the wrong choice. Make it easy for users to change the language. It』s not rare to see websites where it』s genuinely difficult to find the language menu. Most often it』s because the menu is written in the current language (which the user might not speak) without any visual cue. Use flags or some icon that can be understood by everyone.
In summary, a more reasonable way of picking a language goes like this:
- If the user has made another explicit choice, use it. Try putting the language in the URL for any page that might be indexed by search engines or shared.
- If there is an implicit choice — e.g., from the URL — use that language.
- Otherwise, use Accept-Language.
- If none of this works, just ask the user.