Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Setting/Getting Available Languages

The portal includes a portal service and API for obtaining the available portal languages:
source languages, target languages and personalization languages.
The portal’s Locale service controls the available languages. The available languages are determined
by the service’s configuration.
The service provides methods for obtaining the available languages. Obtain a reference to the service as follows:

ILocaleListService localeService = (ILocaleListService)PortalRuntime .getRuntimeResources().getService(ILocaleListService.KEY);


The Locale service is part of the wizard framework. Use the sharing reference:
com.sap.portal.admin.wizardframework and the JAR file
com.sap.portal.admin.wizardframework_api.jar.

Getting the Technical Names for Personalization Languages

The following gets the list of technical names of the languages that an anonymous user can select for a portal session:

private List getTechLanguagesName(IPortalComponentRequest request) {

// Get Locale service
ILocaleListService localeService = (ILocaleListService)PortalRuntime.getRuntimeResources().getService(ILocaleListService.KEY);

// Get current locale
Locale globalLocale = request.getLocale();

// Get technical names of locales
List allLocales = localeService.getListOfPersLocalesOrderedByDisplayName(globalLocale);
List allLocaleTechNames = localeService.getTechnicalNamesForLocales(allLocales);

returnallLocaleTechNames;
}


Getting the Display Names for Personalization Languages

The following gets the list of display names of the languages that an anonymous user can select for a portal session:

private List getDisplayLanguagesName(IPortalComponentRequest request) {
// Get Locale service ILocaleListService localeService = (ILocaleListService)PortalRuntime.getRuntimeResources().getService(ILocaleListService.KEY);

// Get current locale
Locale globalLocale = request.getLocale();

// Get display names of locales
List allLocales = localeService.getListOfPersLocalesOrderedByDisplayName(globalLocale); List allLocaleDisplayNames = localeService.getDisplayNamesForLocales(allLocales, globalLocale);

returnallLocaleDisplayNames;
}


Setting the Language for Anonymous Users

You can create a dropdown list to enable an anonymous user to select a language for the current session.
Create the list by getting the technical names and display names of the languages, as shown above.
Assuming that your user interface passes the technical name of the selected language in the parameter lang, the following code sets the language:

ILocaleListService localeService = (ILocaleListService)PortalRuntime.getRuntimeResources().getService(ILocaleListService.KEY);

// Get the technical name of the selected language
newLocale = localeService.getLocaleForTechnicalName(request.getParameter("lang"));

// Set the language
HttpSession session = request.getServletRequest().getSession(); session.setAttribute("sessionLocale", newLocale);


This only sets the language for anonymous users. For authenticated users, the language is set by the portal personalization.
5 Comments