Bug 544414 - Handle locales correctly on Android r=blassey,sayre, a=blocking-fennec

This commit is contained in:
Alex Pakhotin 2010-11-26 17:28:24 -08:00
parent 6f02ac1273
commit f17c106434
2 changed files with 26 additions and 4 deletions

View File

@ -42,6 +42,7 @@ import java.util.*;
import java.util.zip.*;
import java.nio.*;
import java.lang.reflect.*;
import java.text.*;
import android.os.*;
import android.app.*;
@ -125,11 +126,25 @@ class GeckoAppShell
else
downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath());
GeckoAppShell.putenv("LANG=" + Locale.getDefault().toString());
putLocaleEnv();
loadLibs(apkName);
}
private static void putLocaleEnv() {
GeckoAppShell.putenv("LANG=" + Locale.getDefault().toString());
NumberFormat nf = NumberFormat.getInstance();
if (nf instanceof DecimalFormat) {
DecimalFormat df = (DecimalFormat)nf;
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
GeckoAppShell.putenv("LOCALE_DECIMAL_POINT=" + dfs.getDecimalSeparator());
GeckoAppShell.putenv("LOCALE_THOUSANDS_SEP=" + dfs.getGroupingSeparator());
GeckoAppShell.putenv("LOCALE_GROUPING=" + (char)df.getGroupingSize());
}
}
public static void runGecko(String apkPath, String args, String url) {
// run gecko -- it will spawn its own thread
GeckoAppShell.nativeInit();

View File

@ -1009,9 +1009,16 @@ js_InitRuntimeNumberState(JSContext *cx)
number_constants[NC_MIN_VALUE].dval = u.d;
#ifndef HAVE_LOCALECONV
rt->thousandsSeparator = JS_strdup(cx, "'");
rt->decimalSeparator = JS_strdup(cx, ".");
rt->numGrouping = JS_strdup(cx, "\3\0");
const char* thousands_sep = getenv("LOCALE_THOUSANDS_SEP");
const char* decimal_point = getenv("LOCALE_DECIMAL_POINT");
const char* grouping = getenv("LOCALE_GROUPING");
rt->thousandsSeparator =
JS_strdup(cx, thousands_sep ? thousands_sep : "'");
rt->decimalSeparator =
JS_strdup(cx, decimal_point ? decimal_point : ".");
rt->numGrouping =
JS_strdup(cx, grouping ? grouping : "\3\0");
#else
struct lconv *locale = localeconv();
rt->thousandsSeparator =