Search in sources :

Example 1 with L10NManager

use of com.codename1.l10n.L10NManager in project CodenameOne by codenameone.

the class AndroidImplementation method getLocalizationManager.

/**
 * @inheritDoc
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {

            public double parseDouble(String localeFormattedDecimal) {
                try {
                    return NumberFormat.getNumberInstance().parse(localeFormattedDecimal).doubleValue();
                } catch (ParseException err) {
                    return Double.parseDouble(localeFormattedDecimal);
                }
            }

            public String format(int number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String format(double number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String formatCurrency(double currency) {
                return NumberFormat.getCurrencyInstance().format(currency);
            }

            public String formatDateLongStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.LONG).format(d);
            }

            public String formatDateShortStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.SHORT).format(d);
            }

            public String formatDateTime(Date d) {
                return DateFormat.getDateTimeInstance().format(d);
            }

            public String formatDateTimeMedium(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
                return dd.format(d);
            }

            public String formatDateTimeShort(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                return dd.format(d);
            }

            public String getCurrencySymbol() {
                return NumberFormat.getInstance().getCurrency().getSymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale l = new Locale(language, locale);
                Locale.setDefault(l);
            }
        };
    }
    return l10n;
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Paint(android.graphics.Paint) Date(java.util.Date) L10NManager(com.codename1.l10n.L10NManager)

Example 2 with L10NManager

use of com.codename1.l10n.L10NManager in project CodenameOne by codenameone.

the class IOSImplementation method getLocalizationManager.

/**
 * @inheritDoc
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {

            public String format(int number) {
                return nativeInstance.formatInt(number);
            }

            public String format(double number) {
                return nativeInstance.formatDouble(number);
            }

            public String formatCurrency(double currency) {
                return nativeInstance.formatCurrency(currency);
            }

            public String formatDateLongStyle(Date d) {
                return nativeInstance.formatDate(d.getTime());
            }

            public String formatDateShortStyle(Date d) {
                return nativeInstance.formatDateShort(d.getTime());
            }

            public String formatDateTime(Date d) {
                return nativeInstance.formatDateTime(d.getTime());
            }

            public double parseDouble(String localeFormattedDecimal) {
                return nativeInstance.parseDouble(localeFormattedDecimal);
            }

            public String formatDateTimeMedium(Date d) {
                return nativeInstance.formatDateTimeMedium(d.getTime());
            }

            public String formatDateTimeShort(Date d) {
                return nativeInstance.formatDateTimeShort(d.getTime());
            }

            public String getCurrencySymbol() {
                return nativeInstance.getCurrencySymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale l = new Locale(language, locale);
                Locale.setDefault(l);
                nativeInstance.setLocale(language + "_" + locale);
            }
        };
    }
    return l10n;
}
Also used : Locale(java.util.Locale) Date(java.util.Date) L10NManager(com.codename1.l10n.L10NManager)

Example 3 with L10NManager

use of com.codename1.l10n.L10NManager in project CodenameOne by codenameone.

the class JavaSEPort method getLocalizationManager.

/**
 * @inheritDoc
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {

            public double parseDouble(String localeFormattedDecimal) {
                try {
                    return NumberFormat.getNumberInstance().parse(localeFormattedDecimal).doubleValue();
                } catch (ParseException err) {
                    return Double.parseDouble(localeFormattedDecimal);
                }
            }

            public String format(int number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String format(double number) {
                return NumberFormat.getNumberInstance().format(number);
            }

            public String formatCurrency(double currency) {
                return NumberFormat.getCurrencyInstance().format(currency);
            }

            public String formatDateLongStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.LONG).format(d);
            }

            public String formatDateShortStyle(Date d) {
                return DateFormat.getDateInstance(DateFormat.SHORT).format(d);
            }

            public String formatDateTime(Date d) {
                return DateFormat.getDateTimeInstance().format(d);
            }

            public String formatDateTimeMedium(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
                return dd.format(d);
            }

            public String formatDateTimeShort(Date d) {
                DateFormat dd = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                return dd.format(d);
            }

            public String getCurrencySymbol() {
                return NumberFormat.getInstance().getCurrency().getSymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale l = new Locale(language, locale);
                Locale.setDefault(l);
            }
        };
    }
    return l10n;
}
Also used : Locale(java.util.Locale) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Point(java.awt.Point) L10NManager(com.codename1.l10n.L10NManager)

Example 4 with L10NManager

use of com.codename1.l10n.L10NManager in project CodenameOne by codenameone.

the class GameCanvasImplementation method getLocalizationManager.

/**
 * @inheritDoc
 */
public L10NManager getLocalizationManager() {
    if (lm == null) {
        String l = System.getProperty("microedition.locale");
        String lang = "en";
        String country = "US";
        if (l != null && l.length() >= 5) {
            lang = l.substring(0, 2);
            country = l.substring(3, 5);
        }
        lm = new L10NManager(lang, country) {

            public String format(int number) {
                return super.format(number);
            }

            public String format(double number) {
                return super.format(number);
            }

            public String formatCurrency(double currency) {
                return super.formatCurrency(currency);
            }

            public String formatDateLongStyle(Date d) {
                return super.formatDateLongStyle(d);
            }

            public String formatDateShortStyle(Date d) {
                return super.formatDateShortStyle(d);
            }

            public String formatDateTime(Date d) {
                return super.formatDateTime(d);
            }

            public String getCurrencySymbol() {
                return super.getCurrencySymbol();
            }
        };
    }
    return lm;
}
Also used : Date(java.util.Date) L10NManager(com.codename1.l10n.L10NManager)

Example 5 with L10NManager

use of com.codename1.l10n.L10NManager in project CodenameOne by codenameone.

the class BlackBerryImplementation method getLocalizationManager.

/**
 * @inheritDoc
 */
public L10NManager getLocalizationManager() {
    if (l10n == null) {
        Locale l = Locale.getDefault();
        l10n = new L10NManager(l.getLanguage(), l.getCountry()) {

            public String format(int number) {
                return super.format(number);
            }

            public String format(double number) {
                return super.format(number);
            }

            public String formatCurrency(double currency) {
                return super.formatCurrency(currency);
            }

            public String formatDateLongStyle(Date d) {
                return DateFormat.getInstance(DateFormat.DATE_LONG).format(d);
            }

            public String formatDateShortStyle(Date d) {
                return DateFormat.getInstance(DateFormat.DATE_SHORT).format(d);
            }

            public String formatDateTime(Date d) {
                String date = DateFormat.getInstance(DateFormat.DATE_FULL).format(d);
                String time = DateFormat.getInstance(DateFormat.TIME_FULL).format(d);
                return date + " " + time;
            }

            public String getCurrencySymbol() {
                return super.getCurrencySymbol();
            }

            public void setLocale(String locale, String language) {
                super.setLocale(locale, language);
                Locale.setDefault(Locale.get(language, locale));
            }
        };
    }
    return l10n;
}
Also used : Locale(net.rim.device.api.i18n.Locale) Date(java.util.Date) L10NManager(com.codename1.l10n.L10NManager)

Aggregations

L10NManager (com.codename1.l10n.L10NManager)5 Date (java.util.Date)4 Locale (java.util.Locale)3 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 Paint (android.graphics.Paint)1 Point (java.awt.Point)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (net.rim.device.api.i18n.Locale)1