[gnome-maps/wip/mlundblad/photon-geocode: 2/14] Add module with address util functions
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/photon-geocode: 2/14] Add module with address util functions
- Date: Wed, 5 Jun 2019 20:40:09 +0000 (UTC)
commit c9d6dfafddb5beb30874b7386798be808f5e4eca
Author: Marcus Lundblad <ml update uu se>
Date: Tue Apr 30 23:12:15 2019 +0200
Add module with address util functions
Utility function to format country-specific
street and housenumber format strings.
src/address.js | 113 +++++++++++++++++++++++++++++++++++
src/org.gnome.Maps.src.gresource.xml | 1 +
2 files changed, 114 insertions(+)
---
diff --git a/src/address.js b/src/address.js
new file mode 100644
index 0000000..c85cb63
--- /dev/null
+++ b/src/address.js
@@ -0,0 +1,113 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2019 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 address formatting.
+ */
+
+const Format = imports.format;
+
+/**
+ * Translation lookup table for street name and house number.
+ * First argument is the street name and the second the housenumber.
+ * Based on examples from https://en.wikipedia.org/wiki/Address#Address_format
+ * Currently don't include address formats for i.e. China and Japan as those
+ * formats differ from the Western ones and would need additional handling
+ * when printing place addresses (currently we assume there is a street name
+ * and house number).
+ */
+const FORMAT_MAP = {
+ 'AL': '%1$s %2$s̈́',
+ 'AR': '%1$s %2$s',
+ 'AS': '%1$s %2$s',
+ 'AU': '%2$s %1$s',
+ 'AX': '%1$s %2$s',
+ 'BA': '%1$s %2$s',
+ 'BD': '%1$s. %2$s',
+ 'BE': '%1$s %2$s',
+ 'BR': '%1$s, %2$s',
+ 'BY': '%1$s, д. %2$s',
+ /* if we had access to state codes, we could add a special case for
+ * Quebec format
+ */
+ 'CA': '%2$s %1$s',
+ 'CH': '%1$s %2$s',
+ 'CL': '%1$s No° %2$s',
+ 'CZ': '%1$s %2$s',
+ 'CY': '%1$s %2$s',
+ 'DE': '%1$s %2$s',
+ 'DK': '%1$s %2$s',
+ 'EE': '%1$s %2$s',
+ 'ES': '%1$s, %2$s',
+ 'FI': '%1$s %2$s',
+ 'FR': '%2$s, %1$s',
+ 'GB': '%2$s %1$s',
+ 'GR': '%1$s %2$s',
+ 'HK': '%2$s %1$s',
+ 'HR': '%1$s %2$s',
+ 'HU': '%1$s %2$s',
+ 'IE': '%2$s %1$s',
+ 'IL': '%2$s %1$s',
+ 'IS': '%1$s %2$s',
+ 'IN': '%2$s %1$s',
+ 'ID': '%1$s No. %2$s',
+ 'IR': '%1$s %2$s',
+ 'IT': '%1$s %2$s',
+ 'IQ': '%1$s %2$s',
+ 'KR': '%1$s %2$s',
+ 'LK': '%2$s %1$s',
+ 'LV': '%1$s %2$s',
+ 'ME': '%1$s %2$s',
+ 'MO': '%1$s%2$s',
+ 'MY': '%2$s $1%s',
+ 'MX': '%1$s No. %2$s',
+ 'NL': '%1$s %2$s',
+ 'NO': '%1$s %2$s',
+ 'NZ': '%2$s %1$s',
+ 'OM': '%1$s, %2$s',
+ 'PE': '%1$s %2$s',
+ 'PK': '%2$s, %1$s',
+ 'PH': '%2$s %1$s',
+ 'PL': '%1$s %2$s',
+ 'PT': '%1$s %2$s',
+ 'RO': '%1$s, nr. %2$s',
+ 'RS': '%1$s %2$s',
+ 'RU': '%1$s, д. %2$s',
+ 'SA': '%2$s %1$s',
+ 'SE': '%1$s %2$s',
+ 'SG': '%2$s %1$s',
+ 'SK': '%1$s %2$s',
+ 'SL': '%1$s %2$s',
+ 'TR': '%1$s %2$s',
+ 'TW': '%1$s, %2$s̈́',
+ 'UK': 'вул. %1$s, буд. %2$s',
+ 'US': '%2$s %1$s',
+ 'VN': 'số %2$s %1$s'
+}
+
+function streetAddressForCountryCode(streetName, housenumber, countryCode) {
+ let format = FORMAT_MAP[countryCode];
+
+ if (format)
+ return Format.vprintf(format, [streetName, housenumber]);
+ else
+ return Format.vprintf('%s %s', [housenumber, streetName]);
+}
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 4abd878..16c64b1 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/Maps/js">
<file>accountListBox.js</file>
+ <file>address.js</file>
<file>application.js</file>
<file>checkIn.js</file>
<file>checkInDialog.js</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]