Skip to main content Skip to footer

C1Editor Localization

All end user visible strings in ComponentOne Editor for WinForms can now be localized (translated). Editor for WinForms localization is based on the same approach as the standard localization of .NET Windows forms employed by the Localizable property. As with Windows Forms, you can create a set of resource files with extension .resx for different cultures for the Editor. When the application runs you can switch between those resources and between languages. All parts of your application using components from Editor for WinForms DLL must use the same localization resource.

Localize Dialog Box

To localize C1Editor component in your application, select Localize in the C1Editor tasks or context menus. Clicking Localize opens the Localize dialog box. The Localize dialog box allows you to localize the ComponentOne Editor for WinForms assembly (C1.Win.C1Editor.2.dll) and save the localized resource in any project of your solution. On the left of the Localize dialog box, there is a tree listing the localizable strings' IDs, and on the right are the strings themselves. The structure of the tree reflects the hierarchy of sub-classes in the Strings class. The right panel can show either all strings or just the strings belonging to the selected tree node.

Column

Description

Name

The string's name (ID); this column repeats the selected tree node, and can be optionally turned off.

Default Value

The default (English) value of the string.

Value

The string value for the currently selected culture (the column header displays that culture).

Below is the list of options in the Localize Toolbar.

Localization Toolbar

The Localize dialog box contains the following toolbar menu buttons:

Button

Description

Create new translation begins a new localization for a ComponentOne assembly.

Open opens an existing translation for a particular assembly.

Save saves the current translation.

Save as saves the current translation and allows you to select the project in which to save the translation.

Add culture adds a new culture.

Delete culture removes a culture from the translations.

Select culture selects the culture to display and edit.

Options customizes the appearance and behavior of the localization window.

Create New Translation Clicking the Create new translation button begins a new localization for a ComponentOne assembly. A dialog box opens for you to select the ComponentOne assembly to localize. Note: The assembly must be referenced in the currently open solution. Open Clicking the Open button opens an existing translation for a particular assembly. All translations that you create are stored as .resx files and are automatically added to the project that you select while saving the translation. Clicking this item shows a dialog box where a previously saved translation can be selected. When you create a new solution it does not contain any translations, so initially that window would look like this. After you have created and saved a translation, the Available cultures panel shows the list of cultures for which translations were created for the selected assembly. Save Clicking the Save button saves the current translation. The translation is saved in the project shown in the status bar. When the translation is saved, a folder with the name C1LocalizedResources is created in the selected project (if it does not already exist), and the .resx files with translations are saved in that folder and added to the project. For each culture, a separate .resx file is created. These files are visible in the Solution Explorer window. Note: If your translation is only for the invariant culture, the .resx file does not contain a culture suffix. Save As Clicking the Save as button saves the current translation and allows you to select the project in which to save the translation. Add Culture Clicking the Add culture button adds a new culture. You can make translations for several cultures, and dynamically switch between them at run time. For each culture, a separate .resx file is created in the C1LocalizedResources folder. Clicking the Add culture button opens the Select culture dialog box that provides a list of available cultures: Initially the list contains neutral cultures only. To show all cultures, uncheck the Show only neutral cultures checkbox. You can use the English name, Display name, and Code boxes to filter the list of shown cultures. After you have selected a culture, press the OK button to add it to the translations. The newly added culture will appear in the Culture drop-down in the toolbar and will become current in the window. Delete Culture Clicking the Delete culture button removes a culture from the translations. The Select cultures to delete dialog box provides the list of cultures existing in the translations. Selecting a culture and clicking OK removes it from the translations. Select Culture The Culture drop-down allows you to select the culture to display and edit. Options Clicking the Options button allows you to customize the appearance and behavior of the localization window. [] The available localization options include:

Option

Description

Sync tree with grid

When this item is checked, selecting a string in the right panel list also selects that string in the tree on the left. By default this item is unchecked.

Show names in grid

When this item is checked, the Name column is shown in the right-hand panel, otherwise that column is hidden. By default this item is checked.

Show selected group only

When this item is checked, the list of strings on the right contains only the strings from the group currently selected in the tree on the left. By default this item is unchecked.

The status bar displays the project which will contain the localized resources and the name of the ComponentOne assembly which is currently being localized.

Setting the Current Culture

The C1Editor control will use localization files automatically according to the culture selected in the application as long as you haven't moved files to another location or excluded files from the project. By default, the current culture is designated as System.Threading.Thread.CurrentThread.CurrentCulture. If you want to use a culture other than the current culture, you can set the desired culture in your application using the following code: Visual Basic Code

Public Sub New()  
 ' Set desired culture, for example here the French (France) locale.  
 System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("fr-FR")  
 ' This call is required by the Windows Form Designer.  
 InitializeComponent()  
 ' Add any initialization after the InitializeComponent() call.  
 End Sub

C# Code

public Form1()  
 {// Set desired culture, for example here the French (France) locale.  
 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");  
  // This call is required by the Windows Form Designer.  
 InitializeComponent();  
  // Add any initialization after the InitializeComponent() call.  
 }

Switching Resources at Run Time

Once you have created your localized resources, you can also easily switch between resources at run time by using the following code: Visual Basic Code

' This will switch to German locale.  
System.Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("de")

C# Code

// This will switch to German locale.  
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");

Summarize

Hence, to summarize the localization process, the steps are : 1. Open the Localize dialog of C1Editor from Smart tag/Context menu. 2. Click on 'New Culture' button. 3. Select Culture from the list of cultures. 4. Set the custom strings for desired localizable strings. 5. Click on 'Save As' button and save the localized strings. 6. Close Localize dialog. 7. Write the code for changing the culture of the current thread. The C1Editor displays the localized strings when the application is debugged.

MESCIUS inc.

comments powered by Disqus