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




commit 26d77698b85557a1221c958e3cf330b39d6938c7
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                      | 61 ++++++++++++++++++++++++++++++++++++
 2 files changed, 62 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..ee92d91b
--- /dev/null
+++ b/src/osmNames.js
@@ -0,0 +1,61 @@
+/* -*- 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];
+
+    /* for names in Norwegian, the best practice in OSM is to use the
+     * general code 'no' for translated names, unless the translation
+     * differs between Bokmål (nb) and Nynorsk (nn), in which case the standard
+     * ISO 639-2 codes are used, e.g. the default case from above will be used
+     */
+    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
+     */
+    let natName;
+    let intName;
+
+    // TODO: country/territory-specific heuristics for fallback, romanization etc.
+    switch (place.country_code) {
+
+    }
+
+    if (natName)
+        return natName;
+    else if (intName)
+        return intName;
+    else if (tags.int_name)
+        return tags.int_name;
+    else
+        return tags.name;
+}


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