Specifying an ILocale object for a language type

To run a block of Gosu code with a specified language, you must use a language object of type GWLangauge for the first parameter to runAsCurrentLangauge. You can specify the object in a number of ways:

  • Use the gw.api.util.LocaleUtil.toLanguage method to provide a GWLanguage object that corresponds to a Gosu typecode in the LanguageType typelist. You can specify the parameter to this method by using typecode syntax, such as LanguageType.TC_EN_US. The typecode has to be defined in the LanguageType typelist.
  • You can specify a typecode of the correct type directly, without using the toLanguage method. For example, for U.S. English, use gw.i18n.ILocale.LANGUAGE_EN_US. This syntax requires that the language typecode en_US be defined the LanguageType typelist.
  • You can specify the first parameter by using a method on LocaleUtil that can get the current or default language. For example, getCurrentLanguage and getDefaultLanguage.

You can add a typecode to the LanguageType typelist. If you add a new typecode to this typelist, you must restart Guidewire Studio™ to be able to use it in gw.i18n.ILocale.

Important: During development, if you make a change that requires that a language typecode in the LanguageType typelist not be in effect when you restart, you must retire that language typecode. Do not delete the language typecode, or you might have database errors when you restart the application.

The following example Gosu code sets U.S. English as the language for a display string, overriding the current language:

uses gw.api.util.LocaleUtil

 // Run a block of Gosu code that prints the display string in U.S. English
LocaleUtil.runAsCurrentLanguage(
    LocaleUtil.toLanguage(LanguageType.TC_EN_US),
    \-> {print(displaykey.Activity)})

See also