Language settings

There is no need to rebuild the application for a particular language. When the application is built, all the messages files in all the available languages are included. The default locale can be changed by setting the application property unitime.locale through the Administration > Defaults > Configuration page.


For a particular http session, the locale can be also changed using the locale parameter, e.g., see our online demo in Czech: http://demo.unitime.org/UniTime?locale=cs. Please note that only some portions of the application were made localizable (and have Czech translations) so far.

It is also possible to tell the application to take the language settings from the browser. This is done in the LocaleFilter, when the use-browser-settings parameter is set to true (e.g., by web.xml)

Implementation Details

Most of the UniTime application was written using Apache Struts, however new pages and components (and in future the whole user interface) are written using Google Web Toolkit (GWT). For localization of GWT parts we use its i18n capabilities.

In short, all text messages are put into a Messages interface (e.g., see StudentSectioningMessages) which is then used by calling these methods on a class created calling GWT.create(message interface), e.g., see this widget. Note that this only works in the client code (the code that gets compiled into JavaScript), however, for the server side we have created a very similar approach so that the created Messages interfaces can be reused as we move more towards GWT in the future. We use this technique for both server side of the GWT-based pages and components as well as for the old Struts-based pages and JSPs. For server-side Java code (e.g., Struts forms and actions), the only difference is that the Messages class is instantiated using Localization class (e.g., see here). In Java Server Pages (JSP) files, we have two tags <loc:bundle/> and <loc:message/> that are providing the localized strings (e.g., see here, the tags are defined here).

<%@ taglib uri="/WEB-INF/tld/localization.tld" prefix="loc" %> <loc:bundle name="CourseMessages"> <%-- translated message, using loc:message, e.g., titleRemoveRoomPreferences=Remove Room Preferences --> <loc:message name="titleRemoveRoomPreference"/> <%-- translated message with one argument, e.g., labelConfiguration=Configuration {0}) -->   <loc:message name="labelConfiguration"><bean:write property='configName'/></loc:message> <%-- translated message, using MSG property --> <%=MSG.confirmRoomSizeDifferentFromCapacity()%> <%-- additional message bundle --> <loc:bundle name="ConstantsMessages" id="CONST"> <loc:messsage name="monday" id="CONST"/> <%=MSG.sunday()%> </loc:bundle> </loc:bundle>
An example of using localization tags in a JSP file

protected final static CourseMessages MSG = Localization.create(CourseMessages.class); ... // Throw a localized exception if the user is not logged in if (!Web.isLoggedIn(request.getSession())) throw new Exception(MSG.exceptionAccessDenied()); // Localized message MSG.listInstructors(department.getDeptCode(), department.getName())
An example of using localization in a Java file

public static final StudentSectioningMessages MESSAGES = GWT.create(StudentSectioningMessages.class); // Localized button // buttonRequests=<u>R</u>equests iRequests = new Button(MESSAGES.buttonRequests()); // Localized message with multiple arguments // backToBackDistance=Distance to travel from {0} is approx. {1} minutes. MESSAGES.backToBackDistance(clazz.getBackToBackRoom(), clazz.getBackToBackDistance()
An example of using localization in a GWT client code

Here is an example of a change localizing a particular page. The default messages are in English, the language-dependent messages are in a property file with the same name (plus identification of the language using two character iso language code), e.g., see Czech translation of CourseMessages

Translation Files

Struts localization files are available in org.unitime.localization.messages package, GWT localization files in org.unitime.timetable.gwt.resources package.

Also, please take a look at classes ExportMessages and ImportMessages that can be used to convert existing messages to a CSV file and back -- the file can be easily edited in Excel (or Google Docs) -- it has three columns: message name, English (default) variant and localized variant. One of the first steps could be translating these course messages to your language and trying to plug them in.

Course Messages Localization Example

Example of the localization files in Google Docs.

Note that the language has to be added in the UniTime.gwt.xml (as a supported language, extending locale property) for the GWT compiler to create the appropriate language mutation.

Back to Timetabling Documentation.©2012 UniTime LLCContent available under GNU Free Documentation License 1.3.