/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { List } from "../../types/java/util/List"; import type { Locale } from "../../types/java/util/Locale"; import type { String } from "../../types/java/lang/String"; /** * Locale utility interface. * *

* Note! Sitevision supports a few Locales that uses 3 char ISO-639 language codes. These are not * automatically handled by Java. Sitevision also supports a few 2 char language codes that isn't natively supported by Java in most * regions of the world. This interface handles all Locales supported/installed by Java and all "custom" Locales that Sitevision has added. * Here are some examples for such Locales: *

* *

* Information about Supported Locales in JDK 8. *

* *

* An instance of the Sitevision class implementing this interface can be obtained via {@link senselogic.sitevision.api.Utils#getLocaleUtil()}. * See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface. *

* @author Magnus Lövgren * @since Sitevision 3.6 * @see senselogic.sitevision.api.context.PortletContextUtil#getCurrentLocale() * @see senselogic.sitevision.api.node.NodeResolverUtil#getLocaleResolver() */ export interface LocaleUtil { /** * Gets an immutable list of all available Locales (installed Java Locales and custom ones added by Sitevision). * *

* Note! The returned List is immutable/unmodifiable, i.e. you must create a copy if * you want to modify it (e.g. sort). *

*

* Below is an example of how to display some info about all locales via server-side Javascript: *

*
    (function() {
   *        var localeUtil = require('LocaleUtil'),
   *           locales = localeUtil.getAvailableLocales(),
   *           count = locales.size(),
   *           currentLocale = require('PortletContextUtil').getCurrentLocale(),
   *           locale, i;
   *
   *        out.println('<table>');
   *        out.println('<tr>');
   *        out.println('   <th>Language</th>');
   *        out.println('   <th>Country</th>');
   *        out.println('   <th>Language Tag</th>');
   *        out.println('   <th>Native language name</th>');
   *        out.println('   <th>Localized language name</th>');
   *        out.println('   <th>Directionality</th>');
   *        out.println('</tr>');
   *        for (i = 0; i < count; i++) {
   *           locale = locales.get(i);
   *           out.println('<tr>');
   *           out.println('   <td>' + localeUtil.getNormalizedLanguage(locale) + '</td>');
   *           out.println('   <td>' + locale.getCountry() + '</td>');
   *           out.println('   <td>' + localeUtil.getLanguageTag(locale) + '</td>');
   *           out.println('   <td>' + localeUtil.getNativeLanguageName(locale) + '</td>');
   *           out.println('   <td>' + localeUtil.getLocalizedLanguageName(locale, currentLocale) + '</td>');
   *           out.println('   <td>' + (localeUtil.isRTL(locale) ? 'RTL' : 'LTR') + '</td>');
   *           out.println('</tr>');
   *        }
   *        out.println('</table>');
   *     }());
* @return a immutable/unmodifiable list of all available Locales (i.e. all Locales installed by Java and all custom Locales added by Sitevision) * @since Sitevision 4.1 */ getAvailableLocales(): List; /** * Gets the native language name for a specified Locale. * *

* Some examples: *

* * @param aLocale the locale * @return the native language name for aLocale, or null if aLocale is null */ getNativeLanguageName(aLocale: Locale): string; /** * Gets the localized language name for a specified Locale. * *

* Some examples: *

* * @param aLocale the locale to get the language name for * @param aDisplayLocale the locale that should be used when displaying the language name of aLocale * @return the localized language name for aLocale, or null if aLocale is null */ getLocalizedLanguageName(aLocale: Locale, aDisplayLocale: Locale): string; /** * Gets the native language name for a Locale that is resolved via a specified locale string. * *

* This method can be seen as a convenience method that combines the {@link #getLocaleByString(String)} method and the * {@link #getNativeLanguageName(java.util.Locale)} method to resolve a Locale and get the native language name. * But this is not strictly true. This method will handle all all well-formed locale strings that starts with a valid * language code used by a supported locale (even though the "full" locale string might actually refer to a non-supported locale). *

*

* Some examples of this forgiving/lenient behaviour: *

* * @param aLocaleString a language tag ("en-US") or string that contains language only ("en") or language and country ("en_US"), typically what you will get as result of Locale.toString() * @return the native language name for the aLocale that matches aLocaleString, or null if aLocaleString is null, whitespace only or doesn't match a supported Locale */ getNativeLanguageNameByString(aLocaleString: String | string): string; /** * Gets the localized language name for a Locale that is resolved via a specified locale string. * *

* This is a convenience method that combines the {@link #getLocaleByString(String)} method and the * {@link #getLocalizedLanguageName(java.util.Locale, java.util.Locale)} * method to resolve a Locale and get the localized language name. *

* @param aLocaleString a string that contains language ("en") or language and country ("en_US"), typically what you will get as result of Locale.toString() * @param aDisplayLocale the locale that should be used when displaying the language name of the Locale resolved by aLocaleString * @return the localized language name for the aLocale that matches aLocaleString, or null if aLocaleString is null, whitespace only or doesn't match a supported Locale */ getLocalizedLanguageNameByString( aLocaleString: String | string, aDisplayLocale: Locale ): string; /** * Returns the Locale for a language tag or a String that contains language or language + country ("en-US" or "en" or "en_US"). * *

* A toString() on a english american locale returns the String "en_US", but to create a locale * from that string you can NOT just create it by doing: new Locale("en_US"). You must split language (en) * and country (US) since the proper way of creating the Locale is: new Locale("en", "US"). *

* *

* Some examples of accepted locale strings: *

* * *

* Note! This method only handles supported Locale's, i.e. Locales available via {@link #getAvailableLocales()}. *

* @param aLocaleString a language tag or the toString() value of a Locale (i.e. a String with a lowercased language - or a lowercased language and uppercased country, separated with underscore). * @return a Locale matching aLocaleString, or null if aLocaleString is null, whitespace only or doesn't match a supported Locale */ getLocaleByString(aLocaleString: String | string): Locale; /** * Returns the IETF BCP 47 language tag value for a Locale. * *

* Language tags are used to indicate the language of texts or other items in HTML and XML documents. The language tag * syntax is defined by the IETF BCP 47 * and exemplified by W3C internationalization in * Language tags in HTML and XML. *

* *

* This method supports both the Java default locales and the custom-defined ones in Sitevision (such as Northern Sami). * It produces a well-formatted BCP 47 value for a specified Locale but the language and region are not verified against the * IANA language subtag registry. *

*

* Some output examples: *

* * @param aLocale a locale * @return the aLocale formatted according to BCP 47, or null if aLocale is null */ getLanguageTag(aLocale: Locale): string; /** * Returns the normalized language for a specified Locale. * *

* Java uses old ISO language codes for for language codes that have changed. For instance: the legacy ISO language code for Yiddish * is "ji", but that was changed to "yi" 1989. This method compensates for Javas legacy considerations and returns the * new ISO language codes instead. *

* @param aLocale a locale * @return the normalized language for the locale, or null if the locale is null * @since Sitevision 4.5.1 */ getNormalizedLanguage(aLocale: Locale): string; /** * Checks if a locale has writing direction Right-To-Left (RTL). * *

* Most languages have a clear writing direction, typically Left-To-Right (LTR). Though, some languages has mixed writing directions * (e.g. text is RTL but numbers are LTR) and some languages is written with different symbols (e.g. Latin, Arabic) in different regions. * This method will return true for such complex/mixed languages if the official writing direction is RTL or if RTL is used by the majority * of the native language writers. *

*

* This method supports the Java default locales and the custom-defined ones in Sitevision (such as Northern Sami). * It also supports locales that aren't officially supported by Sitevision (i.e. not present in {@link #getAvailableLocales()}). * The direction of the first char in the locales native name (as of {@link #getNativeLanguageName(Locale)}) * is used to determine if the locale is LTR or RTL for such (unofficial) locales. *

* @param aLocale a locale * @return true if aLocale has Right-To-Left (RTL) writing direction, false otherwise (i.e. false indicates LTR) * @since Sitevision 4.3 */ isRTL(aLocale: Locale): boolean; /** *

* Gets a Locale with language and country for a (typically language-only) Locale. *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Replacement of language-only locales
Locale/languageReplacement
Swedish (sv)Sweden (sv-SE)
Norwegian (no)Norway (no-NO)
Danish (da)Denmark (da-DK)
Finnish (fi)Finland (fi-FI)
Icelandic (is)Iceland (is-IS)
Belarusian (be)Belarus (be-BY)
Bulgarian (bg)Bulgaria (bg-BG)
Catalan (ca)Spain (ca-ES)
Czech (cs)Czech Republic (cs-CZ)
Estonian (et)Estonia (et-EE)
Irish (ga)Ireland (ga-IE)
Hebrew (he) and (iw)Israel (he-IL)
Hindi (hi)India (hi-IN)
Croatian (hr)Croatia (hr-HR)
Indonesian (id) and (in)Indonesia (id-ID)
Italian (it)Italy (it-IT)
Japanese (ja)Japan (ja-JP)
Lithuanian (lt)Lithuania (lt-LT)
Latvian (lv)Latvia (lv-LV)
Malay (ms)Malaysia (ms-MY)
Maltese (mt)Malta (mt-MT)
Polish (pl)Poland (pl-PL)
Romanian (ro)Romania (ro-RO)
Slovak (sk)Slovakia (sk-SK)
Slovenian (sl)Slovenia (sl-SI)
Albanian (sq)Albania (sq-AL)
Thai (th)Thailand (th-TH)
Turkish (tr)Turkey (tr-TR)
Ukranian (uk)Ukraine (uk-UA)
Vietnamese (vi)Vietnam (vi-VN)
*

* Important language-only note! There are many language-only locales that can not be resolved * (i.e. the language is officially spoken in multiple countries). * This method will return null for such locales. For example: *

* * @param aLocale a Locale, typically a language-only Locale * @return the corresponding locale with country, or null if no corresponding locale could be found * @since Sitevision 6.1 */ resolveCountryLocale(aLocale: Locale): Locale; } declare namespace LocaleUtil {} declare var localeUtil: LocaleUtil; export default localeUtil;