You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/07/30 21:06:20 UTC
[03/38] git commit: BB10: Implement getPreferredLanguage and
getLocaleName.
BB10: Implement getPreferredLanguage and getLocaleName.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/3bbed32d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/3bbed32d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/3bbed32d
Branch: refs/heads/lyon-g11n
Commit: 3bbed32dd3f36e7df8ba92dbc7f548bfc563ff62
Parents: 6ab7044
Author: Lianghui Chen <li...@blackberry.com>
Authored: Wed Jul 23 11:42:20 2014 -0400
Committer: Lianghui Chen <li...@blackberry.com>
Committed: Mon Jul 28 15:10:45 2014 -0400
----------------------------------------------------------------------
.../native/src/globalization_ndk.cpp | 36 ++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/3bbed32d/src/blackberry10/native/src/globalization_ndk.cpp
----------------------------------------------------------------------
diff --git a/src/blackberry10/native/src/globalization_ndk.cpp b/src/blackberry10/native/src/globalization_ndk.cpp
index 715850e..4e00015 100644
--- a/src/blackberry10/native/src/globalization_ndk.cpp
+++ b/src/blackberry10/native/src/globalization_ndk.cpp
@@ -17,6 +17,7 @@
#include <string>
#include <json/reader.h>
#include <json/writer.h>
+#include <unicode/calendar.h>
#include "globalization_ndk.hpp"
#include "globalization_js.hpp"
@@ -45,6 +46,15 @@ std::string errorInJson(int code, const std::string& message)
return writer.write(root);
}
+std::string resultInJson(const std::string& value)
+{
+ Json::Value root;
+ root["result"] = value;
+
+ Json::FastWriter writer;
+ return writer.write(root);
+}
+
GlobalizationNDK::GlobalizationNDK(GlobalizationJS *parent) {
m_pParent = parent;
}
@@ -54,12 +64,34 @@ GlobalizationNDK::~GlobalizationNDK() {
std::string GlobalizationNDK::getPreferredLanguage()
{
- return errorInJson(UNKNOWN_ERROR, "Not supported!");
+ const Locale& loc = Locale::getDefault();
+
+ UnicodeString disp;
+ loc.getDisplayLanguage(loc, disp);
+ if (disp.isEmpty())
+ return resultInJson("English"); // FIXME: what should be the default language?
+
+ std::string utf8;
+ disp.toUTF8String(utf8);
+ return resultInJson(utf8);
}
std::string GlobalizationNDK::getLocaleName()
{
- return errorInJson(UNKNOWN_ERROR, "Not supported!");
+ const Locale& loc = Locale::getDefault();
+ const char* name = loc.getName();
+ if (name)
+ return resultInJson(name);
+
+ const char* lang = loc.getLanguage();
+ if (!lang)
+ return resultInJson("en"); // FIXME: what should be the default language?
+
+ const char* country = loc.getCountry();
+ if (!country)
+ return resultInJson(lang);
+
+ return resultInJson(std::string(lang) + "_" + country);
}
std::string GlobalizationNDK::dateToString(const std::string& args)