[gnome-maps/wip/mlundblad/osm-edit-namevariants: 1/2] osmUtils: Add a function to get the bare language code
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/osm-edit-namevariants: 1/2] osmUtils: Add a function to get the bare language code
- Date: Mon, 27 Mar 2017 20:23:56 +0000 (UTC)
commit fdc2bef4ebc6ad4f227bcf58f23bca613a5657e1
Author: Marcus Lundblad <ml update uu se>
Date: Mon Mar 27 22:22:50 2017 +0200
osmUtils: Add a function to get the bare language code
src/osmUtils.js | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/osmUtils.js b/src/osmUtils.js
index 91c6b69..1bbb099 100644
--- a/src/osmUtils.js
+++ b/src/osmUtils.js
@@ -20,10 +20,13 @@
* Author: Marcus Lundblad <ml update uu se>
*/
+const GLib = imports.gi.GLib;
const Soup = imports.gi.Soup;
const Application = imports.application;
+let languageCode = null;
+
/*
* Gets a Wikipedia article in OSM tag format (i.e. lang:Article title)
* given a URL or null if input doesn't match a Wikipedia URL
@@ -65,3 +68,24 @@ function updatePlaceFromOSMObject(place, object) {
Application.placeStore.updatePlace(place);
}
+
+/**
+ * Get the bare ISO 639 language code of the preferred locale.
+ */
+function getLanguageCode() {
+ if (languageCode)
+ return languageCode;
+
+ let locale = GLib.get_language_names()[0];
+
+ // strip charset
+ if (locale.indexOf('.') !== -1)
+ locale = locale.substring(0, locale.indexOf('.'));
+
+ // strip country
+ if (locale.indexOf('_') !== -1)
+ locale = locale.substring(0, locale.indexOf('_'));
+
+ languageCode = locale;
+ return languageCode;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]