Search code examples
c#winformsresx

Implementing language files for c# windows form application


I have a windows form application that has various strings displayed as text labels that are currently assigned strings from a .resx file from within the project. I use a resource manager to look at the resource file I need:

ResourceManager rm = new ResourceManager("UICS_Client.english_Lang", Assembly.GetExecutingAssembly());

And then in a function the labels on the form are set to strings from the resource file:

adminTab.Text = rm.GetString("adminTab");

Then if the user needs the application to run in a different language I switch the resource file used by the resource manager.

rm = new ResourceManager("UICS_Client.chinese_Lang", Assembly.GetExecutingAssembly());

This works great but requires the resource file(s) to be within the project at build time. What I would like to do it have a solution where the form application can scan a folder on the users PC containing 'language files' which the application then reads in the language file selected by the user in a settings tab (the selected file would then be re-used each time the application runs). This is so I can later deploy the language files to users without having to rebuild and send out new versions of the software.

Has anyone done something like this and are there any suggestions for me to try?


Solution

  • I ended up using an SQLite database for my language file, with columns for entry number, tag, and then the languages

    So for example:

    |Entry|  Tag  | English | German |
    -----------------------------------
    |  0  | hello |  Hello  | Hallo  |
    

    So when the form requires a string in english it would send the SQLite database a request:

    SELECT English FROM `Strings` WHERE(Tag='hello')
    

    Which would return column English entry 0: "Hello".

    This way when a new language is required a new column can be created with translations for each entry.

    The form can also request the column names to see which languages are available.

    One language file can then be deployed and changed for the existing language files already used by users.

    Of course the form also needs to handle the error if there is no language file found on the system.