Merge lp:~mterry/timezonemap/alternate-names into lp:timezonemap

Proposed by Michael Terry
Status: Approved
Approved by: Mathieu Trudel-Lapierre
Approved revision: 59
Proposed branch: lp:~mterry/timezonemap/alternate-names
Merge into: lp:timezonemap
Diff against target: 330 lines (+184/-24)
6 files modified
configure.ac (+1/-1)
debian/changelog (+6/-0)
src/cc-timezone-location.c (+68/-0)
src/cc-timezone-location.h (+4/-0)
src/test-timezone.c (+100/-23)
src/tz.c (+5/-0)
To merge this branch: bzr merge lp:~mterry/timezonemap/alternate-names
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
Review via email: mp+280194@code.launchpad.net

Commit message

Exposes the "alternate_names" and "en_name_utf8" fields from the cities database.

Description of the change

This branch exposes the "alternate_names" and "en_name_utf8" fields from the cities database.

My rationale here is enabling the unity8 out-of-box wizard to search on native-language city names.

Ideally, we could use the alternateNames.txt database, but that is 400MB uncompressed, and we probably don't want to add that to the images. (If we did use that, we could add an API like get_localized_name(gchar *locale) or some such, which clients could use to populate their databases with just the current language's search names. That would be swell.)

But failing that, cities15000.txt has a short list of alternate names (without noting which language each name is in). I've exposed that here, so that clients can search across all possible language strings.

While doing that, I noticed that our en_name field was using the ascii name. I considered just upgrading it to the utf8 version, but guessed that you folks wouldn't like that change in behavior. So I exposed the utf8 version too (makes for a better display value).

To post a comment you must log in.
59. By Michael Terry

Bump version

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

LGTM

review: Approve

Unmerged revisions

59. By Michael Terry

Bump version

58. By Michael Terry

Add new field en_name_utf8 rather than upgrading en_name in place

57. By Michael Terry

