Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im on a multi lingual web site project using asp.net C# , i need to check the culture info in every request because content of web site dynamically gets from database and at this point i need to define that which language of specific content load to site ,where is the best place to save the language culture ? cookie or some where else ? and where the best place to check the language of site ?
Posted
Updated 1-Oct-14 18:54pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Oct-14 18:05pm    
There is no such thing.
—SA

There is no such thing as "language of a Web site".

Any site can be in many languages. In many cases, you cannot even tell the language of a single phrase, because a phrase can be a mixture of two or more different languages; and some words can be valid words in two or more different languages. If course, you can parse HTML and read the content of the lang attribute: http://www.w3.org/TR/html401/struct/dirlang.html[^].

Even if such attributes are available, they don't give you a solution. This information is only used for technical purposes by the authors of the site:

Language information specified via the lang attribute may be used by a user agent to control rendering in a variety of ways. Some situations where author-supplied language information may be helpful include:

  • Assisting search engines
  • Assisting speech synthesizers
  • Helping a user agent select glyph variants for high quality typography
  • Helping a user agent choose a set of quotation marks
  • Helping a user agent make decisions about hyphenation, ligatures, and spacing
  • Assisting spell checkers and grammar checkers
Similar thing can be said about content encoding. By the very nature of things, content does not have to have any certain language.

In general case, the problem is not only not solvable; it cannot be even formulated in any valid way. You only can invite the users to indicate the language of the request in some way, for example, via a selected item in some list box.

—SA
 
Share this answer
 
There are several approaches in use.
If you want to go beyond the accept-languages header of the request of the web browser, you can have the user chose the language from a menu and then "add" it to further requests.
Sometimes, you see URLs like www.yoursite.ir/fa/somepage.aspx vs. www.yoursite.ir/en/somepage.aspx, or in query parameters like www.yoursite.ir/somepage.aspx?lang=en etc.
But this approach has a drawback: when the user closes the browser, the language information is lost. Hence many sites persist the user selected language in a cookie (make sure to set an appropriate expires header for the cookie, as otherwise its lifetime is limited to the current session only).
If your users have to log-in into the site, you could also store their selection in the database, and thus retrieve it therefrom based on the user id.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900