In our current globalized world, at this time, any web site must be multilingual, enabling the user to select the language to use.
Moreover, a global company needs to know from which country the user connected.
A lot of sites, more of the streaming services as examples, identifies the country based on the IP address. Which could be a mistake, since a lot of people are in a different country of which belongs to.
Anyway, your database must need a language list and a countries list.
This post shows you a sample application which, using the standardized languages and countries from .Net Framework, and adding some information from external sources, set up some tables to manage this in your databases.
The tool uses information from the System.Globalization namespace, which appears with .Net Framework from it very beginning.
The CultureInfo type exposes each of the languages in use around the world thru the GetCultures member, based in the ISO 639-1: Codes for the Representation of Names of Languages and in the ISO – ISO 3166 — Country Codes.
Each CultureInfo class instance exposes these properties among others:
|Name||The identifier of the culture in the culturecode2-country/regioncode2 format|
|EnglishName||The culture name in Enlgish|
|DisplayName||The culture name in the culture of your current configuration|
|NativeName||The culture name in it own culture|
|IetfcultureTag||The culture part of the name|
|LCID||The Windows Language code|
|ThreeLetterISOcultureName||ISO 639-2 code|
|TextInfo||Information about text management|
|Calendar||Calendars used by the culture|
|DateTimeFormat||How the dates and times are managed|
|NumberFormat||How the numbers, currencies etc. Are used|
|IsNeutralCulture||Indicates if it is just a language or a language and country specification|
Finally, I get information from two external sources. I got the GPS coordinates of each country from here meanwhile the flag’s pictures are from here. You can found the urls inside the code as well.
The tool create 3 tables as you can see in the Diagram.
It is necessary this way, because some countries use more than one language, and the relationship must be preserved.
The tables have a InUse column, to enable/disable each row for your application. So, you can query the Languages table for all the rows with the InUse value in 1, to display only those languages you desire use, or have enabled.
Note: It is important using nvarchar/nchar data types, since several Native names are in UTF-8 chars.
Using the tool.
The tool expects at least the connection string to your database. It accepts a second parameter for the schema name under the tables will be created. If this value is not provided, the tool assumes “Masters” as schema name.
In any case, the DDL scripts manage the creation of the schema if it does not exist.
The source code of the DataGen solution is in my GitHub.
If you prefer just use a T-SQL script to add the tables, here is the script.
In future posts, I will show some faqncy methods for site AND CONTENT localization.