Deep talk on Cultures and languages with Asp.net and Sql

Start from the beginning
                                        

We will talk about both of them in detail with Example.

1. Local resource files

Local resource files will be linked to only one aspx or ascx file. Using it, we will tell the system what every word or sentence will be called in a particular language and culture.

Step 1 

For creating resource file go to the design mode of your aspx file and then click on tools->Generate Local Resource Files.

Step 2

As soon as you do that you will notice 2 changes

A new folder called App_LocalResources get created in the solution explorer with a file called Login.aspx.resx.

Every server control in your UI is now attached with a property called “meta:resourcekey”.

In Resource files you will notice couple of key value pairs, where every key represents particular property of a particular control and value represents the content.

Step 3

Copy the resource file and create a new copy of it and rename the new copy to “Login.aspx.es-CR.resx”. Here es-CR is called Culture indentifier. Culture identifiers are made by 2 tokens – the culture name and the language name.For example here ‘es’ represents Spanish language and ‘CR’ represents Costa Rica culture.

Step 4

Open the newly created resource file. This file is just a copy of your previous resource file that is “Login.aspx.resx”, so you will find all the keys in this new file which were there in previous file.

Use Google translator or any other tool and put Spanish representation of every word/sentence in corresponding value field.

Step 5

Execute application for both the cultures and check the output.

Note: If you notice width of the button get increased. Now that is what we are supposed to consider in globalization phase. While designing the UI we should consider the fact that in future we are going to make the UI available for other languages also and that’s why we should either put the width of control(which are going to change its content in future) to ‘auto’ or to max value.

2. Global Resource Files

Global resource files are not linked to any particular aspx or ascx. Let’s say we want to reuse some messages across multiple pages and also these messages shoul be language based. In this situation global resource files comes handy.

Step 1

Right click your asp.net project Add->Add Asp.Net Folder->App_GlobalResources.

Step 2

Right click the folder. Click on add Item. Select Resource file. Name it DisplayMessages.resx.

Step 3

Open the file, it will look like Local resource files but with no entries.

Add an entry into it.

Step 4

Create a duplicate copy of the file and name it DisplayMessages.es-CR.resx.

Step 5

Open the newly created fie. And change value to its Spanish representation.

Note: For demo purpose I just used the demo Text.

Step 6

Create a label in Login page as follows

...Where stories live. Discover now