Permalink
Browse files

Update package name and add getPreferredLanguage API

  • Loading branch information...
1 parent 948db0e commit 7d49b765b240b3d5b07de31c27009f587bf1b1f1 mow415 committed Aug 7, 2012
@@ -2,7 +2,7 @@
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
- * Copyright (c) 2011, IBM Corporation
+ * Copyright (c) 2011-2012, IBM Corporation
*/
package org.apache.cordova.plugins.globalization;
@@ -41,6 +41,8 @@ public PluginResult execute(String action, JSONArray data, String callbackId) {
try {
if (action.equals(Resources.GETLOCALENAME)) {
obj = getLocaleName();
+ } else if (action.equals(Resources.GETPREFERREDLANGUAGE)){
+ obj = getPreferredLanguage();
} else if (action.equalsIgnoreCase(Resources.DATETOSTRING)) {
obj = getDateToString(data);
} else if (action.equalsIgnoreCase(Resources.STRINGTODATE)) {
@@ -90,6 +92,23 @@ private JSONObject getLocaleName() throws GlobalizationError {
}
}
+ /*
+ * @Description: Returns the string identifier for the client's current language
+ *
+ * @Return: JSONObject
+ * Object.value {String}: The language identifier
+ *
+ * @throws: GlobalizationError.UNKNOWN_ERROR
+ */
+ private JSONObject getPreferredLanguage() throws GlobalizationError {
+ JSONObject obj = new JSONObject();
+ try {
+ return obj.put("value", Locale.getDefault().getDisplayLanguage().toString());
+ } catch (Exception e) {
+ throw new GlobalizationError(GlobalizationError.UNKNOWN_ERROR);
+ }
+ }
+
/*
* Returns a date formatted as a string according to the client's user
* preferences and calendar using the time zone of the client.
@@ -2,7 +2,7 @@
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
- * Copyright (c) 2011, IBM Corporation
+ * Copyright (c) 2011-2012, IBM Corporation
*/
package org.apache.cordova.plugins.globalization;
@@ -19,6 +19,7 @@
public static final String STRINGTONUMBER = "stringToNumber";
public static final String GETNUMBERPATTERN = "getNumberPattern";
public static final String GETCURRENCYPATTERN = "getCurrencyPattern";
+ public static final String GETPREFERREDLANGUAGE = "getPreferredLanguage";
// Globalization Option Parameters
public static final String OPTIONS = "options";
Oops, something went wrong.

0 comments on commit 7d49b76

Please sign in to comment.