[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [libosinfo v3 2/4] Load localized values for entity params



On Wed, Oct 24, 2012 at 12:02:29AM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> Use the localized values of entity params if available.
> ---
>  osinfo/osinfo_loader.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
> index a0034f5..d592cf6 100644
> --- a/osinfo/osinfo_loader.c
> +++ b/osinfo/osinfo_loader.c
> @@ -228,14 +228,25 @@ static void osinfo_loader_entity(OsinfoLoader *loader,
>  
>      /* Standard well-known keys first, allow single value only */
>      for (i = 0 ; keys[i] != NULL ; i++) {
> -        gchar *xpath = g_strdup_printf("string(./%s)", keys[i]);
> +        gboolean translatable;
> +
> +        gchar *xpath = g_strdup_printf("string(./%s[ xml:lang])", keys[i]);

If we are looking up the translation from the .mo file, there is no point
in merging translations back into the XML file, this only makes it bigger
(ie slower to download, slower to parse) for no good reason, so I would
make sure that we don't get xml:lang in the xml file. I think gtkbuilder
files look for a 'translatable' attribute on xml nodes.

>          gchar *value = osinfo_loader_string(xpath, ctxt, err);
> +        if (value == NULL) {
> +            translatable = FALSE;
> +            g_free(xpath);
> +            xpath = g_strdup_printf("string(./%s)", keys[i]);
> +            value = osinfo_loader_string(xpath, ctxt, err);
> +        } else
> +            translatable = TRUE;
>          g_free(xpath);
>          if (error_is_set(err))
>              return;
>  
>          if (value) {
> -            osinfo_entity_set_param(entity, keys[i], value);
> +            const gchar *local_value =
> +                (translatable)? g_dgettext(GETTEXT_PACKAGE, value) : value;

You can use the shorter _(value) here instead of calling g_dgettext.

Christophe

Attachment: pgp00MAF4Re9y.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]