Websydian v6.1 online documentationOnline documentation - WebsydianExpress v3.0

Using ChangeLanguageForSession

Overview

The ChangeLanguageForSession business process is delivered as part of the WebsydianExpress runtime.

It offers a function that presents a list of languages to the user. When the user selects a language, the language of the session is changed.

The business process can be implemented as it is in your own site or you can create your own version in Plex by inheriting from the delivered business process.

Implementing the business process

This section will describe how you can implement the delivered business process without making any changes.

This will make it possible for the user to change the language of the session, but the selection is not saved anywhere.

This means that it is suitable for sites, where the sessions normally are anonymous (no user has logged in).

The functionality can be implemented in two different ways:

 

1. Defining the business process as a part of the site structure.

If you define the business process as part of the site structure, you can control this by using the normal role-based authorization control of WebsydianExpress.

This means that you can ensure e.g. that the selection of languages only are shown for anonymous sessions - or for users having specific roles.

It also means that the normal way to access this business process will be through pressing a menu item or by the initial load of a frame in a frameset.

2. Adding the ShowLanguages page to an existing page as a dynamic child page.

By adding the page as a dynamic child, you do not have to change the site structure to get this function shown. This also means that there is no way to use roles to control whether the ShowLanguages page should be shown - it will always follow the page the dynamic child marker is placed on.

The ShowLanguages page will follow the presentation of the page it is included on. This means that if the template of the parent page is specified with a suffix, you also have to create a template with this suffix for the ShowLanguages page.

Implementing the business process as part of the site structure

Specify the business process in the site

The first step you have to perform is to define the process using the administration interface.

Use the menu item Content loaders→Business Processes to create the business process in the site.

Press "Insert" to go to the create page.

Specify: WSCHLNG as the Process ID and keep the "Create default presentation" checkbox checked.

 

The next step is to add the process to the site structure.

In the site structure, find the menu or frameset you want to add the business process to.

Select the site element and press "Add".

Keep the selections of "Create new site element" and "Business Process" and press "Next".

Select the presentation that was created for the business process (has the same name as the process).

Enter the information about where the business process should be placed under the menu or the frameset and press "Next".

Add roles to the site element and press "Finish" to create the site element and add it to the site structure.

Change the template

As the delivered template might not fit your purpose, you might want to change the content of the template so that it fits your design.

In the header frame of the demosite, you can see one example of how you can show that languages as a list of national flags.

Please note that for this to work, you must specify an image for the language on the language maintenance page.

You can find a large number of flag icons in the delivered /res/flags folder. The template for the ShowLanguages page is named WSCHLNGP.

Adding the ShowLanguages page as a dynamic child

A page that can be dynamically inserted on a parent page has been wrapped around the page showing the languages.

Doing this means that if you have an existing page, e.g. a top page, that is always shown in the site, you can add the list of languages the user can select as a child to this page. This means that the language selection will be available no matter where the user is in the site.

The benefit of this, is that you do not have to define the business process and add it to the site structure, the language selection will be available everywhere the parent page is shown.

The page showing the languages is added to the parent page in the following way:

1. Add call to the dynamic child

Open the page, where you want to include the language selector.

In the template of the parent page, add:

/(CHILDFNC-WSCHLNDC)

Add this replacement marker at the position where you want to place the language selector.

You can see an example of using the dynamic child in the top frame of the delivered demosite. The name of the template of the parent page is WSCOM_topwithlanguage - the name of the template showing the ShowLanguages page is WSCHLNGP_topwithlanguage.

2. Change the template of the ShowLanguages page

The template of the ShowLanguages page must in most cases be changed to fit the page it is going to be part of. You can also select several different ways to present the language selection - e.g. the flags shown in the demosite example or a drop down box showing the languages defined for the site. You can decide how to show this by changing the template WSCHLNGP.

Customizing ChangeLanguageForSession

The implementation of the business process is created in the WSYAPI model. You can find the implementation of the process at: _BusinessProcesses.ChangeLanguageForSession.

The following will be describe how you can extend the process so that it not just changes the session language - but also sets the language as the user language if a user is logged into the session.

1. Create a new business process

Source Object Verb Target Object
ChangeLanguageForSessionAndUser is a FNC _BusinessProcesses.ChangeLanguageForSession

2. Add a call to User.SetLanguageCode

Open the action diagram for ChangeLanguageForSessionAndUser.ShowLanguages.Select.

 

Add the following to the Post Point: Success from SetLanguageCode:

 

if APIServer.GetBasicSessionData/Output<APIFields.UserSurrogate> != <APIFields.UserSurrogate.*Zero>

Call APIServer.User.SetLanguageCode

Map with:

    APIServer.GetBasicSessionData/Output<APIFields.UserSurrogate>

    WebInput<APIFields.Language Code>

This will mean that the user will get the selected language as his default language. In this way, he will not have to select the language each time he uses the site.

You can enter any functionality you want in this edit point. Another example could be that you write a cookie with the selected language to the browser. By checking for this cookie in the callback point SessionAfterCreate, you would be able to set the last selected language from the browser to new sessions.

3. Generate and build the business process

Generate and build ChangeLanguageForSessionAndUser and all the scoped objects.

Run the template generator for ChangeLanguageForSessionAndUser.ShowLanguages

Deploy the template and program objects as you do for any other business process.

4. Add the process to your site

Just as for the original ChangeLanguageForSession, the custom business process can be deployed by adding the business process to the site or by adding the ShowLanguages page as a dynamic child to a parent page in the application. You must of course refer to the implementation names of the new functions when defining the business process or when inserting the /(CHILDFNC-...) marker in the parent page.