Bug 781634 followup - separate translatable commodity namespace strings from those uses in storage

There is now a separate GNC_COMMODITY_NS_ISO_GUI label to be used
everywhere the users needs to read 'Currency namespace'. It's currently
set to 'Currencies' and can be translated. It may change in to future
to better describe this namespace is restricted to ISO4217 defined
currencies as opposed to all the non-formal currencies in vogue today
(like bitcoin and friends).
This commit is contained in:
Geert Janssens 2017-06-16 20:30:33 +02:00
parent b5b0f60396
commit cc3010d89b
7 changed files with 67 additions and 27 deletions

View File

@ -1660,6 +1660,16 @@ gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
return ns->name;
}
const char *
gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns)
{
if (ns == NULL)
return NULL;
if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
return GNC_COMMODITY_NS_ISO_GUI;
return ns->name;
}
GList *
gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
{

View File

@ -98,14 +98,17 @@ GType gnc_commodity_namespace_get_type(void);
#define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES"
/* The ISO define is deprecated in favor of CURRENCY */
#define GNC_COMMODITY_NS_ISO "ISO4217"
#define GNC_COMMODITY_NS_CURRENCY N_("CURRENCY")
#define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
#define GNC_COMMODITY_NS_NASDAQ "NASDAQ"
#define GNC_COMMODITY_NS_NYSE "NYSE"
#define GNC_COMMODITY_NS_EUREX "EUREX"
#define GNC_COMMODITY_NS_MUTUAL "FUND"
#define GNC_COMMODITY_NS_AMEX "AMEX"
#define GNC_COMMODITY_NS_ASX "ASX"
#define GNC_COMMODITY_NS_NONCURRENCY _("ALL NON-CURRENCY")
#define GNC_COMMODITY_NS_NONCURRENCY _("All non-currency")
/* Delay translation of this one, we use it in both translated and untranslated form
when presenting the currency related namespace to the user */
#define GNC_COMMODITY_NS_ISO_GUI N_("Currencies")
typedef GList CommodityList;
@ -804,6 +807,19 @@ gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBoo
* owned by the engine and should not be freed by the caller. */
const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns) ;
/** Return the textual name of a namespace data strucure in a form suitable to
* present to the user.
*
* @param ns A pointer to the namespace data strucure.
*
* @return A pointer to the gui friendly name of the namespace. This string is
* owned by the engine and should not be freed by the caller.
*
* @notes The returned string is marked for translation, but not translated yet.
* If you want it translated pass the return value on to gettext.
*/
const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns) ;
/** Return a list of all commodity data structures in the specified namespace.
*

View File

@ -605,27 +605,46 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
namespaces = g_list_prepend (NULL, GNC_COMMODITY_NS_CURRENCY);
break;
}
/* First insert "ALL" */
/* First insert "Currencies" entry if requested */
if (mode == DIAG_COMM_CURRENCY || mode == DIAG_COMM_ALL)
{
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
_(GNC_COMMODITY_NS_ISO_GUI), -1);
if (init_string &&
(g_utf8_collate(GNC_COMMODITY_NS_ISO_GUI, init_string) == 0))
{
matched = TRUE;
match = iter;
}
}
/* Next insert insert "All non-currency" entry if requested */
if (mode == DIAG_COMM_NON_CURRENCY_SELECT || mode == DIAG_COMM_ALL)
{
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
GNC_COMMODITY_NS_NONCURRENCY, -1);
}
/* add them to the combobox */
/* add all others to the combobox */
namespaces = g_list_sort(namespaces, collate);
for (node = namespaces; node; node = node->next)
{
if (g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0)
/* Skip template, legacy and currency namespaces.
The latter was added as first entry earlier */
if ((g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0) ||
(g_utf8_collate(node->data, "template" ) == 0) ||
(g_utf8_collate(node->data, GNC_COMMODITY_NS_CURRENCY ) == 0))
continue;
/* Hide the template entry */
if (g_utf8_collate(node->data, "template" ) != 0)
{
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, _(node->data), -1);
}
if (init_string && (g_utf8_collate(node->data, init_string) == 0))
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, node->data, -1);
if (init_string &&
(g_utf8_collate(node->data, init_string) == 0))
{
matched = TRUE;
match = iter;
@ -648,16 +667,11 @@ gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
if (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0)
{
/* In case the user types in ISO4217, map it to CURRENCY. */
/* Map several currency related names to one common namespace */
if ((g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0) ||
(g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
(g_strcmp0 (name_space, _(GNC_COMMODITY_NS_ISO_GUI)) == 0))
return g_strdup(GNC_COMMODITY_NS_CURRENCY);
}
else if (g_strcmp0 (name_space, _(GNC_COMMODITY_NS_CURRENCY)) == 0)
{
/* In case the user entered a translation of CURRENCY, return it untranslated. */
return g_strdup(GNC_COMMODITY_NS_CURRENCY);
}
else
return g_strdup(name_space);
}

View File

@ -596,7 +596,7 @@ gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
{
case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, gnc_commodity_namespace_get_name (name_space));
g_value_set_string (value, _(gnc_commodity_namespace_get_gui_name (name_space)));
break;
default:
g_value_init (value, G_TYPE_STRING);

View File

@ -708,7 +708,7 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
{
case GNC_TREE_MODEL_PRICE_COL_COMMODITY:
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, gnc_commodity_namespace_get_name (name_space));
g_value_set_string (value, gnc_commodity_namespace_get_gui_name (name_space));
break;
case GNC_TREE_MODEL_PRICE_COL_VISIBILITY:
g_value_init (value, G_TYPE_BOOLEAN);

View File

@ -223,8 +223,8 @@ sort_namespace (GtkTreeModel *f_model,
ns_a = gnc_tree_model_commodity_get_namespace (model, &iter_a);
ns_b = gnc_tree_model_commodity_get_namespace (model, &iter_b);
return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
gnc_commodity_namespace_get_name (ns_b));
return safe_utf8_collate (gnc_commodity_namespace_get_gui_name (ns_a),
gnc_commodity_namespace_get_gui_name (ns_b));
}
static gint

View File

@ -205,8 +205,8 @@ sort_ns_or_cm (GtkTreeModel *f_model,
{
ns_a = gnc_tree_model_price_get_namespace (model, &iter_a);
ns_b = gnc_tree_model_price_get_namespace (model, &iter_b);
return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
gnc_commodity_namespace_get_name (ns_b));
return safe_utf8_collate (gnc_commodity_namespace_get_gui_name (ns_a),
gnc_commodity_namespace_get_gui_name (ns_b));
}
comm_a = gnc_tree_model_price_get_commodity (model, &iter_a);