subject: Overview Of .net String Resources For .net Application Development [print this page] .NET application development features and functionalities are designed keeping in mind the increasing flexibility required in an increasingly globalized world. With the extensive spread of a global economy, application development has to reach and serve multiple geographies. Hence, there rises the need to localize applications into the local languages. This is achieved through the string functionality in .NET application development framework.
What are string resources?
The .NET development features enable efficient creation and management of resource files from resources that are in XML format or binary data such as images. The resources can be compiled into assemblies. .NET application development supports writing of resources onto an external file. External resource files are commonly used to define localized string messages. When the application is released in a new language all that is required is the provision of the correct resource file without the need for a recompilation.
How does it work?
Language independence is achieved through maintenance of language-independent elements as a separate module distinctly different from the actual software code. This obviates the need for the time-consuming and error-prone redefining, debugging, and recompiling of the application code. In .NET development framework, externalized string handling functionality is achieved through ResourceManager class. ResourceManager allows controlled access to strings, user-defined string resource files, enumerations strings, type safe formatting, etc. This plausibilizes the introduction of an application in a new language through creation of respective localized resources. GetString method of ResourceManager is used to retrieve the string resource by passing the string name. The method returns the localized string.
How does it look?
.NET application development can leverage the string-handling capabilities of the .NET development framework to create truly language-independent software applications. The steps to create string resources are:
Enter name values for all strings in a text file
Use Resgen.exe to convert the text file into a .resources file
Create a DLL
Use the Assembly Generation Tool or any other language compilers of .NET development framework and embed the .resources file
Find below an example illustration of the definition of a string resource file.
Static void myResource()
{
rw.AddResource(1, The order is confirmed.);
rw.AddResource(2, Click here to enter.);
.
.
.
rw.Generate();
rw.Close();
}
The above sample code illustrates the process of creation of resources file. You can define as many strings as needed that need to be localized when the .NET application is released in a new language. rw stands for ResourceWriter which enables writing to binary *.resources file. rw.AddResource method allows us to add the string resources with a name and a value, the format being, rw.AddResource(, );. rw.Generate() enables us to create the string resources and rw.Close() is used to finish and return. Alternatively, you can use XML or simple text files to generate string resource files through the RESGEN.EXE utility.
Conclusion
The versatile .NET development features enable efficient creation and management of resource files. External resource files are commonly used to define localized string messages. When the application is released in a new language all that is required is the provision of the correct resource file without the need for a recompilation.