Take the 2-minute tour ×

I've the following code to convert the controls in static mode i.e by writing the translated string(french,german etc) and saving the resource file and calling it back. How ever if I need to translate dynamically(including the user-inputs), say like how google translator works. I need to implement the same in offline mode. Is there any possibility to access google like translators, which instantly/dynamically translates to the selected language, but offline? Or please suggest me any preferred method.

foreach (Control c in this.Controls)
        ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm));
        resources.ApplyResources(c, c.Name, new CultureInfo(lang));

-- Regards, Manohar.

share|improve this question
add comment

1 Answer

I don`t know if it helps you, but here is what I did. It's written in managed c++ /clr you can easyly translat it to c#. I wrote a little helper calss to manage the translation process

(You can change the language during runtime with this! It will instantly translate the whole form.)

ref class LanguageSwitcher
   /// <summary>
   /// Change language at runtime in the specified form
   /// </summary>
   static void SetLanguage( Form ^form, CultureInfo ^lang )
      //Set the language in the application
      System::Threading::Thread::CurrentThread->CurrentUICulture = lang;

      ComponentResourceManager ^resources = gcnew ComponentResourceManager( form->GetType() );

      ApplyResourceToControl( resources, form->MainMenuStrip, lang );
      ApplyResourceToControl( resources, form, lang );

      form->Text = resources->GetString( "$this.Text", lang );
   static void ApplyResourceToControl( ComponentResourceManager ^resources, Control ^control, CultureInfo ^lang )
      for each( Control ^c in control->Controls )
         ApplyResourceToControl( resources, c, lang );
         String ^text = resources->GetString( c->Name + ".Text", lang );
         if( text != nullptr )
            c->Text = text;

   static void ApplyResourceToControl( ComponentResourceManager ^resources, MenuStrip ^menu, CultureInfo ^lang )
      if(menu != nullptr)
         for each( ToolStripItem ^m in menu->Items )
            String ^text = resources->GetString( m->Name + ".Text", lang );
            if( text != nullptr )
               m->Text = text;

This is how it is used:

System::Globalization::CultureInfo^ lang = cli::safe_cast<System::Globalization::CultureInfo^ >(langCombo->SelectedItem);

Hope this helps!

share|improve this answer
add comment

Your Answer


