- Adapting a website to support multiple languages
- What is a multilingual website?
- Practical example: integrating multilingualism into a site
- Step 1: Choosing the project languages
- Step 2: Choice of languages in the analysis
- Adding languages in the analysis
- Shared multilingual information
- Applying changes
- Step 3: Multilingual management of project components
- Checking the new language is taken into account in the page
- Translating menu options
- Translating website controls
- Translating programming text
- Changing the language programmatically
- Language buttons
- Page test
- Further information: Translation tools
- Translating text with translation software
- Translation with WDMSG and WDTRAD
- Other elements to translate: the framework messages
Tutorial - Managing multiple languages in a website
Adapting a website to support multiple languages We will cover the following topics: - What is a multilingual website?
- Creating a multilingual website, step by step.
50 mn What is a multilingual website? A multilingual site is a site that proposes an interface in several languages: English, French, German or any other language. In WEBDEV, the same website can support up to 64 different languages. We will use a project that can be run in English or French, according to the user's choice. Practical example: integrating multilingualism into a site Let's say we have developed a website with a UI in one language (e.g., English) but we need to make some changes so that is supports another language (e.g., French). There's a specific order to these changes. The first step is to indicate that the project supports multiple languages. This step is absolutely essential in order to develop a multilingual website. Let's take a look at the main steps to developing a multilingual WEBDEV website. These steps are as follows: - Choosing the languages supported by the project.
- Choosing the languages supported by the analysis.
- Implementing the languages in the different elements of the project (pages, reports, controls, etc.).
- Implementing the languages in the code.
- Programming the change of language in the website.
To illustrate these steps, we will use the "Full_WEBDEV_Site" project. This project will be translated from English into French. Opening the example project - Go to the WEBDEV home page (Ctrl + <).
- On the home page, click on "Tutorial", then in the "Tutorial - Managing multilingualism" area, click on the "Open exercise project" link.
Step 1: Choosing the project languages First, we will select the project languages. - Open the project description window. To do so, go to the "Project" tab, "Project" group, and select "Description".
- Click the "Languages" tab. Our project will support English and French.
- Click "Add". The window for selecting languages is displayed.
- Click "French". A checkmark is displayed on the right of the language.
- Validate. "French" appears in the list of project languages.
The "Languages" tab also allows you to set the language options for numbers, currencies, dates, etc., in the selected language. Let's see an example: - Click "French".
- Select the "Date" tab.
- The Windows language options are used by default. Select "Use the following parameters": you now have the ability to define the date format as well as the translation used for the days and months.
If you select "Use the settings defined in the language options of the operating system", the settings used to deploy will be those of the server and not the ones defined by the user. - Keep "Use the following parameters".
In the language options, you can set the text direction ("Miscellaneous" tab, "Text direction" option). This allows you to create interfaces with a language written from right to left. Now, let's simply apply changes: - Validate the project description window.
- A message prompts you to synchronize the different project elements. Select "Yes". All the open elements in the editor (pages, reports, etc.) are closed and the additional languages are added to these elements.
Note: Labels existing in the project's base language are automatically copied to the added language(s).
Step 2: Choice of languages in the analysis By default, an analysis is created in a specific language and cannot be translated. However, some information can be written in several languages (notes in the documentation, shared information, etc.). Why translate the data present in the analysis? By default, the controls created from analysis items use the caption specified in the analysis. If a caption has been specified in the shared information of the item, it will be used when creating the control. In a multilingual project, this information must be translated so that new elements are created with all the necessary languages. When you change the language of the project linked to the analysis, this change is not automatically applied to the analysis, since analyses can be shared between multiple projects.
To discover how this works, let's first add the languages in the analysis, then enter the shared information in multiple languages. Adding languages in the analysis To use multiple languages in the "Full_WEBDEV_Site" project: - Display the data model editor: click on in WEBDEV's menu of quick access buttons.
- In the analysis description ("Analysis description" option in the context menu), select the "International" tab.
- The list of languages supported by the analysis is displayed. Since French is not supported, we need to add it:
- Click the "Add" button.
- Select "French".
- Validate the language selection window.
- The new language appears in the list.
To take into account all the languages of the project linked to the current analysis, click "Synchronize with the project". - Validate the description window of the analysis.
Shared multilingual information To enter shared information in several languages, let's look at a simple case: entering the label of the field linked to the "Address" item in the "Customer" data file: - Select the Customer data file.
- Open the description of the items (select "Description of items" in the context menu of the data file).
- Select the "Address" item and open the parameters of the control bound to the selected item (shared information). To do so, click the link at the bottom of the screen. The shared information is displayed in a new window.
- On the "General" tab, in the French caption, enter "Adresse".
- Validate the shared information window.
- Confirm changes in the description window of items.
The shared information of the analysis can be translated: - when creating the analysis.
- at any time via the editor.
- at any time via WDMSG and WDTRAD, tools used to extract, translate and reintegrate the different elements of the project. These two tools will be presented later in this tutorial.
Applying changes To take account of changes made in the analysis, it is necessary to generate the analysis: under the "Analysis" ribbon pane, in the "Analysis" group, click on "Generation". Close the data model editor (click the "X" icon of the analysis in the open document tabs). Step 3: Multilingual management of project components All project elements can become multilingual: pages, reports, etc. We will modify some elements in "PAGE_List_of_products" to present the different methods that can be used.
We are going to see how to modify: - the captions of the controls in PAGE_List_of_products.
- the menu options.
- a message displayed by the WLanguage code.
Open "PAGE_List_of_products" in the editor (double-click its name in the "Project explorer" pane, for example). Confirm the template update if necessary. Checking the new language is taken into account in the page First, check whether PAGE_List_of_products is associated with the different languages defined in the project: - Open the page description ("Description" in the context menu of the page).
- Select the "Language" tab: the two languages selected in the project are displayed.
- Select the "General" tab. Under "Title", we can see that the title specified in English has been automatically copied into the language we added.
By default, when a language is added to a project, all captions are automatically created with the content of the existing language. This avoids having "blanks" while waiting for the translation of the different elements. - Let's translate the page title: replace the text in the English box with "List of products".
- Validate the description window.
Translating menu options As with controls, menu options can be translated via the description window, or directly in the page editor.
In our example, we are going to translate the "List of products" option. - The menu is contained in the template associated with the page. Open the page template:
- Click the menu and open the context menu.
- Select "Open the template".
- The page template appears with a colored frame.
- Select the menu in the page template and press Space.
- The menu becomes editable and a yellow border appears.
- Select the "List of products" option.
- Display the option description window: open the context menu and select "Option description".
- In the description window, enter the "List of products" option.
- Validate.
The options can also be translated directly in the page editor. Let's use this method to translate the "Product form" option: - On the "Display" tab, in the "Options" group, expand "Language displayed" and select the language to display in the editor (French in our case).
- The menu options are displayed in the selected language. If no translation corresponds to the selected language, the menu options are displayed in English.
- Select the "Product form" option.
- Press the Space key on the keyboard: the label is edited.
- Enter the wording in English: "Product form".
- Press Enter to confirm changes.
- Press Esc to exit the edit mode.
- Save the page template ( or Ctrl + S).
- Switch back to French display mode: in the "Display" pane, in the "Options" group, pull down "Language displayed" and select "Français".
- Update the pages that use the page template by clicking the icon in the header of the template. Validate the update window.
- Close the page template displayed in the editor.
Translating website controls Controls can display different types of information to the user: Sometimes, this information must be translated. This data is available in the different tabs of the control description window. To translate the "Edit" link of "PAGE_List_of_products": - Select the "Edit" link.
- Open the control description window (select "Description" in the context menu).
- Type the caption in French: "Modifier".
- Validate.
- Save the page ( or Ctrl + S).
Translating programming text All messages in your program can be translated into multiple languages. Let's see how to translate a programming message: - Open the code editor (press F2 on the PAGE_List_of_products" page).
- Write the following code in the "Global declarations" event:
Global declarations (server)
MyString is string = "List of products"
- To translate this type of message, position the cursor in the "List of products" string and press Ctrl + T. You can also go to the "Code" tab, "Languages" group, expand "Translate strings" and select "Translate messages".
- The multilingual message editing window appears. This window allows you to translate all the messages of your program into all the languages of the project.
- In "French", enter "Liste des produits" and validate.
- The icon appears in the code editor. This icon indicates that the multilingual message exists in multiple languages. You can quickly view the different translations by hovering over the icon.
- Close the code editor.
Changing the language programmatically We have translated different elements in "PAGE_List_of_products". Now let's see how to change the website language. By default, the project is run in the language defined for the project, in the "Languages" tab of the project description ("Description" in the "Project" tab). In a website, there are several methods to select the language to be used. In most cases, a menu option (or "Language" button) is used. You can change the language of the running application by calling Nation in the code associated with the menu option. In our example, the page template already has 2 flags that can be used to switch between languages. Let's use them. It works as follows: click on a flag to see the site in the language corresponding to the flag clicked. For example, clicking on the US flag displays the site in English. To do so, two Button controls have been created in the template (one for each language). Language buttons The language buttons can be found in the template of PAGE_List_of_products. - If necessary, open "PAGE_List_of_products" in the editor (double-click its name in the "Project explorer" pane).
- Click the Button control with the US flag and select "Open template" in the context menu.
- Select this control in the page template. Right-click to open the context menu and select "Code".
- Enter the following code in the server code of the menu option:
Click on BTN_English (LAYOUT_Language) (server)
Nation(nationEnglish)
PageUse(CurrentPage())
Let's take a quick look at this code: - Nation changes the runtime language of the website. The constants passed as parameters specify the language to be used.
- PageUse reloads the page (the current page in our case) to apply the new language.
| It's up to you In the same way, enter the following code in the button with the American flag:
Click on BTN_Français (LAYOUT_Language) (server)
Nation(nationFrench)
PageUse(CurrentPage())
|
We have made all the necessary changes in the page template.: - Close the code window.
- Save the page template ( or Ctrl + S).
- Update the pages that use the page template by clicking the icon in the header of the template. Validate the update window.
- Close the page template displayed in the editor.
Page test We have translated some elements of the application. Now, we will change the language in test mode. To test the language change in PAGE_List_of_products: - Test the page (click in the quick access buttons). The page is displayed in test mode in English.
- Click the French flag at the bottom of the page.
- The elements that have been translated are displayed in French:
- Close the browser.
Further information: Translation tools We have manually translated some elements of the website. However, several translation methods are available in WEBDEV: - direct translation of messages in different editors This is the feature we've just used to translate a few elements of our site. With this solution, you can use a translation tool such as Google Translate (a license may be required), etc.
- translating large amounts of text via an external tool (WDMSG and WDTRAD).
Translating text with translation software The translations are typed in the product interface directly: this is the method that was used until now. However, you can also configure WEBDEV to use a translation software or website: - On the "Home" tab, in the "Environment" group, expand "Options" and select "WEBDEV general options".
- Go the "Translation" tab.
- Specify:
- Whether the regional settings must be automatically enabled according to the language used for the input. In this case, if the language requires a specific character set, it will be automatically selected.
- The translation software or website to be used. You can use WDDIXIO, a translation dictionary included with WDMSG (see next paragraph), a specific translation software or website, or Google Translate.
For more details, see Using Google Translate. - The supported languages.
- Once the translation parameters have been set, you can use the button in the various project element description windows to use the software defined for the translation.
Translation with WDMSG and WDTRAD WDMSG is an optional tool that allows you to: - extract all the project messages (control captions, code message, window titles, etc.) to translate them,
- reintegrate the translated messages.
The messages to translate are extracted: - in a text format that can be configured to be used by most translation tools.
- in HFSQL format.
WDMSG also comes with WDTRAD, a computer-assisted translation tool. WDTRAD makes it easy to enter all the translations of multilingual resources in a project. Contact PC SOFT Sales Department for more details about WDMSG and WDTRAD. Other elements to translate: the framework messages Various pieces of information and messages are located in the WEBDEV framework. For example, the names of the days and months used by the date functions come from the WEBDEV framework. To translate one or more libraries of the framework, you must use WDINT (optional tool provided with WDMSG). This software is used to get a WDM extension file containing all the translations of the libraries. To use this file in your application: - use the LoadError function.
- include the file in the "Languages" tab of the project description. Simply select the desired language and click on the "Miscellaneous" tab.
Contact PC SOFT Sales Department for more details about WDINT.
|
|
|