Skip to content

Commit 3aa36e0

Browse files
author
Iain Lane
committed
component: Don't strip ";" from keywords before translating them
We're failing to translate strings now, when the keywords ends with a ";" as they almost always do, e.g.: Keywords=Drivers;Repositories;Repository;PPA; because we strip the trailing semicolon off before translating, in order to avoid having empty elements in the output. Instead what we can do is process the list passed to `as_component_set_keywords` and remove empties at that point. This allows us to not modify the string retrieved from the desktop file, and fixes finding translations.
1 parent aaac0fe commit 3aa36e0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/as-component.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -1301,14 +1301,25 @@ void
13011301
as_component_set_keywords (AsComponent *cpt, gchar **value, const gchar *locale)
13021302
{
13031303
AsComponentPrivate *priv = GET_PRIVATE (cpt);
1304+
g_autoptr(GPtrArray) keywords = NULL;
13041305

13051306
/* if no locale was specified, we assume the default locale */
13061307
if (locale == NULL)
13071308
locale = as_component_get_active_locale (cpt);
13081309

1310+
keywords = g_ptr_array_new ();
1311+
1312+
if (value != NULL) {
1313+
for (guint i = 0; value[i] != NULL; ++i) {
1314+
if (g_strcmp0 (value[i], "") != 0)
1315+
g_ptr_array_add (keywords, g_strdup (value[i]));
1316+
}
1317+
}
1318+
g_ptr_array_add (keywords, NULL);
1319+
13091320
g_hash_table_insert (priv->keywords,
13101321
g_ref_string_new_intern (locale),
1311-
g_strdupv (value));
1322+
(gchar **) (g_ptr_array_steal (keywords, NULL)));
13121323

13131324
g_object_notify ((GObject *) cpt, "keywords");
13141325
}

src/as-desktop-entry.c

-8
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ as_desktop_entry_parse_data (AsComponent *cpt,
468468
g_auto(GStrv) kws = NULL;
469469
g_autoptr(GPtrArray) l10n_data = NULL;
470470

471-
/* drop last ";" to not get an empty entry later */
472-
if (g_str_has_suffix (val, ";"))
473-
val[strlen (val) -1] = '\0';
474-
475471
kws = g_strsplit (val, ";", -1);
476472
as_component_set_keywords (cpt, kws, locale);
477473

@@ -483,10 +479,6 @@ as_desktop_entry_parse_data (AsComponent *cpt,
483479
const gchar *e_locale = g_ptr_array_index (l10n_data, j);
484480
gchar *e_value = g_ptr_array_index (l10n_data, j + 1);
485481

486-
/* drop last ";" to not get an empty entry later */
487-
if (g_str_has_suffix (e_value, ";"))
488-
e_value[strlen (e_value) -1] = '\0';
489-
490482
e_kws = g_strsplit (e_value, ";", -1);
491483
as_component_set_keywords (cpt, e_kws, e_locale);
492484
}

0 commit comments

Comments
 (0)