0

I've heard that many people had problems using the language localization features, plus you can only translate the interface (I can't translate messages from a messagebox as far as I know). So I just wanted to know what do you think about my approach to translate my winform app.

namespace Tris
{
    class Translations
    {
        public string draws;
        public string language;
        public string help;
        public string newgame;
        public bool lang_en;
        public bool lang_it;
        public bool lang_ru;



namespace Tris
{
    class TranslationStrings
    {
        public void engTranslation(Translations TS)
        {
            TS.draws = "Draws";
            TS.language = "Language";
            TS.help = "Help";
            TS.newgame = "New Game";
            TS.lang_en = true;
            TS.lang_it = false;
            TS.lang_ru = false;


        public void rusTranslation(Translations TS)
        {
            TS.draws = "Ничья";
            TS.language = "Язык";
            TS.help = "Помощь";
            TS.newgame = "Новая Игра";
            TS.lang_en = false;
            TS.lang_it = false;
            TS.lang_ru = true;

When I need something I just call the right method:

case 2:
    pic = Properties.Resources.end3;
    if (lang_en)
    {
        strings.winTranslationsEng(TS);
        phrase = loser + TS.win3;
        End1 end3 = new End1(lang_en, lang_it, lang_ru, winner, loser, phrase, pic);
        end3.ShowDialog();
    }
    if (lang_it)
    {
        strings.winTranslationsIta(TS);
        phrase = loser + TS.win3;
        End1 end3 = new End1(lang_en, lang_it, lang_ru, winner, loser, phrase, pic);
        end3.ShowDialog();
    }
    if (lang_ru)
    {
        strings.winTranslationsRus(TS);
        phrase = winner + TS.win1;
        End1 end1 = new End1(lang_en, lang_it, lang_ru, winner, loser, phrase, pic);
        end1.ShowDialog();
    }
    break;

Before all the code was like:

if(lang_en)
{
    phrase="hi";
}
if(lang_it)
{
    phrase="ciao";
}

etc

Now it's way better than before, but I'm not still satisfied. This way of managing translations makes me use a boolean, so I have to add a new "if else" on which translation method I want to pick for every new language I add.

Do you have any suggestions about how to implement a better translation system? Do you think mine is legit or inappropriate?

edit: The application should be in English, then I can press a button to use either the Italian or the Russian language

Gino Perla
  • 91
  • 1
  • 10
  • you aren't really helping with the question and I find your comment offensive and not constructive – Gino Perla Feb 25 '15 at 13:51
  • Are you looking to localize your application according to the users preferences (Show all text in English or Italian or Russian) or do you want to make a translation application? – Bernd Linde Feb 25 '15 at 13:53
  • The application should be in English, then I can press a button to use either the Italian or the Russian language – Gino Perla Feb 25 '15 at 13:54
  • 1
    @Gino, I don't see what's offensive in my comment, but of course you're entitled to your opinion. I was only pointing out that dismissing the existing localization features as problematic and incomplete will not buy you much, especially when you attempt to replace them with a, let's say, "heavy" implementation. Don't reinvent the wheel, learn to use it properly instead. – Frédéric Hamidi Feb 25 '15 at 13:55
  • Well you're right, it was just not constructive at all. anyway I've tried to follow some examples a while ago now, but I've had some problems. That's why I was looking for your opinions about this being a valid or not valid approach – Gino Perla Feb 25 '15 at 14:00

1 Answers1

2

Your implementation of localization will work, but it will involve heavy maintenance, lots and lots of if statements and your entire codebase will need to be revisited when you want to add another language option to your application. You can imagine the headache that that will make for yourself or a future maintainer of the application.

Instead of rolling a self made, very heavy localization implementation, I would recommend that you familiarize yourself with how to do localization and globalization within C# on an application scale, utilizing resource files. Full information obtainable here

This method will even allow for localization of message dialogue texts, menu text, form headers and most importantly numerical representations of values
(Eg. US = $23 432.22 vs DE = $23.432,22 note the difference in thousand and decimal seperators)

Here is also a very good explanation from a similar question on SO:
How to use localization in C#

Community
  • 1
  • 1
Bernd Linde
  • 2,098
  • 2
  • 16
  • 22
  • omg I just had to use a resource file and call the strings from here based on which language I want to use. One more thing, can I disable the localization to have the application running in English and then change the language only when people click a change language button? – Gino Perla Feb 25 '15 at 14:09
  • 1
    You can do that yes by explicitly calling `Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");` in your main application and then change the language when the user requests it – Bernd Linde Feb 25 '15 at 14:13
  • I created a project and it works like a charm. Well it's more maintainable now. And also today I've learned something new, thank you – Gino Perla Feb 25 '15 at 14:22