/soc/2015/jgeboski/facebook: 473934b0c408: facebook: use working...

James Geboski jgeboski at gmail.com
Tue Jun 23 17:16:15 EDT 2015


Changeset: 473934b0c4080c752490821c24b016c0ce35e1c4
Author:	 James Geboski <jgeboski at gmail.com>
Date:	 2015-06-14 20:14 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/473934b0c408

Description:

facebook: use working locale language

diffstat:

 libpurple/protocols/facebook/api.c  |   6 ++++--
 libpurple/protocols/facebook/util.c |  28 ++++++++++++++++++++++++++++
 libpurple/protocols/facebook/util.h |   3 +++
 3 files changed, 35 insertions(+), 2 deletions(-)

diffs (73 lines):

diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -382,14 +382,16 @@ fb_api_http_req(FbApi *api, const FbApiH
 	PurpleHttpRequest *req;
 
 	fb_http_params_set_str(params, "api_key", FB_API_KEY);
-	fb_http_params_set_str(params, "client_country_code", "US");
 	fb_http_params_set_str(params, "device_id", priv->did);
 	fb_http_params_set_str(params, "fb_api_caller_class", info->klass);
 	fb_http_params_set_str(params, "fb_api_req_friendly_name", info->name);
 	fb_http_params_set_str(params, "format", "json");
-	fb_http_params_set_str(params, "locale", "en_US");
 	fb_http_params_set_str(params, "method", info->method);
 
+	val = fb_util_locale_str();
+	fb_http_params_set_str(params, "locale", val);
+	g_free(val);
+
 	req = purple_http_request_new(url);
 	purple_http_request_set_method(req, "POST");
 
diff --git a/libpurple/protocols/facebook/util.c b/libpurple/protocols/facebook/util.c
--- a/libpurple/protocols/facebook/util.c
+++ b/libpurple/protocols/facebook/util.c
@@ -27,6 +27,34 @@
 #include "util.h"
 
 gchar *
+fb_util_locale_str(void)
+{
+	const gchar * const *langs;
+	const gchar *lang;
+	gchar *chr;
+	guint i;
+
+	static const gchar chrs[] = {'.', '@'};
+
+	langs = g_get_language_names();
+	lang = langs[0];
+
+	if (purple_strequal(lang, "C")) {
+		return g_strdup("en_US");
+	}
+
+	for (i = 0; i < G_N_ELEMENTS(chrs); i++) {
+		chr = strchr(lang, chrs[i]);
+
+		if (chr != NULL) {
+			return g_strndup(lang, chr - lang);
+		}
+	}
+
+	return g_strdup(lang);
+}
+
+gchar *
 fb_util_randstr(gsize size)
 {
 	gchar *ret;
diff --git a/libpurple/protocols/facebook/util.h b/libpurple/protocols/facebook/util.h
--- a/libpurple/protocols/facebook/util.h
+++ b/libpurple/protocols/facebook/util.h
@@ -29,6 +29,9 @@
 typedef void (*FbUtilRequestBuddyFunc) (GSList *buddies, gpointer data);
 
 gchar *
+fb_util_locale_str(void);
+
+gchar *
 fb_util_randstr(gsize size);
 
 gpointer



More information about the Commits mailing list