[gnome-maps/wip/mlundblad/localized-names-from-overpass: 1/2] WIP: Add module with utility functions for localized OSM names




commit c60f547fdaad841fe69d9f2077206acc81f2ff77
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Oct 9 22:39:26 2020 +0200

    WIP: Add module with utility functions for localized OSM names

 src/org.gnome.Maps.src.gresource.xml |  1 +
 src/osmNames.js                      | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index ab2e12f0..8c455163 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -45,6 +45,7 @@
     <file>osmConnection.js</file>
     <file>osmEdit.js</file>
     <file>osmEditDialog.js</file>
+    <file>osmNames.js</file>
     <file>osmTypeSearchEntry.js</file>
     <file>osmTypeListRow.js</file>
     <file>osmTypePopover.js</file>
diff --git a/src/osmNames.js b/src/osmNames.js
new file mode 100644
index 00000000..48778023
--- /dev/null
+++ b/src/osmNames.js
@@ -0,0 +1,41 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2020 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+/**
+ * Utility functions for getting localized names of OSM objects.
+ * See https://wiki.openstreetmap.org/wiki/Multilingual_names
+ */
+
+function getNameForLanguage(tags, language) {
+    let localizedName = tags['name:' + language];
+
+    if (!localizedName && (language === 'nb' || language === 'nn'))
+        localizedName = tags['name:no'];
+
+    return localizedName;
+}
+
+function getFallbackNameForLanguage(tags, place, language) {
+    /* TODO: determine fallback name variant depending on location-dependent
+     * rules
+     */
+    return tags.name;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]