How to use meta-data for translated strings with lupdate? - qt

The Qt documentation advertises the following syntax to add meta-data to translated strings.
An alternative way to attach meta-data is to use the following syntax:
//~ <field name> <field contents>
This can be used to attach meta-data to the message. The field name should consist of a domain prefix (possibly the conventional file extension of the file format the field is inspired by), a hyphen and the actual field name in underscore-delimited notation. For storage in TS files, the field name together with the prefix "extra-" will form an XML element name. The field contents will be XML-escaped, but otherwise appear verbatim as the element's contents. Any number of unique fields can be added to each message.
Example:
//: This is a comment for the translator.
//= qtn_foo_bar
//~ loc-layout_id foo_dialog
//~ loc-blank False
//~ magic-stuff This might mean something magic.
QString text = MyMagicClass::tr("Sim sala bim.");
Even when I copy the special comments verbatim into the source code, the <extracomment> appears in the .ts file, and the id is added as <message id="qtn_foo_bar">.
As for the meta-data, I would expect new entries in the .ts file, e. g. <extra-loc-layout_id>foo_dialog</extra-loc-layout_id>, but the meta-data doesn't appear at all.
How do I make this work?

Related

Include information from file name (Tag) in output

Using the 'tail' input plugin I'd like to include information from the filename into the message. I can parse the filename (from the tag) and modify it, but not able to include any info from it in the (stdout) output.
Specifying a Path_Key to tail will add the file name to the record. The parser filter can be used to extract information as individual fields.

How to Set a File's Blob Filename?

In a Plone's File content type, which property stores the file's original filename?
I'm using plone.jsonapi.routes to upload files to a plone instance. I can set the id ant the title but I can't set the associated file's filename.
For example, when I upload a file to Plone in the regular way, I can set its id and title, but additionally to that, the original file name is stored somewhere. You can see it here:
objects-essay.pdf - PDF document indicates the name the original file has.
But when I upload it with plone.jsonapi.routes that field is empty. So, I'm trying to figure it out which property stores the name to pass it to the api or to set it by hand.
Thanks.
IIRC, all Archetypes-based content types have a setFilename method that you can use to do this.
On Dexterity-based content types file's content is stored in blobs in the ZODB (instances of NamedBlobFile) and there's a parameter named filename that you can use to set it.
You can see an example of the later in plone.app.contenttypes.

Should RegEx be stored in XML as CDATA or as Attributes?

I am trying to output a RegEx in an xml file as an Attribute.
The problem is that the RegEx generated in the XML output is different than the one i have in Database:
-- database
[a-z0-9!#$%&&apos;*+\/=?^_`{|}~-]+(\.[a-z0-9!#$%&&apos;*+\/=?^_`{|}~-]+)*#([a-z0-9_-]+\.)+(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|[a-z]{2})
-- generated
[a-z0-9!#$%&amp;&apos;*+\/=?^_`{|}~-]+(\.[a-z0-9!#$%&amp;&apos;*+\/=?^_`{|}~-]+)*#([a-z0-9_-]+\.)+(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|[a-z]{2})
Should i save the RegEx as a <![CDATA[ regex ]]> or is this just the default behavior of xml files (encoding some characters and decode them automatically when i read it back) ?
This is the code i have to generate the element:
XElement attr =
new XElement("Attribute",
new XAttribute("RegEx", item.RegularExpression)
);
And this is what it generates:
<Attribute RegEx="[a-z0-9!#$%&amp;&apos;*+\/=?^_`{|}~-]+(\.[a-z0-9!#$%&amp;&apos;*+\/=?^_`{|}~-]+)*#([a-z0-9_-]+\.)+(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|[a-z]{2})" />
The problem is that the regex in the database already uses XML escaping, and when copying it into the XML file, you have added another layer of escaping, so &apos; has become &apos;.
There are two ways of escaping special characters, you can turn & into & as done here, or you can wrap it in CDATA. In this case you don't want to do either, because it is already escaped.
I'm not familiar with link-to-xml so I don't know how to do this correctly in that environment.

How to configure jsdom to preserve tag name case?

Look at these lines:
var doc = jsdom.jsdom("<moshe></moshe>");
console.log(doc.childNodes[0].tagName);
The second line writes "MOSHE" to the console in uppercase that means jsdom recognized my string as HTML and not XML. How can I enforce jsdom to preserve tag name original case?
Thanks in advance.
According to the HTML standard tagName is supposed to be uppercase in a HTML document.
The tagName attribute must run these steps:
If context object's namespace prefix is not null, let qualified name be its namespace prefix, followed by a ":" (U+003A), followed by its local name. Otherwise, let qualified name be its local name.
If the context object is in the HTML namespace and its node document
is an HTML document, let qualified name be converted to ASCII
uppercase.
Return qualified name.
Jsdom currently does not support XML documents (officially), since there's no differentiation internally between a HTML and XML document.
To parse as XML in v1.0+ you have to provide htmlparser2 as the parser, jsdom then implies parsing as XML based on a <?xml directive. This might become unnecessary if #883 gets merged, in which case a parsingMode option will be introduced, which accepts "xml" and switches to a xml parser.
Ultimately, work is underway to go about this problem, however an immediate solution to parsing XML with jsdom is not in sight.

Do *.zcml files get parsed i18n wise?

I have named utilities and would like to mark names for later i18n usage. Is this the right way?
<utility
name="Home"
i18n:attributes="name"
provides=".interfaces..."
factory=".shortcut...." />
The utility's name is not a translatable message id, but an internal technical id. You cannot use it for translation purposes.
If you look at zope.component.zcml you can see the interface for the directive containing:
class IUtilityDirective(IBasicComponentInformation):
"""Register a utility."""
name = zope.schema.TextLine(
title=_("Name"),
description=_("Name of the registration. This is used by"
" application code when locating a utility."),
required=False)
If you look at for example http://wiki.zope.org/zope3/zcml.html it will tell you that an attribute needs to be of type MessageID to be translatable in ZCML.
If you have a ZCML directive with an attribute of type MessageID, all you need to do is to define an i18n:domain for the ZCML file. The ZCML machinery knows what attributes are translatable itself based on them being of the right type. So you don't need any extra markup to note any attributes like you need in TAL.
All that said, if you work inside Plone and use i18ndude to extract messages, it won't extract any messages from ZCML files - simply because there's not a single message being defined in ZCML, that's also actually shown anywhere in the Plone UI.
If you have utilities and want to give them translatable names, give them a title attribute, like:
from zope.i18nmessageid import MessageFactory
_ = MessageFactory('mydomain')
class MyShortCut(object):
title = _('My shortcut')
and use the title attribute in the UI.
You do not want to do that. The name attribute is meant for application use, not end-users, and needs to be stable.
If you translate it, then you'll have to translate all named look-ups through-out your code too!
Titles and descriptions can be translated, using the i18n_domain="domain" marker on the <configure> element.

Resources