|
- In this lesson you will learn the following concepts
- What is a multilingual site?
- Choosing the project languages
- Internationalizing the project elements
- Internationalizing an image
- Internationalizing the menu
- Internationalizing controls
- Internationalizing messages in the code
- The translation tools
- Entering the translations directly
- Translation with WDMSG and WDTRAD
- Other elements to translate: the framework messages
- Changing the language programmatically
- Adding a menu option
- Programming
- Project test
Lesson 5.5. Managing multiple languages In this lesson you will learn the following concepts - What is a multilingual site?
- Creating a multilingual site, step by step.
What is a multilingual site? A multilingual site is a website with a user interface in multiple languages: English, French, German or any other language. In WEBDEV, the same site 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. These are the steps to make a site multilingual: - Choosing the project languages.
- Internationalizing the project elements (pages, reports, controls, etc.).
- Internationalizing messages in the code.
- Programming the change of language in the site.
We are going to apply these different steps to the "Full_WEBDEV_Site" project. This project, available in English, will be translated into French. - Open the project you worked on in the previous lesson.
- Go to the WEBDEV home page (Ctrl + <).
- On the home page, click "Tutorial", then in "Parts 3 to 6", double-click "Full WEBDEV Site (Exercise)".
- A dialogue box prompts you to open the project you worked on in the previous lesson. You can open the local copy or the original project. Select "Open the local copy".
| | |  | Answers | A completed project is available. This project contains the results of the different operations performed in this lesson. To open the completed project, go to the home page and click "Tutorial", then in "Parts 3 to 6", double-click "Full WEBDEV Site (Answers)". |
Choosing the project languages - First, we will select the project languages.
- Open the project description: on the "Project" tab, in the "Project" group, click "Description".
- Click the "Languages" tab. Our project will support English and French.
- Click the "Add" button. The language selection window appears.
- 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.
- Specific language options are used by default: you can also define the date format as well as the translation of 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".
| | |  | Note | 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. |
- Validate. A message prompts you to synchronize the different project elements. Answer "Yes". All the project elements open in the editor (pages, reports, etc.) are closed and the new languages are added to these elements.
| | |  | Note | UI errors may occur. We will ignore them for now. We will see how to handle these errors later in this tutorial. |
Internationalizing the project elements All project elements can be 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 logo used in PAGE_List_of_products.
- 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.
- 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: the page title must be translated.
- Replace the text in the French section with "Liste des produits".
- Validate the window.
Internationalizing an image - To change the logo used in PAGE_List_of_products according to the runtime language:
- Open "PAGE_List_of_products" if necessary.
- The logo is in the template associated with the page. Open the page template:
- Click the logo and open the context menu.
- Select "Open template".
- The page template appears with a colored frame.
- Open the logo description window (double-click the control).
- In the "General" tab, next to the "Image" field, click
. In the menu that appears, select "Multilingual". - The multilingual image management window opens.
- A different image can be used for each language:
- Click
. - In the menu that appears, select "Browse".
This feature is very useful if you use images that contain text. In our case, we use the same image. - Validate the multilingual editing window.
- Close the control description window.
- As we are in the page template, we will translate the "List of products" menu option.
Internationalizing the menu 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.
- 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.
- Open the option description window: open the context menu and select "Option description".
- In the description window, type the option in French: "Liste des produits".
- Validate.
The options can also be translated directly in the page editor. - To translate the "Add a product" 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 "Add a product" option.
- Press the Space key: the text becomes editable.
- Type the caption in French: "Ajouter un produit".
- Press Enter to confirm changes.
- Press Esc to exit the edit mode.
- Save the page template (
or Ctrl + S). - Change the display mode back to English: on the "Display" tab, in the "Options" group, expand "Language displayed" and select "English".
- 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.
Internationalizing 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 "Modify" link of "PAGE_List_of_products":
- Select the "Modify" 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).
Internationalizing messages in the code All the messages of 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:
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.
We have translated some elements of the application manually. However, several translation methods are available in WEBDEV: - translating the messages directly in the editors: this is the method we previously used to translate some elements of our site. With this solution, you can use a translation tool such as Google Translate (a license may be required).
- translating the messages via an external tool (WDMSG and WDTRAD).
Entering the translations directly Translations can be typed directly in the interface: this is the method we have used so far. 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 "General options of WEBDEV".
- 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 site to be used. You can use WDDIXIO, a translation dictionary included with WDMSG (see next paragraph), a specific translation software or site, or Google Translate.
For more details, see Translation with Google Translate. - The supported languages.
- Once the translation settings are defined, you can use the
button in the different description windows of the project elements: this button allows you to use the translation software.
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 management 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. Changing the language programmatically 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 site, the language can be chosen via a menu option. You can change the language of the running application by calling Nation in the code associated with the menu option. Adding a menu option - To add a menu option:
- If necessary, open "PAGE_List_of_products" in the editor (double-click its name in the "Project explorer" pane).
- Click the menu, then right-click to open the context menu and select "Open template".
- In the page template, select the menu. Right-click to open the context menu and select "Edit menu".
- The menu becomes editable and a yellow border appears.
- Click "Pages".
- Press the Space key: the text becomes editable.
- Enter "Languages" and validate.
- Select the "LANGUAGES"' option you have just created.
- Right-click to open the context menu and select the "Insert a sub-menu" option.
- Select the menu option that was just created.
- Press Space to edit the text.
- Enter the text of the first sub-option: "Français". Press Enter to validate.
- Select the first sub-option again.
- Press Enter: a second sub-option is created.
- Press Space and type the text of the second sub-option: "English".
- We will translate the last menu option in the page template:
- Select "CONTACT".
- Open the option description window.
- Type "Contactez-nous" in French.
We will write the WLanguage code to change the language. Programming - To enter the language management code:
- Select "LANGUAGES .. ENGLISH" in the page template displayed in the editor.
- Right-click to open the context menu. Select "Code".
- Enter the following code in the server code of the menu option:
Nation(nationEnglish) PageUse(CurrentPage())
- Close the code window.
- Select "LANGUAGES .. FRANÇAIS" in the page template displayed in the editor.
- Right-click to open the context menu. Select "Code".
- Write the following code:
Nation(nationFrench) PageUse(CurrentPage())
In this code:- Nation changes the runtime language of the site. 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.
- Close the code window.
- Press Esc to exit the edit mode.
- 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.
Project test We have translated some elements of the application. Now, we will change the language in test mode. - To test the site:
- Test the project (click
in the quick access buttons). The page is displayed in test mode in English. - Select "LANGUAGES .. FRANÇAIS".
- The elements that have been translated are displayed in French:
- Close the browser.
|
|
|
|
|
|
|