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

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



On Fri, Oct 19, 2012 at 12:56 PM, Michal Privoznik <mprivozn redhat com> wrote:
> On 19.10.2012 05:50, Zeeshan Ali (Khattak) wrote:
>> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
>>
>> Attempt to use the localized values of entity params if available before
>> using the non-localized values.
>>
>> This does not yet include custom (ones starting with 'x-') params as I
>> haven't yet figured the right xpath magic to (cleanly) achieve that.
>> Suggestions welcome!
>
> We are again hitting the issue I've mentioned when I was updating the
> RNG files. From XML/XPATH specification it is not possible to regexp
> over element names. Therefore we need to switch to other scheme. We can
> leave the 'x-' prefix, though. Something like:
>   <x-attribute name='foo' value='bar'/>

IIRC I and danpb agreed with your solution?

>> ---
>>  osinfo/osinfo_loader.c | 33 +++++++++++++++++++++++++++------
>>  1 file changed, 27 insertions(+), 6 deletions(-)
>>
>> diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
>> index 934c758..7569262 100644
>> --- a/osinfo/osinfo_loader.c
>> +++ b/osinfo/osinfo_loader.c
>> @@ -219,14 +219,35 @@ static void osinfo_loader_entity(OsinfoLoader *loader,
>>                                   GError **err)
>>  {
>>      int i = 0;
>> +    const gchar * const *langs = g_get_language_names ();
>>
>>      /* 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]);
>> -        gchar *value = osinfo_loader_string(xpath, ctxt, err);
>> -        g_free(xpath);
>> -        if (error_is_set(err))
>> -            return;
>> +    for (i = 0 ; keys[i] != NULL; i++) {
>> +        gchar *value = NULL;
>> +        gchar *xpath;
>> +        int j;
>> +
>> +        /* We are guaranteed to have at least the default "C" locale and we
>> +         * want to ignore that, hence the NULL check on index 'j + 1'.
>> +         */
>> +        for (j = 0; langs[j + 1] != NULL; j++) {
>> +            xpath = g_strdup_printf("string(./%s[lang('%s')])", keys[i], langs[j]);
>> +            value = osinfo_loader_string(xpath, ctxt, err);
>> +            g_free(xpath);
>> +            if (error_is_set(err))
>> +                return;
>> +
>> +            if (value != NULL)
>> +                break;
>> +        }
>> +
>> +        if (value == NULL) {
>> +            xpath = g_strdup_printf("string(./%s)", keys[i]);
>> +            value = osinfo_loader_string(xpath, ctxt, err);
>> +            g_free(xpath);
>> +            if (error_is_set(err))
>> +                return;
>> +        }
>>
>>          if (value) {
>>              osinfo_entity_set_param(entity, keys[i], value);
>>
>
> Again, if an app was querying for 'vendor' attribute, for instance, if
> the DB gets translated the application will not get any result even
> though it was prior this change?

Yes, that is true. Ideally vendor should be a separate entity with an
ID and a name but that will require us to break the API/ABI. I wonder
though if any application using libosinfo (there is only 3 I think) is
doing such a query. If so I suggest we add separate node and prop for
translated vendor name (e.g 'vendor-l10n').

-- 
Regards,

Zeeshan Ali (Khattak)
FSF member#5124


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