Multi-Language support in C#

Hi,

I have developed SmartDeviceApplication output of which is an .exe in C#.I want that exe to support multiple language.can anyone help me in this regard to how to do it.Wheather i need to add a new resx or do i have to create a dll I want to support basically both chinese and english depending on the user requirment.



Answer this question

Multi-Language support in C#

  • Osmose1000

    Hi Ahmed,

    Thanks 4 all u r support.But id id not get why we need to use

    Global Declaration
    ResourceManager rm;

    //In the constructor
    rm = new ResourceManager("YourNameSpace.Res", Assembly.GetExecutingAssembly());

    If suppose i have my application namespace as Message we should use

    rm = new ResourceManager("Message .Res", Assembly.GetExecutingAssembly());

    I have to display message based on the language choosed i.e MessageBox.Show(UpdateText.Text) must dispsplay message in

    respective language that the usere is opted.

    Can i use Add New String present in the resource and display message in the box.

    How can i load the respective resource if iam using different languages

    I have Form1.resx and Form1.zh-CHS.resx how can load depending on the language selected


  • microsoft_programmer

  • SweptSquash

    I want to know how to use the secound method.In which file i should declare

    ResourceManager rm;

    rm = new ResourceManager("Form1.zh-CHS.resx", Assembly.GetExecutingAssembly());

    //Getting the resources
    public void LoadResources()
    {
    label1.Text = rm.GetString("str_text");
    }

    How to use the string table


  • Abhishek Chadha

    Hi,

    I created a sample SmartDeviceApplication in C# and set the Localizable property to True and changed the Language to

    Chinese,which i want to support.What should i do next Do i have to add new resx by right-clicking on the project

    I have some textbox and label on the forrm.I want those things to be dispalyed in other languages when the application comes up

    How to proceed with this


  • Jenise

    Hi,

    How can i make out which language is used.Is there any api like GetUserDefaultUILanguage If so how and where to use it.With that i want to dispaly messages using MessageBox in respective language.


  • bluefocs

    Hi,

    I followed the steps whatever u told.In button handler event i coded as below.

    ResourceManager rm;

    //In the constructor

    rm = new ResourceManager("Form1.Res", Assembly.GetExecutingAssembly());

    // on the button Click event definition, add..

    MessageBox.Show(rm.GetString("Test"));

    But while debuging i am getting "MissingManifestResource" exception in MessageBox.Show(rm.GetString("Test"));

    I am guessing i am doing mistake in giving baseName of ResourceManager(first parameter)..and my all resource files names are given below.

    Form1.resx

    Form1.zh-CHS.resx.

    And namespace of my project is Message.

    So what should be the baseName of ResourceManager.


  • kangalert

    Hi Sunil,

    How are u

    anyway, Do the following Sunil...

    1- Create new smart device project..

    2- in the form, set the localizable property to true, add new lable and set its text to "Hello All".

    3- Choose Chinese(Simplified) language now, and set the new lable text to the alternative words in your language..

    This will switch the lable text with the change of the regional settings of the device..

    Now to use the Resource file.....

    4- Add new resource file and name it "Res.resx" and another resource file name it "Res.zh-CHS.resx", add a new string object in both resource files name it "str_Test" and set its value to "Test" in Res.resx file and "Test in Chineese" in Res.zh-CHS.resx file

    5- Add New Button to the form.

    5- Use this code:

    using System.Reflection;
    using System.Globalization;
    using System.Resources;

    //Global Declaration
    ResourceManager rm;

    //In the constructor
    rm = new ResourceManager("YourNameSpace.Res", Assembly.GetExecutingAssembly());

    // on the button Click event definition, add..
    MessageBox.Show(rm.GetString("str_Login"));

     

    run and test, click the button and see what it displays, now change the regional settings language and press the button again and see what is the output again..

    I hope this will answer your questions...

     

    Regards,
    If this post was helpfull, please press "Yes".

    Ahmed H. Waly



  • Jacco Mintjes

    Hi Ahmed,

    Thanks 4 the reply.But still i have some questions.

    1.Wheather i need to set CurrentUICulture If so do i have to do before InitilizeComponent and how to do it.

    2.I checked in the emulator and also in device there is no Chinese(Simplified) .How do i add that

    3.Is there any way without changing the Regional settings i can make my application to display in different language

    4.When i select different languages Form1.zh-CHS.resx and Form1.zh-CHS.resx will be added by itself right.So how can it differentiate in which language it has to display

    Can u please give u r mail id.It will be of great help.

    Regards,

    Sunil


  • search and deploy

    Hi Ahmed,

                          Thanks very much 4 u r support..I installed the chinese emulator and its working.But when i give chinese word inside a label

    it is showing boxes before compiling,but when it compiles it shows correctly.

    One more query!

    Now i am using message box to display some notification.Like i am communicationg with the help of message queue to interact with oter program.Depending on the response sent by that i will pop-up message like "Update Successful".

    How can i pop-up messages in chinese.Is there any way to use string table and map the id's.

     

    Thanks and Regards,

    Sunil

     

     


  • xlordt

    Hi sunil_sg,


    That's a very good steps u did, now..
    the way u choosed to use is the first i talked about, now to see the output of your work, u need to set the Language Regional Settings of your Device/Emulator to Chinese(Simplified), once u did this and opened the application, it should display the localized form to the new changes u did in the UI.

    You can't change the culture of the device programmatically, it is not supported, u can only get and not set it.

    To Load a strings from a resource file, add a new resource file to the project and name it any name u choose (e.g: Res.resx) now add another one and name it the same name and add the language name (eg: Res.zh-CHS.resx).
    Fill both resources files with data.

    To get data from them do:


    //Namespaces used
    using System.Reflection;
    using System.Globalization;
    using System.Resources;

    //Declaring resource manager in global
    ResourceManager rm;

    //in the constructor
    rm = new ResourceManager("AppNameSpace.ResourceFileName", Assembly.GetExecutingAssembly());


    //Getting the resources
    public void LoadResources()
    {
    label1.Text = rm.GetString("str_text");
    }


    You can get more info from here:
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=718942&SiteID=1

    if u need to know more info tell me,

    Regards,
    if this post was helpful, please press "Yes".


    Ahmed H. Waly



  • Trainwreck

    Hi Ahmed,

    thanks 4 the reply.But i am new to C# it would be helpful for me if u could elobrate on the above.May i know how to implement the above two methods.


  • NoEgo

    I have done the following steps:

    1. Do everything with the FormLayout (i mean design of my application.).

    2.After the Designing of the form is done the form is now using the default Language setting.Now build the application

    3.Change the forms properties Loacalizable to true and set the properties Language to whatever Language you like to Use.

    I used Chinese(Simplified)

    4.Change the Text of the Label,Button,Form and so on.. to the Language u have selected

    5.Build the application.

    6.Then i suppose i need to do

    Thread.CurrentThread.CurrentUICulture=new System.Globalization.CultureInfo("zh-CHS") to support chinese.But CurrentUiCulture is not supported in SmartDeviceApplication.

    How to proceed with this...

    Regards,

    Sunil


  • Sab2

    Hi sunil_sg,


    You can make a multilanguage application either by two ways:

    First, by making the application localizable, so when the user changes the culture of the device, the application will switch automatically to culture's UI if you added this language allready to the supported languages in the application.
    you can perform this by setting each form'm localizable property on the project to localizable, and then changing the UI to the new culture.

    Second way, by making a language option and a resource file (.resx) for each added language in your application, and depending on the selected language, you can load the images or the strings from selected language's resource file.

    i can help you on this if you don't know how to perform this.


    Regards,
    if this post was helpful, please press "Yes".


    Ahmed H. Waly



  • Kris2006

    Hi sunil_sg,


    1- u can't set the CurrentUICulture in CF programming, it can't be setted, only used to get it.

    2- if you don't have the Chinese(Simplified) lang. in your emulator, then you can download a localized version of the emulator for this language from Microsoft site. and if it doesn't exist in your device too, then your device doesn't support it too.

    3- This way is used to change the UI lang with the change of the regional settings, but you can use alternative way by loading the strings from a resource file after checking the language the user want in your application, but it must be supported on the device or it will display a rectangles or strange characters.

    4- after selecting another lang, it will add new .resx file to the form, and it will use this file when the related lang is selected on the Regional settings...

    i hope i answered most of your questions....
    if you need to know more ask me and i'll be happy to help you.


    Regards,
    if this post was helpful, please press "Yes".


    Ahmed H. Waly
    ahmed_h_waly@hotmail.com



  • Multi-Language support in C#