[libvirt] [PATCH 1/2] virsh: use more compact VIR_ENUM_IMPL

Eric Blake eblake at redhat.com
Mon Feb 24 17:49:22 UTC 2014


On 02/24/2014 10:42 AM, Michal Privoznik wrote:

>>
>> +VIR_ENUM_DECL(vshDomainIOError)
>> +VIR_ENUM_IMPL(vshDomainIOError,
>> +              VIR_DOMAIN_DISK_ERROR_LAST,
>> +              N_("no error"),
>> +              N_("unspecified error"),
>> +              N_("no space"))
>> +

>> -    return _("unknown error");
>> +    const char *str = vshDomainIOErrorTypeToString(error);
>> +    return str ? _(str) : _("unknown error");
>>   }
>>
> 
> Why _(str) if str itself already contains translated message?

str is NOT translated.  C semantics forbid initializing something with a
function call, and VIR_ENUM_IMPL is creating an initializer.  N_() is a
markup that is a no-op to the C compiler (so you aren't violating
initializer rules) while still marking a string for translation for the
purposes of xgettext scanning; we still have to actually translate the
string at some point down the road.  Hence, my call to _(str) - where we
are translating a string, but where xgettext sees that it is a variable
rather than a string literal and so has nothing it can stick in the .po
file.  You need both halves for translating strings that are stored in
an initializer list.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140224/68a00d96/attachment-0001.sig>


More information about the libvir-list mailing list