Do *.zcml files get parsed i18n wise? - plone

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.

Related

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

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?

How to select the right <category> in RSS? is there a list?

i am noting that in a RSS feed you can add the tag
Source: https://www.w3schools.com/xml/rss_tag_category_item.asp
But I don't undestand one thing: is there a list with all the categories? Or can I write anything? I need a category about videogames
Or can I write anything?
You can write anything.
Unless you're submitting your feed to a directory, with a documented set of categories, it's essentially free text.
However, in RSS:
It has one optional attribute, domain, a string that identifies a categorization taxonomy.
The value of the element is a forward-slash-separated string that identifies a hierarchic location in the indicated taxonomy.
and in Atom:
The "scheme" attribute is an IRI that identifies a categorization
scheme.
you can indicate that your term is from a specific scheme.
In practice, some schema extensions like iTunes introduce a separate element:
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
...
<itunes:category text="Sports">
<itunes:category text="Wilderness"/>
</itunes:category>
rather than suggesting use of the scheme attribute. The iTunes guide currently includes:
<itunes:category text="Leisure">
<itunes:category text="Video Games" />
</itunes:category>

How to handle I18n when texts are not in .properties files but in the jsp page itself

I'm building a multi-languages application with Spring MVC.
So far I handled the multi-languages system with the Spring class ReloadableResourceBundleMessageSource and .properties files. It was easy since texts were very short.
Now, I have to translate the body of the page and I can't rely on .properties files.
I have an Italian version of the page and an english version of the page. My doubt is: how should I handle it?
I thought that after the #Controller return the page name, for example "index", I should have a filter that check the application Locale and then add to the page name a suffix. So, the filter must turn "index" into "it/index" or "en/index".
IS it a good way to solve the issue?
Thank you.
Here's a suggestion with one drawback: I didn't test it with .jsp but .vm. The idea might still work.
As not to break the i18n mechanism put a message key, say parseContent in every language.property file. Now, make a view for every locale and name them, say parse_en_US.vm, parse_de_DE.vm and so on. These files must only contain what you wouldn't want to be in the language.property files.
Example of an entry in messages_en_US.porperties might be parseContent = parse_en_US.vm
An now use #springMessage('parseContent') to get the right view name depending on the present locale. This view you parse as a sub-view and problem solved.
For .vm it looks like this:
#set($view = "#springMessage('parseContent')")
#parse($view)
Same number of .vm files, but no need to invent sth new.

How to customize/localize Assert messages in Symfony2?

When you use #Assert\NotBlank constraint and the given field is empty, then you get the error:
This value should not be blank
I would like to change this message application-wide, without changing Symfony2 source code. How to accomplish that?
Cutomizing validation error messages is quite simple, but can seem tricky at first.
Default locale
First of all you should change the default locale of your application. In versions 2.0.x the correct value to change is framework.session.default_locale. For future reference, starting from 2.1.0 it'll be framework.default_locale. Consult the docs for correct syntax.
A locale should consist of your language and region and is defined as language_REGION (list of languages, list of countries). The locale used in Germany for german would be de_DE for example.
Validation messages
Validation messages are hard coded in their respective constraint classes.
Translating validation messages
Symfony uses Twig to render all the validation messages. The process itself is complicated and falls out of the scope of this question, but the important part is that each constraint message is sent through a translation filter, which depending on the user's locale (default_locale by default) translates the messages to the proper language.
To change any of the translations, simply copy the validation translation file from vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.{lang}.xlf to app/Resources/translations/validators.{lang}.xlf where {lang} is the language part of your default locale.
Having done the former, simply change the default messages to what ever you see more fit. If the language you need support for doesn't exist, copy any translation file to the same directory and modify that file instead.
To read more about how translation works in Symfony2, visit the official documentation on translation.
Additionally to the instructions by gilden, you have to make sure the framework.translator block in config/config.yml is uncommented (it's commented by default nowadays). If you don't do that, you'll still end up with the original English messages.
If anyone has doubts in 2021, here's all I had to do to switch "Error" (eng) constraint message to "Erreur" (fr):
Go to your config/packages/translation.yaml file
Edit it by replacing "en" to "fr" (or your language) :
Test it on your localhost :
Note :
here is the Symfony 5.2 doc I used to help me out
All I did was set a Default_locale (!! not detect where the user comes from !!)

Is there a way to restrict file types on a file field, using AGX tagged values?

Using argo uml and archgenxml, I have a file field. I would like to restrict it to one extension: .ttf
Can I do this using a tagged value?
Also is there a glossary for the AGXProfile which would answer this?
You could try the allowable_content_types mime type property of FileField|ImageFields but I can't find anything that indicates that validation is done on that property. IOW, this wouldn't show the user an error if they uploaded something else. If you want that, you're going to have to write an AT field validator yourself that takes the file and validates it against the mimetype_registry.

Resources