Localization/Globalization

Why is the culture set to the current thread?

First let me explain this question. If you look at the code snippet of how to set the culture info.

Thread.CurrentThread.CurrentCulture = new CultureInfo(strCulture);

It uses the current thread to set it. What does that mean? Let’s drill down a bit of how IIS handles request to understand this concept. When any user requests a resource from IIS like an ASPX page or any other resource. IIS services that request in his own thread. That means if 100 users have requested some resource from IIS he will serve every request in its own thread. In short IIS will spawn 100 threads to More >

Can you list best practices for globalization and localization?

Below are the best practices while developing international language support software:

  • Do not hardcode strings or user interface resources.
  • Make sure your application depends on Unicode.
  • When ever you read or write data from various encoding make sure you use the System.text namespace. Many programmers assume ASCII data.
  • While testing test it with actual international data and environments.
  • Whenever we manipulate data for instance numbers, dates or currency make sure that you are using culture-aware classes defined in System.Globalization namespace.

Below is the table which specifies in more detail about the functionality and the classes to be used to achieve the same.

If a security decision is based on More >

Can we change the order in a select query with a specified collation sequence?

Yes we can specify a collate sequence in the order by clause. That will change the sort according to the collation defined in the order by claused.

ORDER BY

{

order_by_expression

[ COLLATE collation_name ] [ ASC | DESC ]

} [ ,...n ] ]

Can you explain collation sequence in sql server?

First let’s define collation.

Collation sequences are set of rules which determine how the data is sorted and compared. Sorting rules can be defined with options with case-sensitivity, accent marks, kana character types and character width.

Case sensitivity

If A and a, B and b, etc. are treated in the same way then it is case-insensitive. A computer treats A and a differently because it uses ASCII code to differentiate the input. The ASCII value of A is 65, while a is 97. The ASCII value of B is 66 and b is 98.

Accent sensitivity

If a and á, o and ó are treated More >

Can we get a strongly typed resource class rather than using resource manager?

In the previous question we had seen how resourcemanager class can be used to read the string from the resource file. But there has been considerable improvement in VS.Net 2005 for resource support. You no more need to load using resourcemanager class. Though Microsoft has still kept it for backward compatibility. You can now get strongly types classes in your VS.NET intellisense as shown in the figure below.

Can you explain the fundamentals of “GetGlobalResourceObject” and “GetLocalResourceObject” functions?

These two functions belong to the HttpContext object. Using it you can get the object reference of the resource object. For instance you can see from the below code snippet we have got reference to the Global resource object and we are trying to get the value for “lblUserIdresource1” key.

lblUserId.Text=HttpContext.GetGlobalResourceObject(“Resource”, “lblUserIdResource1″).ToString();

Note :- In the same globalization folder there is “LoginScreenUsingGetGlobal.aspx” which demonstrates how “GetGlobalResource” works.

One short note because “GetGlobalResourceObject” and “GetLocalResourceObject” operate from with in current HttpContext.It uses what the regional settings are sent from the browser end.

Can we sign a satellite assembly?

Yes you can sign the satellite assembly using the /keyfile switch which takes “.snk” file as the input parameter.

What precautions do we need to take while deploying satellite assemblies?

When we deploy the assembly, the folder structure has to very organized. Below table shows how the folder structure should be organized. MainFolder is the main application folder. All satellite assemblies should be deployed in the Main application folder with in there own respective folder. The respective folder is denoted by the culture code.

What’s the use of resource manager class?

ResourceManager class helps us to read the resource files and get the values using key.

First you need to create the object of resource manager. You need to specify the resource name and the assembly in the constructor.

private ResourceManager objResourceManager = new

ResourceManager(“Globalization.resource”,System.Reflection.Assembly.GetExecutingAssembly());

Once the resource manager is populated with details you can then use the GetString function to get by key. For instance in the below code snippet we are using the “cmdAddNew” key to get the value for button “cmdAddNew”.

cmdAddNew.Text = objResourceManager.GetString(“cmdAddNew”);

What is AL.EXE and RESGEN.EXE?

In the previous question you have see how we can use resource files to store data according to the localized languages. But when you actually go for deployment you will not like to also install the “resx” or “txt” files. It’s definitely not a good deployment practice to install data which can be easily modified. In short some how we should install this in a binary format so that no end user can change it. That’s why Microsoft introduced satellite assemblies.

Satellite assemblies are assemblies which do not contain source code. They only contain resource files. You can create a satellite assembly More >