• Translations are saved as *.resources files under %appdata%
  • Uses a Class inside the main application to hold translations.
  • This Class is derived from a base class inside the TranslationDlg.
  • The base Class contains the current CultureInfo and RegionInfe for the selected language.
  • Translations are defined either Fields or Properties in this Class with an mandatory grouping attribute.
  • Transation Properties can adjust the user-interface in their set code. For this a simple helper function is supplied.
  • Translations Properties can store text directly the controls Text properties
  • Translation Fields can be used for messages.
  • Translation are checked for the correct number of String.Format replacement patterns '{n}'.
  • Translations can be automated by the integration of Google Translate.
  • A helper function for performing an initial translation (saving the default text) is available.
  • Can translate tricky controls like MenuItems & ListViewHeaders that are not named and hard to access through reflection.

Sample code:
  • Derived CustomTranslations class in main application with a Field type string:
public class CustomTranslations : TranslationDlg.Translations
    public String sAlbumId = "Album Id:";
  • CustomTranslations constructor that takes a reference to Form1 in the application (used for translating controls and adjusting the user-interface)
public class CustomTranslations : TranslationDlg.Translations
  private Form1 fForm;

  /// <summary>
  /// One must define a construtor that takes the Form1 as 
  /// parameter to be able to refer to controls on it 
  /// in order to translate them and 
  /// be able to adjust the user-interface.
  /// See the code for labels and buttons.
  /// </summary>
  /// <param name="form">The Form1 to be Translated</param>
  public CustomTranslations(Form1 form)
      : base()
      this.fForm = form;
  • Translation Property that stores its value in the Control's Text property:
/// <summary>
/// Translation of a ListViewHeader.
/// </summary>
public String cAlbumTitleColumn
    get { return fForm.AlbumTitleColumn.Text; }
    set { fForm.AlbumTitleColumn.Text = value; }
  • Same as above but with adjustment of the user-interface (alters the Width of a neighbouring ProgressBar):
/// <summary>
/// Translation of a Button.
/// </summary>
public String cDownloadBtn
    get { return fForm.DownloadBtn.Text; }
        Rectangle deltaBounds = SetText(fForm.DownloadBtn, value);

        fForm.progressBar1.Width = fForm.progressBar1.Width - (deltaBounds.Width);



Last edited Jan 7, 2010 at 2:11 PM by wvd_vegt, version 10


No comments yet.