Expose alternate_names from cities database

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2015-05-07 23:16:25 +0000
+++ configure.ac 2015-12-14 21:59:55 +0000
@@ -1,5 +1,5 @@
1AC_INIT([libtimezonemap],1AC_INIT([libtimezonemap],
2 [0.4.4],2 [0.4.5],
3 [http://bugs.launchpad.net/libtimezonemap],3 [http://bugs.launchpad.net/libtimezonemap],
4 [libtimezonemap],4 [libtimezonemap],
5 [http://launchpad.net/libtimezonemap])5 [http://launchpad.net/libtimezonemap])
66
=== modified file 'debian/changelog'
--- debian/changelog 2015-05-07 23:18:41 +0000
+++ debian/changelog 2015-12-14 21:59:55 +0000
@@ -1,3 +1,9 @@
1libtimezonemap (0.4.5) UNRELEASED; urgency=medium
2
3 * Add alternate_names and en_name_utf8 fields to locations.
4
5 -- Michael Terry <mterry@ubuntu.com> Thu, 10 Dec 2015 15:40:49 -0500
6
1libtimezonemap (0.4.4) wily; urgency=medium7libtimezonemap (0.4.4) wily; urgency=medium
28
3 [ David Shea ]9 [ David Shea ]
410
=== modified file 'src/cc-timezone-location.c'
--- src/cc-timezone-location.c 2013-11-29 12:23:12 +0000
+++ src/cc-timezone-location.c 2015-12-14 21:59:55 +0000
@@ -34,6 +34,8 @@
34 gchar *country;34 gchar *country;
35 gchar *full_country;35 gchar *full_country;
36 gchar *en_name;36 gchar *en_name;
37 gchar *en_name_utf8;
38 gchar **alternate_names;
37 gchar *state;39 gchar *state;
38 gdouble latitude;40 gdouble latitude;
39 gdouble longitude;41 gdouble longitude;
@@ -48,6 +50,8 @@
48 PROP_COUNTRY,50 PROP_COUNTRY,
49 PROP_FULL_COUNTRY,51 PROP_FULL_COUNTRY,
50 PROP_EN_NAME,52 PROP_EN_NAME,
53 PROP_EN_NAME_UTF8,
54 PROP_ALTERNATE_NAMES,
51 PROP_STATE,55 PROP_STATE,
52 PROP_LATITUDE,56 PROP_LATITUDE,
53 PROP_LONGITUDE,57 PROP_LONGITUDE,
@@ -73,6 +77,12 @@
73 case PROP_EN_NAME:77 case PROP_EN_NAME:
74 g_value_set_string (value, priv->en_name);78 g_value_set_string (value, priv->en_name);
75 break;79 break;
80 case PROP_EN_NAME_UTF8:
81 g_value_set_string (value, priv->en_name_utf8);
82 break;
83 case PROP_ALTERNATE_NAMES:
84 g_value_set_boxed (value, priv->alternate_names);
85 break;
76 case PROP_STATE:86 case PROP_STATE:
77 g_value_set_string (value, priv->state);87 g_value_set_string (value, priv->state);
78 break;88 break;
@@ -113,6 +123,12 @@
113 case PROP_EN_NAME:123 case PROP_EN_NAME:
114 cc_timezone_location_set_en_name(loc, g_value_get_string(value));124 cc_timezone_location_set_en_name(loc, g_value_get_string(value));
115 break;125 break;
126 case PROP_EN_NAME_UTF8:
127 cc_timezone_location_set_en_name_utf8(loc, g_value_get_string(value));
128 break;
129 case PROP_ALTERNATE_NAMES:
130 cc_timezone_location_set_alternate_names(loc, (const gchar **)g_value_get_boxed(value));
131 break;
116 case PROP_STATE:132 case PROP_STATE:
117 cc_timezone_location_set_state(loc, g_value_get_string(value));133 cc_timezone_location_set_state(loc, g_value_get_string(value));
118 break;134 break;
@@ -159,6 +175,18 @@
159 priv->en_name = NULL;175 priv->en_name = NULL;
160 }176 }
161177
178 if (priv->en_name_utf8)
179 {
180 g_free (priv->en_name_utf8);
181 priv->en_name_utf8 = NULL;
182 }
183
184 if (priv->alternate_names)
185 {
186 g_strfreev (priv->alternate_names);
187 priv->alternate_names = NULL;
188 }
189
162 if (priv->state) 190 if (priv->state)
163 {191 {
164 g_free (priv->state);192 g_free (priv->state);
@@ -220,6 +248,20 @@
220 "",248 "",
221 G_PARAM_READWRITE));249 G_PARAM_READWRITE));
222 g_object_class_install_property(object_class,250 g_object_class_install_property(object_class,
251 PROP_EN_NAME_UTF8,
252 g_param_spec_string ("en_name_utf8",
253 "English Name in UTF-8",
254 "The name of the location, encoded in UTF-8",
255 "",
256 G_PARAM_READWRITE));
257 g_object_class_install_property(object_class,
258 PROP_ALTERNATE_NAMES,
259 g_param_spec_boxed ("alternate_names",
260 "Alternate Names",
261 "Non-English names of the location",
262 G_TYPE_STRV,
263 G_PARAM_READWRITE));
264 g_object_class_install_property(object_class,
223 PROP_STATE,265 PROP_STATE,
224 g_param_spec_string ("state",266 g_param_spec_string ("state",
225 "State",267 "State",
@@ -320,6 +362,32 @@
320 g_object_notify(G_OBJECT(loc), "en_name");362 g_object_notify(G_OBJECT(loc), "en_name");
321}363}
322364
365const gchar *cc_timezone_location_get_en_name_utf8(CcTimezoneLocation *loc)
366{
367 return loc->priv->en_name_utf8;
368}
369
370void cc_timezone_location_set_en_name_utf8(CcTimezoneLocation *loc, const gchar *en_name_utf8)
371{
372 g_free(loc->priv->en_name_utf8);
373 loc->priv->en_name_utf8 = g_strdup(en_name_utf8);
374
375 g_object_notify(G_OBJECT(loc), "en_name_utf8");
376}
377
378const gchar * const *cc_timezone_location_get_alternate_names(CcTimezoneLocation *loc)
379{
380 return (const gchar * const *)loc->priv->alternate_names;
381}
382
383void cc_timezone_location_set_alternate_names(CcTimezoneLocation *loc, const gchar **alternate_names)
384{
385 g_strfreev(loc->priv->alternate_names);
386 loc->priv->alternate_names = g_strdupv((gchar **)alternate_names);
387
388 g_object_notify(G_OBJECT(loc), "alternate_names");
389}
390
323const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc)391const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc)
324{392{
325 return loc->priv->state;393 return loc->priv->state;
326394
=== modified file 'src/cc-timezone-location.h'
--- src/cc-timezone-location.h 2013-11-14 15:50:49 +0000
+++ src/cc-timezone-location.h 2015-12-14 21:59:55 +0000
@@ -77,6 +77,10 @@
77void cc_timezone_location_set_full_country(CcTimezoneLocation *loc, const gchar *full_country);77void cc_timezone_location_set_full_country(CcTimezoneLocation *loc, const gchar *full_country);
78const gchar *cc_timezone_location_get_en_name(CcTimezoneLocation *loc);78const gchar *cc_timezone_location_get_en_name(CcTimezoneLocation *loc);
79void cc_timezone_location_set_en_name(CcTimezoneLocation *loc, const gchar *en_name);79void cc_timezone_location_set_en_name(CcTimezoneLocation *loc, const gchar *en_name);
80const gchar *cc_timezone_location_get_en_name_utf8(CcTimezoneLocation *loc);
81void cc_timezone_location_set_en_name_utf8(CcTimezoneLocation *loc, const gchar *en_name_utf8);
82const gchar* const *cc_timezone_location_get_alternate_names(CcTimezoneLocation *loc);
83void cc_timezone_location_set_alternate_names(CcTimezoneLocation *loc, const gchar **alternate_names);
80const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc);84const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc);
81void cc_timezone_location_set_state(CcTimezoneLocation *loc, const gchar *state);85void cc_timezone_location_set_state(CcTimezoneLocation *loc, const gchar *state);
82gdouble cc_timezone_location_get_latitude(CcTimezoneLocation *loc);86gdouble cc_timezone_location_get_latitude(CcTimezoneLocation *loc);
8387
=== modified file 'src/test-timezone.c'
--- src/test-timezone.c 2013-11-29 12:26:52 +0000
+++ src/test-timezone.c 2015-12-14 21:59:55 +0000
@@ -3,33 +3,15 @@
33
4#include "tz.h"4#include "tz.h"
55
6int main (int argc, char **argv)6gboolean test_pixmaps(TzDB *db, const gchar *pixmap_dir)
7{7{
8 TzDB *db;
9 GPtrArray *locs;8 GPtrArray *locs;
10 guint i;9 guint i;
11 char *pixmap_dir;10 gboolean retval = TRUE;
12 int retval = 0;11
13
14 setlocale (LC_ALL, "");
15
16 if (argc == 2)
17 {
18 pixmap_dir = g_strdup (argv[1]);
19 } else if (argc == 1) {
20 pixmap_dir = g_strdup ("data/");
21 } else {
22 g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
23 return 1;
24 }
25
26#if !GLIB_CHECK_VERSION(2, 35, 0)
27 g_type_init();
28#endif
29 GValue zone = {0};12 GValue zone = {0};
30 g_value_init(&zone, G_TYPE_STRING);13 g_value_init(&zone, G_TYPE_STRING);
3114
32 db = tz_load_db ();
33 locs = tz_get_locations (db);15 locs = tz_get_locations (db);
34 for (i = 0; i < locs->len ; i++)16 for (i = 0; i < locs->len ; i++)
35 {17 {
@@ -53,15 +35,110 @@
53 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE)35 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE)
54 {36 {
55 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));37 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));
56 retval = 1;38 retval = FALSE;
57 }39 }
5840
59 g_free (filename);41 g_free (filename);
60 g_free (path);42 g_free (path);
61 tz_info_free (info);43 tz_info_free (info);
62 }44 }
45
46 return retval;
47}
48
49gboolean test_names(TzDB *db)
50{
51 GPtrArray *locs = tz_get_locations (db);
52 for (guint i = 0; i < locs->len; i++)
53 {
54 CcTimezoneLocation *loc = locs->pdata[i];
55
56 gchar *en_name;
57 g_object_get (G_OBJECT (loc), "en_name", &en_name, NULL);
58
59 if (g_strcmp0 (en_name, "Aibak") == 0)
60 {
61 g_free (en_name);
62
63 gchar *en_name_utf8;
64 g_object_get (G_OBJECT (loc), "en_name_utf8", &en_name_utf8, NULL);
65 if (g_strcmp0 (en_name_utf8, "Aībak") != 0)
66 {
67 g_message ("Aībak utf8 name is wrong: %s", en_name_utf8);
68 g_free (en_name_utf8);
69 return FALSE;
70 }
71 g_free (en_name_utf8);
72
73 gchar **alternate_names;
74 g_object_get (G_OBJECT (loc), "alternate_names", &alternate_names, NULL);
75
76 gchar *expected_names[] = {"Aibak", "Aybak", "Aībak", "Eybak",
77 "Haibak", "Samagan", "Samangan",
78 "Samangān", "aybk", "smngan", "Āybak",
79 "Саманган", "آیبک" ,"ایبک" ,"سمنگان", NULL};
80
81 guint names_len = g_strv_length (alternate_names);
82 if (names_len != g_strv_length (expected_names))
83 {
84 g_message ("Aībak alternate name list is wrong length (%d vs %d):\n%s",
85 names_len, g_strv_length (expected_names),
86 g_strjoinv (",", alternate_names));
87 g_strfreev (alternate_names);
88 return FALSE;
89 }
90
91 for (guint j = 0; j < names_len; j++)
92 {
93 if (g_strcmp0 (alternate_names[j], expected_names[j]) != 0)
94 {
95 g_message ("Aībak alternate name list has wrong contents (%s vs %s):\n%s",
96 alternate_names[j], expected_names[j],
97 g_strjoinv (",", alternate_names));
98 g_strfreev (alternate_names);
99 return FALSE;
100 }
101 }
102
103 return TRUE;
104 }
105
106 g_free (en_name);
107 }
108
109 g_message ("Did not find Aībak");
110 return FALSE;
111}
112
113int main (int argc, char **argv)
114{
115 TzDB *db;
116 gchar *pixmap_dir;
117 gboolean retval = TRUE;
118
119 setlocale (LC_ALL, "");
120
121 if (argc == 2)
122 {
123 pixmap_dir = g_strdup (argv[1]);
124 } else if (argc == 1) {
125 pixmap_dir = g_strdup ("data/");
126 } else {
127 g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
128 return 1;
129 }
130
131#if !GLIB_CHECK_VERSION(2, 35, 0)
132 g_type_init();
133#endif
134
135 db = tz_load_db ();
136
137 retval = test_pixmaps(db, pixmap_dir) && retval;
138 retval = test_names(db) && retval;
139
63 tz_db_free (db);140 tz_db_free (db);
64 g_free (pixmap_dir);141 g_free (pixmap_dir);
65142
66 return retval;143 return retval ? 0 : 1;
67}144}
68145
=== modified file 'src/tz.c'
--- src/tz.c 2013-12-16 17:01:37 +0000
+++ src/tz.c 2015-12-14 21:59:55 +0000
@@ -114,6 +114,11 @@
114114
115 cc_timezone_location_set_country(loc, parsed_data_v[8]);115 cc_timezone_location_set_country(loc, parsed_data_v[8]);
116 cc_timezone_location_set_en_name(loc, parsed_data_v[2]);116 cc_timezone_location_set_en_name(loc, parsed_data_v[2]);
117 cc_timezone_location_set_en_name_utf8(loc, parsed_data_v[1]);
118
119 gchar **altnames = g_strsplit(parsed_data_v[3], ",", -1);
120 cc_timezone_location_set_alternate_names(loc, (const gchar **)altnames);
121 g_strfreev(altnames);
117122
118 gchar * tmpState = g_strdup_printf ("%s.%s",123 gchar * tmpState = g_strdup_printf ("%s.%s",
119 cc_timezone_location_get_country(loc),124 cc_timezone_location_get_country(loc),

Subscribers

People subscribed via source and target branches