Architecture FAQ for Localization and Globalization - Part 2
(B) What are satellite assemblies?
(A) How do we generate Satellite assemblies?
(A) What is AL.EXE and RESGEN.EXE?
(I) What is the use of resource manager class?
(A) What precautions do we need to take while deploying satellite assemblies?
(A) Can we get a strongly typed resource class rather than using resource manager?
(A) Can you explain the fundamentals of "GetGlobalResourceObject" and "GetLocalResourceObject" functions?
(A) Can we sign a satellite assembly?
(I) Can you explain collation sequence in sql server?
(A)How do we define collation sequence for database and tables?
(A)Can we change the order in a select query with a specified collation sequence?
(A) Can you list best practices for globalization and localization?
(A) Why is the culture set to the current thread?
Other Interview question PDF's
In case if you have not seen part 1 of Localization and Globalization, click here
When we see around, architectures mainly discuss about loose coupling , scalability , performance etc etc. Many architecture forget one of the important aspects in software is making application globalized. Depending on project some application would not really want to have multi-language based websites , but i am sure many will. So in this article we will go through a series of FAQ which will give you a quick start on making application multi-language based.
Lately i have been writing and recording videos heavily on design patterns , UML and many architectural stuff you can visit http://www.questpond.com/ for design pattern and UML videos.
You can download by architecture interview question book from
In the previous question, you have seen how we can use resource files to store data according to the localized languages. However, when you actually go for deployment you will not like to also install the "resx" or "txt" files. It is 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 is 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 using rsgen.exe and al.exe. They are in binary DLL format, which makes it easier to ship it during deployment. So finally, during deployment you do not need to ship the resx files but only the compiled satellite DLL.
Figure 14.15: - resgen.exe and al.exe in action
The above diagram will give you a complete picture of how to generate Satellite assembly. You can see from the above figure we need two exe resgen.exe and al.exe. Once you made your resx file or text file, you should first convert in to a ".resource" files. This is done by using the resgen.exe. Below is the command snippet for resgen.exe where LoginScreen.aspx.el.resx is the resx file and output is Greek. Resources file. If you do not provide the output file name it will generate "LoginScreen.resources".
Resgen LoginScreen.aspx.el.resx Greek.Resources
You can also generate resx files from txt file using resgen.exe below is the code snippet for the same:-
Resgen MyLanguage.txt MyLanguage.resx
The above command snippet will generate a MyLanguage.resx using MyLanguag.txt file. You can make a DLL using resource files and not resx so you should make this conversion.
Now once the resource file is generated its time make the compiled assembly of the same so that it can be shipped during deployment. This is accomplished by using the assembly linker tool al.exe provided by Microsoft. Below is the command code snippet for the same.
al.exe /out: el.dll /c: de /embed: greek.resources
In the /out switch you need to provide the output DLL name. /c you need to specify the culture of the resource file. /embed you need to specify all the resources which are present in the resource file. As said previously other than strings you can also put image files like GIF, BMP etc. So those physical resources you can specify in the /embed switch. You can specify more than one resource use "," as a separator to specify more than one resource files.
Resource Manager 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.
privateResourceManagerobjResourceManager = new ResourceManager("Globalization.resource",System.Reflection.Assembly.GetExecutingAssembly());
Once the resource manager is populated with details, you can then use the Get String 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");
When we deploy the assembly, the folder structure has to very organized. Below table shows how the folder structure should be organized. Main Folder 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.
Figure 14.16: - Satellite Assembly folder structure
You can see from the above figure Hindi satellite assembly is deployed in hi folder, Greek satellite assembly is deployed in el folder and so on. If the program does not find resource file for a culture it uses the invariant culture satellite assembly. The above folder structure is a strict requirement when we deploy the satellite assembly. Any mismatch in the folder structure will lead to in appropriate results.
In the previous question, we had seen how resource manager class could be used to read the string from the resource file. However, there has been considerable improvement in VS.Net 2005 for resource support. You no more need to load using resource manager class. However, Microsoft has still kept it for backward compatibility. You can now get strongly types classes in your VS.NET intelligence as shown in the figure below.
Figure 14.17: - Strongly typed resource class
All belong to Resources namespace. Let us do a small sample and see how the strongly typed classes work in VS.NET 2005 and the simplicity, which they bring while implementing globalization in projects. Below is the screen shot of the project? It is a simple login screen with user id and password text boxes. User has options to select the language. Currently only two languages are provided English and Greek. Depending on the languages selected, the user id and password label values will be displayed.
Figure 14.18: - Strongly typed project
Note: - In the globalization project you can get the project sample in "LoginScreenUsingStrongType.aspx".
Below is the code snippet, which describes the various important sections of the code. First thing are the resource files. We have generated two resource files one for Greece with el and second is the general resource file which will be used when the regional code does not match.
Figure 14.19: - Walkthrough for using the resources namespace
There are three important steps in the code:-
. First is set the culture information for the current thread with the new culture info object. Structure has the language code, which is currently selected in the drop down.
Thread.CurrentThread.CurrentCulture = new CultureInfo (structure);
. We set the same culture to the Resource class.
Resources.Resource.Culture = Thread.CurrentThread.CurrentCulture;
. Now we are all set to use the value.
lblUserId.Text = Resources.Resource.lblUserIdResource1.ToString ();
blPassword.Text = Resources.Resource.lblPasswordResource1.ToString ();
Note: - You can get the same from globalization folder in "LoginScreenUsingStrongType.aspx". Try to add a new language and most of the fundamentals will be clear.
These two functions belong to the Http Context 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 reference to the Global resource object and we are trying to get the value for "lblUserIdresource1" key.
lblUserId.Text=HttpContext.GetGlobalResourceObject("Resource", "lblUserIdResource1").To String();
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.
Yes you can sign the satellite assembly using the /key file switch which takes ".snk" file as the input parameter.
al /res:MyLanguage.resources /c:de /keyfile:MyLang.snk out:MyLanguages.resources.dll
First, let us 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.
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.
If a and ÃƒÂ¡, o and ÃƒÂ³ are treated in the same way, then it is accent-insensitive. A computer treats a and ÃƒÂ¡ differently because it uses ASCII code for differentiating the input. The ASCII value of a is 97 and ÃƒÂ¡is 225. The ASCII value of o is 111 and ÃƒÂ³ is 243.
When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive.
When a single-byte character (half-width) and the same character when represented as a double-byte character (full-width) are treated differently then it is width sensitive.
You can create a database with language specific collation sequence. For instance in the below create statement tblCustomer is created by Latin language collation sequence.
Create database tblCustomer collate Latin1_General_BIN
You can also create tables with particular collation sequence. Below is the create table syntax for the same.
Create table tblCustomer
[CustomerCode] char(10) COLLATE Albanian_CI_AI_KS_WS NULL,
[EntryDate] [char] (8) COLLATE Korean_Wansung_Unicode_CS_AS_KS NOT NULL ,
[CustAbbrev] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
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.
[ COLLATE collation_name ]
[ ASC | DESC ]
} [ ,...n ] ]
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.
. Whenever 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.
Figure 14.20: - Functionality and classes used
. If a security decision is based on the result of a string comparison or case change operation, perform a culture-insensitive operation by explicitly specifying the CultureInfo.InvariantCulture property. This practice ensures that the result is not affected by the value of CultureInfo.CurrentCulture.
. Move all your localizable resources to separate DLL's.
. Avoid using images and icons that contain text in your application. They are expensive to localize.
. Allow plenty of room for the length of strings to expand in the user interface. In some languages, phrases can require 50-75 percent more space.
. Use the System.Resources.ResourceManager class to retrieve resources based on culture.
. Explicitly set the CurrentUICulture and Current Culture properties in your application. Do not rely on defaults.
. Be aware that you can specify the following three types of encodings in ASP.NET:
. Request Encoding specifies the encoding received from the client's browser.
. Response Encoding specifies the encoding to send to the client browser. In most situations, this should be the same as request Encoding.
. File Encoding specifies the default encoding for .aspx, .asmx, and .asax file parsing.
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 us 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 service the 100 request. It is very much practically possible that you can have different locale in different threads. Therefore, when we set a culture we cannotset it for the whole application, as it will affect all the requests. So when we set a culture we set it to a particular thread rather to the whole application.
.NET Interview Question PDF
Project Management interview questions
Download Networking Interview Questions
Download Software Testing Interview Questions
Download Sql Server Interview Questions
Download C# and ASP .Net Projects
Download Java Interview Questions
Download Software Architecture Interview Questions
Download Excel Question and Answers
Download HINDI Excel Question and Answers