………
<globalization/>
</system.web>
</configuration>
3. Programmatically
Collapse | Copy Code
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-CR");
base.InitializeCulture();
}
How to manage user input data in globalized applications
When we say web application it don’t just display information. It also take information from user and ultimately it stores these information in database.
In order to make a complete proper multi lingual application a proper database design is must. And in order to create proper database design we should know following things.
What is Sql Server collation?
Sql server collation is concerned with how character data is interpreted by sql server.
In short collation specifies three properties.
Sort order for non-Unicode data types like char, varchar.
Sort order for Unicode data types like varchar and nchar.
The Code Page used to store non-Unicode character data.
(We will not talk in detail about code page in this article, but in short it defines a set of values for a language each representing a particular character. For detail visit this link http://en.wikipedia.org/wiki/Code_page)
Now sort order also depend on
Case sensitivity – is ‘A’ and ‘a’ same or not?
Accent sensitivity – is ‘a’ and ‘á’ same or not?
Kana sensitivity – is Hiragana character and Katakana character treated as same or not? Belong to Japanese language).
Width sensitivity – is “Sql” as varchar and “Sql” as nvarchar same? In short is single byte character is equal to its double byte representation?
How to deal with collation?
Collation can be applied
At sql server instance level (at the time of installation).
Note: Collation applied at server level can be changed afterwards. For detail visit this link.
http://msdn.microsoft.com/en-IN/library/ms179254(v=sql.105).aspx
At database level (at the time of database creation).
Collapse | Copy Code
CREATE DATABASE newDatabase
COLLATE SQL_Latin1_General_CP1_CS_AS
At column level
Collapse | Copy Code
CREATE TABLE [T1]
[NormalColumn] [varchar](50) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL,
[AdvancedColumn] [nvarchar](50)COLLATE SQL_Latin1_General_CP1_Ci_AS NOT NULL
At query level
Collapse | Copy Code
SELECT Column1
FROM Table1
WHERE Column1 COLLATE Latin1_General_CS_AS = 'casesearch'
and Column2 COLLATE Latin1_General_CI_AS = 'CaseInsensitiveSearch'
Collation and TempDb
TempDb is the place where all our temporary tables and procedure will be stored. This database gets created every time sql server is started. Now the question is what will be the collation of the database? In simple word answer for this question is, same as Model database. And it means database on which we are currently working (for example customer database) and TempDb database have different collations which may lead to unexpected outputs.
In order to avoid such problem one solution will be explicitly set the collation for every column while creating temporary tables.
Collapse | Copy Code
CREATE TABLE #T1(
[NormalColumn] [varchar](50) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL
) ON [PRIMARY]
What is the difference between varchar and nvarchar?
Now in sql server in order to store user input (especially texts) we have choices like text, ntext, char, nchar, varchar, nvarchar etc.
Almost every data type has it’s ’n’ representation. Now the difference between them?
Well one without ‘n’ stores non Unicode characters and one with ‘n’ stores Unicode characters as well.
And so data types such as nvarchar, nchar are capable of storing data of multiple languages.
How to localize JavaScript messages in Asp.Net
1. Using hidden fields and labels
In order to localize JavaScript message one thing we can do is, we will put either label or hidden field in the page.
Assign values to those controls at runtime based on cultures from resource files.
In JavaScript whenever message need to be displayed, we will just access the control and get its value.
Example: alert ($(‘.ConfirmationLabel’).text());
2. Using JSON
We will create a JavaScript file which will contain JsonObject something like this,
Collapse | Copy Code
var MyAppLocalizedMessages =
{
DoYouWantToDeleteMessage: {
'en/US': 'Are you sure?',
'fr/FR': 'Are you sure in Spanish?'
}
}
Create a hiddenfield in the page and in the page load or page init assign current culture code to it. Example: HiddenCulture.Value = Session["CurrentCultureCode"].ToString();
Every time you want to display the message use the following syntax var message=MyAppLocalizedMessages.
DoYouWantToDeleteMessage[$(‘#HiddenCulture’).val()];
3. Using a jQuery plugin
Read here
4. Using script Manager
Read here
Conclusion
In this article we have learned how to create a multi lingual website using asp.net. Thank you for your patience. Keep reading, keep learning and keep sharing.
For technical training related to various topics including ASP.NET, Design Patterns, WCF and MVC contact SukeshMarla@Gmail.com or at www.sukesh-marla.com
For more stuff like this click here. Subscribe to article updates or follow at twitter @SukeshMarla
For 500+ videos on MSBI, .NET, SharePoint, Architecture, SQL, WPF, WCF, MVC, ASP.NET etc click @ www.questpond.com
Deep talk on Cultures and languages with Asp.net and Sql
Start from the beginning
