Multi language website, how to approach this?

I have a website (Coldfusion) on which I want to offer multi language, but no idea what is the best way to do this.

There 2 plans I have:

1:

Of course all content (text) is in a database.

If a user would want a different language, the user would click on a link/flag, this would put the requested language in a session variable, for example: session.language = "es"

In the database I would have 2 columns (every language has 1 column) and then select the text which belongs to 'es'

Every page would then do a request to the database to get the text beloging to the session.language.

PROS: Relatively simple to implement

CONS: SEO wise I don't think this could be very good. http:// www.domain.com/page.cfm would give an english text or spanish text (or other language). Google will not add duplicate URL's

2:

Do something with http:// www.domain.com/en/page.cfm for english and http:// www.domain.com/es/page.cfm for english.

With a URL rewrite rule the language value in the URL http:// www.domain.com/en/page.cfm would actually be a page http:// www.domain.com/page.cfm?language=en

The url.language variable will then select the correct language from the database.

PROS: Unique URL for each language. Good for SEO and Google indexing.

CONS: A bit more difficult to implement. (I think)

Or does anyone have other / better ideas?

Thanks!!


You should always first check the browser header "Accept-Language" for the default language(s) (the correct standard way to do it), and offer links (the intuitively seemingly right way) only as an alternative.

Doing it in a database doesn't seem very standard. Let's assume you would like to use MVC architecture (model-view-controller). Most software uses keys in the presentation layer (view) (eg. html) and along with the presentation layer, you have language files (in Java, this is typically properties files) which are mapped simply by their filenames, and can be modified by regular users, without any special skills, such as professional translators with no computer skills. Certainly you could put it in a database, but then it is just more work, and moves the information out of the presentation layer.

There are various libraries for doing this. You should find the normal one for your application. Please edit your question to include what you are using to develop the application. (eg. JSP, Tapestry, Wicket, ASP, PHP, etc.) So for example, if you wanted to use JSPs, I would then suggest you use the JSTL tag library's language support. Or if you were using Tapestry, I would point you to http://tapestry.apache.org/localization.html or http://tapestry.apache.org/tapestry4.1/UsersGuide/localization.html

To look it up, you can look for the terms "internationalization" aka "i18n", or "localization". (The terms don't mean the same thing, but few use them correctly, so either works. http://www.w3.org/International/questions/qa-i18n)


I would go for option 2. Every translation should have its own url. Links to your website will already be in the intended translation.

To store translations in a database, I wouldn't put every translation in a seperate column, but rather put them in a seperate table:

Table Posts:
- id
- title_id
- ...

Table Translations:
- label_id
- value
- country_code
- language_code

Where title_id matches label_id

This way you won't have to alter your table structure when a new translation is added. This allows you to have infinite translations for any label or text.


To effectively do a multi-lingual site then you need set a rule for yourself that NO TEXT is ever put in the source as hard coded. It either needs to come from the database and / or a Resource Bundle.

Text from the database

You need to make sure that the column you are storing your data in is unicode otherwise you'll have issues with accented character. Also don't have a column per language as this is not scalable, do what @jan suggests and have a translations table where the items are keyed on a reference as well as a language.

Resource bundles

You are not going to want to get every last little bit of text from the database so for those you can utilise a resource bundle. This is an, admittedly old, link http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=FD48909C-50FC-543B-1FE177C1B97E8CC1 from Paul Hastings's blog about some solutions to resource bundles. To be honest his blog is an excellent resource on this very subject.

With regards to how you handle the URLs do not do option 1 as you quite rightly identified you will cause issues the SEO rankings of the page and it will mean that users cannot correctly share or return to the page.

Two approaches are having the language code in the URL as you identified in option 1.

Pros

  • Simpler to configure
  • Cons

  • You have one application which means that as you add more languages you add more complexity and weight on the memory of that app
  • Or you can have a different sub domain or domain per application eg es.yourdomain.com or yourdomain.es they can all be the same codebase

    Pros

  • Each language is a standalone application meaning it has it's own memory
  • Cons

  • more effort to configure
  • 链接地址: http://www.djcxy.com/p/37486.html

    上一篇: 在php中完成多语言网站

    下一篇: 多语言网站,如何解决这个问题?