Class LocaleParser

java.lang.Object
ch.tocco.nice2.textresources.api.locale.LocaleParser

public class LocaleParser extends Object
Parses a Locale string into Locale objects. Note: This class does not validate any ISO codes.
  • Constructor Details

    • LocaleParser

      public LocaleParser()
      Creates a non-strict parser.
    • LocaleParser

      public LocaleParser(boolean strict)
  • Method Details

    • setToStrictMode

      public void setToStrictMode()
      Only standard rules allowed, but still no ISO code validation.
       It is a shortcut for:
         setLanguageCountrySeparators("_")
         setCheckCase(true)
    • parseLocaleString

      @Nullable public @Nullable Locale parseLocaleString(@Nullable @Nullable String localeString) throws IllegalArgumentException
      Parameters:
      localeString - Trim it.
      Returns:
      A locale, or null when input is empty or null.
      Throws:
      IllegalArgumentException - On invalid syntax, see setToStrictMode().
    • parseLocaleStringNoEx

      @Nullable public @Nullable Locale parseLocaleStringNoEx(String localeString)
      Calls parseLocaleString() and swallows an IllegalArgumentException, returning null instead.
      Parameters:
      localeString - (trim it. may be null.)
      Returns:
      a locale, or null on failure or invalid syntax.
    • parseLocalesString

      public Set<Locale> parseLocalesString(String localesString) throws IllegalArgumentException
      Works on a comma-separated list, for example "da, en-GB"
      Parameters:
      localesString - (may be null)
      Returns:
      Ordered Set, may be empty
      Throws:
      IllegalArgumentException - on first parse or validation error