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
1=== modified file 'configure.ac'
2--- configure.ac 2015-05-07 23:16:25 +0000
3+++ configure.ac 2015-12-14 21:59:55 +0000
4@@ -1,5 +1,5 @@
5 AC_INIT([libtimezonemap],
6- [0.4.4],
7+ [0.4.5],
8 [http://bugs.launchpad.net/libtimezonemap],
9 [libtimezonemap],
10 [http://launchpad.net/libtimezonemap])
11
12=== modified file 'debian/changelog'
13--- debian/changelog 2015-05-07 23:18:41 +0000
14+++ debian/changelog 2015-12-14 21:59:55 +0000
15@@ -1,3 +1,9 @@
16+libtimezonemap (0.4.5) UNRELEASED; urgency=medium
17+
18+ * Add alternate_names and en_name_utf8 fields to locations.
19+
20+ -- Michael Terry <mterry@ubuntu.com> Thu, 10 Dec 2015 15:40:49 -0500
21+
22 libtimezonemap (0.4.4) wily; urgency=medium
23
24 [ David Shea ]
25
26=== modified file 'src/cc-timezone-location.c'
27--- src/cc-timezone-location.c 2013-11-29 12:23:12 +0000
28+++ src/cc-timezone-location.c 2015-12-14 21:59:55 +0000
29@@ -34,6 +34,8 @@
30 gchar *country;
31 gchar *full_country;
32 gchar *en_name;
33+ gchar *en_name_utf8;
34+ gchar **alternate_names;
35 gchar *state;
36 gdouble latitude;
37 gdouble longitude;
38@@ -48,6 +50,8 @@
39 PROP_COUNTRY,
40 PROP_FULL_COUNTRY,
41 PROP_EN_NAME,
42+ PROP_EN_NAME_UTF8,
43+ PROP_ALTERNATE_NAMES,
44 PROP_STATE,
45 PROP_LATITUDE,
46 PROP_LONGITUDE,
47@@ -73,6 +77,12 @@
48 case PROP_EN_NAME:
49 g_value_set_string (value, priv->en_name);
50 break;
51+ case PROP_EN_NAME_UTF8:
52+ g_value_set_string (value, priv->en_name_utf8);
53+ break;
54+ case PROP_ALTERNATE_NAMES:
55+ g_value_set_boxed (value, priv->alternate_names);
56+ break;
57 case PROP_STATE:
58 g_value_set_string (value, priv->state);
59 break;
60@@ -113,6 +123,12 @@
61 case PROP_EN_NAME:
62 cc_timezone_location_set_en_name(loc, g_value_get_string(value));
63 break;
64+ case PROP_EN_NAME_UTF8:
65+ cc_timezone_location_set_en_name_utf8(loc, g_value_get_string(value));
66+ break;
67+ case PROP_ALTERNATE_NAMES:
68+ cc_timezone_location_set_alternate_names(loc, (const gchar **)g_value_get_boxed(value));
69+ break;
70 case PROP_STATE:
71 cc_timezone_location_set_state(loc, g_value_get_string(value));
72 break;
73@@ -159,6 +175,18 @@
74 priv->en_name = NULL;
75 }
76
77+ if (priv->en_name_utf8)
78+ {
79+ g_free (priv->en_name_utf8);
80+ priv->en_name_utf8 = NULL;
81+ }
82+
83+ if (priv->alternate_names)
84+ {
85+ g_strfreev (priv->alternate_names);
86+ priv->alternate_names = NULL;
87+ }
88+
89 if (priv->state)
90 {
91 g_free (priv->state);
92@@ -220,6 +248,20 @@
93 "",
94 G_PARAM_READWRITE));
95 g_object_class_install_property(object_class,
96+ PROP_EN_NAME_UTF8,
97+ g_param_spec_string ("en_name_utf8",
98+ "English Name in UTF-8",
99+ "The name of the location, encoded in UTF-8",
100+ "",
101+ G_PARAM_READWRITE));
102+ g_object_class_install_property(object_class,
103+ PROP_ALTERNATE_NAMES,
104+ g_param_spec_boxed ("alternate_names",
105+ "Alternate Names",
106+ "Non-English names of the location",
107+ G_TYPE_STRV,
108+ G_PARAM_READWRITE));
109+ g_object_class_install_property(object_class,
110 PROP_STATE,
111 g_param_spec_string ("state",
112 "State",
113@@ -320,6 +362,32 @@
114 g_object_notify(G_OBJECT(loc), "en_name");
115 }
116
117+const gchar *cc_timezone_location_get_en_name_utf8(CcTimezoneLocation *loc)
118+{
119+ return loc->priv->en_name_utf8;
120+}
121+
122+void cc_timezone_location_set_en_name_utf8(CcTimezoneLocation *loc, const gchar *en_name_utf8)
123+{
124+ g_free(loc->priv->en_name_utf8);
125+ loc->priv->en_name_utf8 = g_strdup(en_name_utf8);
126+
127+ g_object_notify(G_OBJECT(loc), "en_name_utf8");
128+}
129+
130+const gchar * const *cc_timezone_location_get_alternate_names(CcTimezoneLocation *loc)
131+{
132+ return (const gchar * const *)loc->priv->alternate_names;
133+}
134+
135+void cc_timezone_location_set_alternate_names(CcTimezoneLocation *loc, const gchar **alternate_names)
136+{
137+ g_strfreev(loc->priv->alternate_names);
138+ loc->priv->alternate_names = g_strdupv((gchar **)alternate_names);
139+
140+ g_object_notify(G_OBJECT(loc), "alternate_names");
141+}
142+
143 const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc)
144 {
145 return loc->priv->state;
146
147=== modified file 'src/cc-timezone-location.h'
148--- src/cc-timezone-location.h 2013-11-14 15:50:49 +0000
149+++ src/cc-timezone-location.h 2015-12-14 21:59:55 +0000
150@@ -77,6 +77,10 @@
151 void cc_timezone_location_set_full_country(CcTimezoneLocation *loc, const gchar *full_country);
152 const gchar *cc_timezone_location_get_en_name(CcTimezoneLocation *loc);
153 void cc_timezone_location_set_en_name(CcTimezoneLocation *loc, const gchar *en_name);
154+const gchar *cc_timezone_location_get_en_name_utf8(CcTimezoneLocation *loc);
155+void cc_timezone_location_set_en_name_utf8(CcTimezoneLocation *loc, const gchar *en_name_utf8);
156+const gchar* const *cc_timezone_location_get_alternate_names(CcTimezoneLocation *loc);
157+void cc_timezone_location_set_alternate_names(CcTimezoneLocation *loc, const gchar **alternate_names);
158 const gchar *cc_timezone_location_get_state(CcTimezoneLocation *loc);
159 void cc_timezone_location_set_state(CcTimezoneLocation *loc, const gchar *state);
160 gdouble cc_timezone_location_get_latitude(CcTimezoneLocation *loc);
161
162=== modified file 'src/test-timezone.c'
163--- src/test-timezone.c 2013-11-29 12:26:52 +0000
164+++ src/test-timezone.c 2015-12-14 21:59:55 +0000
165@@ -3,33 +3,15 @@
166
167 #include "tz.h"
168
169-int main (int argc, char **argv)
170+gboolean test_pixmaps(TzDB *db, const gchar *pixmap_dir)
171 {
172- TzDB *db;
173 GPtrArray *locs;
174 guint i;
175- char *pixmap_dir;
176- int retval = 0;
177-
178- setlocale (LC_ALL, "");
179-
180- if (argc == 2)
181- {
182- pixmap_dir = g_strdup (argv[1]);
183- } else if (argc == 1) {
184- pixmap_dir = g_strdup ("data/");
185- } else {
186- g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
187- return 1;
188- }
189-
190-#if !GLIB_CHECK_VERSION(2, 35, 0)
191- g_type_init();
192-#endif
193+ gboolean retval = TRUE;
194+
195 GValue zone = {0};
196 g_value_init(&zone, G_TYPE_STRING);
197
198- db = tz_load_db ();
199 locs = tz_get_locations (db);
200 for (i = 0; i < locs->len ; i++)
201 {
202@@ -53,15 +35,110 @@
203 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE)
204 {
205 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));
206- retval = 1;
207+ retval = FALSE;
208 }
209
210 g_free (filename);
211 g_free (path);
212 tz_info_free (info);
213 }
214+
215+ return retval;
216+}
217+
218+gboolean test_names(TzDB *db)
219+{
220+ GPtrArray *locs = tz_get_locations (db);
221+ for (guint i = 0; i < locs->len; i++)
222+ {
223+ CcTimezoneLocation *loc = locs->pdata[i];
224+
225+ gchar *en_name;
226+ g_object_get (G_OBJECT (loc), "en_name", &en_name, NULL);
227+
228+ if (g_strcmp0 (en_name, "Aibak") == 0)
229+ {
230+ g_free (en_name);
231+
232+ gchar *en_name_utf8;
233+ g_object_get (G_OBJECT (loc), "en_name_utf8", &en_name_utf8, NULL);
234+ if (g_strcmp0 (en_name_utf8, "Aībak") != 0)
235+ {
236+ g_message ("Aībak utf8 name is wrong: %s", en_name_utf8);
237+ g_free (en_name_utf8);
238+ return FALSE;
239+ }
240+ g_free (en_name_utf8);
241+
242+ gchar **alternate_names;
243+ g_object_get (G_OBJECT (loc), "alternate_names", &alternate_names, NULL);
244+
245+ gchar *expected_names[] = {"Aibak", "Aybak", "Aībak", "Eybak",
246+ "Haibak", "Samagan", "Samangan",
247+ "Samangān", "aybk", "smngan", "Āybak",
248+ "Саманган", "آیبک" ,"ایبک" ,"سمنگان", NULL};
249+
250+ guint names_len = g_strv_length (alternate_names);
251+ if (names_len != g_strv_length (expected_names))
252+ {
253+ g_message ("Aībak alternate name list is wrong length (%d vs %d):\n%s",
254+ names_len, g_strv_length (expected_names),
255+ g_strjoinv (",", alternate_names));
256+ g_strfreev (alternate_names);
257+ return FALSE;
258+ }
259+
260+ for (guint j = 0; j < names_len; j++)
261+ {
262+ if (g_strcmp0 (alternate_names[j], expected_names[j]) != 0)
263+ {
264+ g_message ("Aībak alternate name list has wrong contents (%s vs %s):\n%s",
265+ alternate_names[j], expected_names[j],
266+ g_strjoinv (",", alternate_names));
267+ g_strfreev (alternate_names);
268+ return FALSE;
269+ }
270+ }
271+
272+ return TRUE;
273+ }
274+
275+ g_free (en_name);
276+ }
277+
278+ g_message ("Did not find Aībak");
279+ return FALSE;
280+}
281+
282+int main (int argc, char **argv)
283+{
284+ TzDB *db;
285+ gchar *pixmap_dir;
286+ gboolean retval = TRUE;
287+
288+ setlocale (LC_ALL, "");
289+
290+ if (argc == 2)
291+ {
292+ pixmap_dir = g_strdup (argv[1]);
293+ } else if (argc == 1) {
294+ pixmap_dir = g_strdup ("data/");
295+ } else {
296+ g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
297+ return 1;
298+ }
299+
300+#if !GLIB_CHECK_VERSION(2, 35, 0)
301+ g_type_init();
302+#endif
303+
304+ db = tz_load_db ();
305+
306+ retval = test_pixmaps(db, pixmap_dir) && retval;
307+ retval = test_names(db) && retval;
308+
309 tz_db_free (db);
310 g_free (pixmap_dir);
311
312- return retval;
313+ return retval ? 0 : 1;
314 }
315
316=== modified file 'src/tz.c'
317--- src/tz.c 2013-12-16 17:01:37 +0000
318+++ src/tz.c 2015-12-14 21:59:55 +0000
319@@ -114,6 +114,11 @@
320
321 cc_timezone_location_set_country(loc, parsed_data_v[8]);
322 cc_timezone_location_set_en_name(loc, parsed_data_v[2]);
323+ cc_timezone_location_set_en_name_utf8(loc, parsed_data_v[1]);
324+
325+ gchar **altnames = g_strsplit(parsed_data_v[3], ",", -1);
326+ cc_timezone_location_set_alternate_names(loc, (const gchar **)altnames);
327+ g_strfreev(altnames);
328
329 gchar * tmpState = g_strdup_printf ("%s.%s",
330 cc_timezone_location_get_country(loc),

Subscribers

People subscribed via source and target branches