Class L10NManager

java.lang.Object
com.codename1.l10n.L10NManager

public class L10NManager extends Object

The localization manager allows adapting values for display in different locales thru parsing and formatting capabilities (similar to JavaSE's DateFormat/NumberFormat). It also includes language/locale/currency related API's similar to Locale/currency API's from JavaSE.

The sample code below just lists the various capabilities of the API:

Form hi = new Form("L10N", new TableLayout(16, 2));
L10NManager l10n = L10NManager.getInstance();
hi.add("format(double)").add(l10n.format(11.11)).
    add("format(int)").add(l10n.format(33)).
    add("formatCurrency").add(l10n.formatCurrency(53.267)).
    add("formatDateLongStyle").add(l10n.formatDateLongStyle(new Date())).
    add("formatDateShortStyle").add(l10n.formatDateShortStyle(new Date())).
    add("formatDateTime").add(l10n.formatDateTime(new Date())).
    add("formatDateTimeMedium").add(l10n.formatDateTimeMedium(new Date())).
    add("formatDateTimeShort").add(l10n.formatDateTimeShort(new Date())).
    add("getCurrencySymbol").add(l10n.getCurrencySymbol()).
    add("getLanguage").add(l10n.getLanguage()).
    add("getLocale").add(l10n.getLocale()).
    add("isRTLLocale").add("" + l10n.isRTLLocale()).
    add("parseCurrency").add(l10n.formatCurrency(l10n.parseCurrency("33.77$"))).
    add("parseDouble").add(l10n.format(l10n.parseDouble("34.35"))).
    add("parseInt").add(l10n.format(l10n.parseInt("56"))).
    add("parseLong").add("" + l10n.parseLong("4444444"));
hi.show();
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    L10NManager(String language, String locale)
    Instances of this class should be received via the Display class
  • Method Summary

    Modifier and Type
    Method
    Description
    format(double number)
    Format a double number for this locale
    format(double number, int decimalPlaces)
    Formats a number as a String with a fixed number of decimal places
    format(int number)
    Format an integer number for this locale
    formatCurrency(double currency)
    Format a currency value
    Formats a date in a long form e.g.
    Formats a date in a short form e.g.
    Formats a date and a time in a default form e.g.
    Formats a date and a time in a default form e.g.
    Formats a date and a time in a default form e.g.
    Formats the time in a default form e.g.
    Returns the currency symbol for this locale
    Convenience method that invokes Display.getLocalizationManager()
    Returns the current locale language as an ISO 639 two letter code
    Determines the locale (location) as an ISO 3166 country code
    Gets the long month name in the current locale for the given date.
    Gets the short month name in the current locale for the given date.
    boolean
    Indicates whether the language is a right to left language
    double
    Parses the currency value
    double
    parseDouble(String localeFormattedDecimal)
    Parses a double based on locale conventions
    int
    parseInt(String localeFormattedInteger)
    Parses an integer based on locale conventions
    long
    parseLong(String localeFormattedLong)
    Parses a long based on locale conventions
    void
    setLocale(String locale, String language)
    Forces the locale/language

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • L10NManager

      protected L10NManager(String language, String locale)
      Instances of this class should be received via the Display class
  • Method Details

    • getInstance

      public static L10NManager getInstance()

      Convenience method that invokes Display.getLocalizationManager()

      Returns

      the L10NManager instance

    • getLanguage

      public String getLanguage()

      Returns the current locale language as an ISO 639 two letter code

      Returns

      iso language string

    • setLocale

      public void setLocale(String locale, String language)

      Forces the locale/language

      Parameters
      • locale: the new locale

      • language: the language to use

    • format

      public String format(int number)

      Format an integer number for this locale

      Parameters
      • number: the number to format
      Returns

      a string representation of a number

    • format

      public String format(double number)

      Format a double number for this locale

      Parameters
      • number: the number to format
      Returns

      a string representation of a number

    • getShortMonthName

      public String getShortMonthName(Date date)

      Gets the short month name in the current locale for the given date.

      Parameters
      • date: The date.
      Returns

      Short month name. E.g. Jan, Feb, etc..

      Since

      7.0

    • getLongMonthName

      public String getLongMonthName(Date date)

      Gets the long month name in the current locale for the given date.

      Parameters
      • date: The date.
      Returns

      Long month name. E.g. January, February, etc..

      Since

      7.0

    • formatCurrency

      public String formatCurrency(double currency)

      Format a currency value

      Parameters
      • currency: the monetary value
      Returns

      a string representation of a number

    • getCurrencySymbol

      public String getCurrencySymbol()

      Returns the currency symbol for this locale

      Returns

      currency symbol

    • formatDateLongStyle

      public String formatDateLongStyle(Date d)

      Formats a date in a long form e.g. Sunday January 1st 2001

      Parameters
      • d: the date
      Returns

      the long form string

    • formatDateShortStyle

      public String formatDateShortStyle(Date d)

      Formats a date in a short form e.g. 1/1/2011

      Parameters
      • d: the date
      Returns

      the short form string

    • formatDateTime

      public String formatDateTime(Date d)

      Formats a date and a time in a default form e.g. 1/1/2011 10:00AM

      Parameters
      • d: the date
      Returns

      the date and time

    • formatDateTimeMedium

      public String formatDateTimeMedium(Date d)

      Formats a date and a time in a default form e.g. 1/1/2011 10:00AM

      Parameters
      • d: the date
      Returns

      the date and time

    • formatTime

      public String formatTime(Date d)

      Formats the time in a default form e.g. 10:00AM

      Parameters
      • d: the date time object
      Returns

      the time as a String

    • formatDateTimeShort

      public String formatDateTimeShort(Date d)

      Formats a date and a time in a default form e.g. 1/1/2011 10:00AM

      Parameters
      • d: the date
      Returns

      the date and time

    • isRTLLocale

      public boolean isRTLLocale()

      Indicates whether the language is a right to left language

      Returns

      true for bidi/rtl languages

    • getLocale

      public String getLocale()

      Determines the locale (location) as an ISO 3166 country code

      Returns

      the locale

    • format

      public String format(double number, int decimalPlaces)

      Formats a number as a String with a fixed number of decimal places

      Parameters
      • number: the number

      • decimalPlaces: decimals

      Returns

      formatted string

    • parseDouble

      public double parseDouble(String localeFormattedDecimal)

      Parses a double based on locale conventions

      Parameters
      • localeFormattedDecimal: the locale formatted number
      Returns

      the parsed double

    • parseLong

      public long parseLong(String localeFormattedLong)

      Parses a long based on locale conventions

      Parameters
      • localeFormattedLong: the number
      Returns

      a long

    • parseInt

      public int parseInt(String localeFormattedInteger)

      Parses an integer based on locale conventions

      Parameters
      • localeFormattedInteger: the number
      Returns

      a parsed number

    • parseCurrency

      public double parseCurrency(String amount)

      Parses the currency value

      Parameters
      • amount: the amount
      Returns

      a numeric value for the currency