from Hacker News

Ask HN: Best Structure for a Multilingual Website?

by offsky on 3/1/23, 6:07 AM with 2 comments

I am planning to translate a static website into a few other languages. I am trying to figure out the best structure for doing this. I can think of 5 ways to do it. Example using Spanish:

1) es.example.com/index.html

2) www.example.es/index.html

3) www.example.com/es/index.html

4) www.example.com/index.html (with language set via a cookie)

5) www.example.com/index.html?lang=es

I see a problem with #2 already because TLDs are country specific not language specific. Also expensive.

I think #4 has a problem with regard to search engine optimizations as both languages would have the same canonical url. I would like my content to be indexed in both languages.

Wikipedia does #1. Apple does #3. Google does both #2 and #4.

Question 1) What structure would people here recommend?

Question 2) Would it be best to detect the browser's preferred language and auto-redirect people, or should I make the user do that language choice manually?

  • by necovek on 3/1/23, 6:30 AM

    I think Apache web server supported setting Content-Language automatically and doing content negotiation based on Accept-Language (browser-set language) for static sites if you simply used index.es.html.

    It's been a long time since I used this, so check the specifics.

  • by mytailorisrich on 3/1/23, 6:45 AM

    I think #3 is the most elegant and generic, and you can still use TLDs in addition. It also works well for a static website.