Click here to Skip to main content
15,886,058 members
Articles / Programming Languages / C#

Localization process by using resource files in .NET

Rate me:
Please Sign up or sign in to vote.
4.56/5 (9 votes)
17 May 2010CPOL7 min read 70.2K   4.4K   42  
Process for localization when resource files are used in a Windows Forms application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Util;
using System.Globalization;

namespace HelloWorld
{
    public class MyClass
    {
        public string MyString()
        {
            TextResourceHandler h = new TextResourceHandler
                                            ("HelloWorld.Language.HelloWorld", 
                                            Assembly.GetExecutingAssembly());

            string s = h.GetString("Some_Key_In_Resx_File");
            return s;
        }

        public System.Object GetImage(string key_name)
        {
            TextResourceHandler h;

            // this name of resource file is a constant and not culturally related
            // In ORBIFLO we use resource files for images, but images are not
            // kept in resource files from localization perspective
            // its purely for customization only...
            // hence the usage or complete name of resource file

            h = new TextResourceHandler("HelloWorld.Language.HelloWorld", 
                                            Assembly.GetExecutingAssembly());
            
            System.Object imageStream = h.GetImage(key_name);
            return imageStream;
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect BrainScale Consulting
India India
I am a Technical Architect and Managing Partner for BrainScale Consulting. At BrainScale we do training and consulting on latest and greatest on Microsoft technology stack.

MCSD and BizTalk 2006 Certified Technical Specialist.

-Phani

Comments and Discussions