Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1.- I am looking for some example of multilanguage application in C#. I'm not talking about entering the text of each language by hand.

2.- In WPF I have several ComboBox linked to a table in a Sql Server database. How can I translate the texts retrieved from the database into the active language? I do not want to add in each table a text field for each language.


What I have tried:

What have you tried?
What have you tried?
Posted
Updated 17-Aug-18 23:05pm

1 solution

Multi-Language support in C# is controlled by the following 2 properties:

C#
Thread.CurrentThread.CurrentCulture
Thread.CurrentThread.CurrentUICulture


which you can either query or set at runtime:

Thread.CurrentThread.CurrentCulture = new CultureInfo(options.LanguageSelected);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(options.LanguageSelected);


Reference: Edi/App.xaml.cs at master · Dirkster99/Edi · GitHub[^]

The referenced project uses this information to find the right *.resx file for the best language match a user might be looking for.

How you use this in a database table is completely up to you and depends and the other all structure (about which you are telling nothing so I am left to guessing). But simply put, if you jsut want to retrieve strings from a table, why not having a table with strings like this:

SQL
Create Table MyStrings
(
  id       int          not null,
  mystring varchar(255) not null,
  langid   int          not null
)


where the langid identifies the language of a given string and the id itself should be unique to identify each string - you can then use this structure to find strings you have not translated, yet, or determine if there is a translation at all.

You should of course always have all required strings available in a base language (eg. English) at the very least. The best way of ensuring this might be unit testing against it...
 
Share this answer
 
Comments
[no name] 18-Aug-18 5:13am    
What I want to say is that in the end you have to introduce the texts by hand and that is what I do not want to do.
Dirk Bahle 18-Aug-18 8:55am    
OK. You want to follow a process and you should have a tool that supports your process. In my case, I've been using a tool to translate fomr a base language into any other language

https://github.com/Dirkster99/Locult

The tool consumed resx files and produced matching resx files based on a language translation service. It was free and easily to use until Microsoft required the use of a credit card - that said, its still free but I have to up date for the new API before it will work again.

You could use a similair file based approach (resx, csv, xml), because most translators won't be able to deal with your database directly and you probably want to limit access anyway.
[no name] 18-Aug-18 10:37am    
Programs that are Multilanguage, how do they do it? Do they employ dozens of translators? I thought there was some use like connecting to Google translator.
Dirk Bahle 18-Aug-18 11:59am    
Yes, software companies usually buy the service from a translation agency to translate from English to Chinese, English to German and so forth, open source works similar but usually without the money aspect.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900