Play framework localisation is not working in production - scala

If I run my play framework application with "play run" the localisation is fine. But if I do a "play dist" then use the start command, then the original English messages appear.
I have found, that if I change the classpath order in the start script putting the jar containing my messages file to the first place, then the localisation is fine.
Is there any better way to do this?
It is the same, if I copy the conf/messages to conf/messages.hu and set application.langs="hu" in the application.conf.
And stays the same, if I change my browser settings, so this is in the request header: "Accept-Language:hu,en-US;q=0.8,en;q=0.6". Still English messages (only, if they are the built in keys. My custom keys are translated correctly).

We have figured it out.
There is a custom field constructor used. My assumption was, that it is using the implicit lang parameter, but this is not the case. The lang must be given to the elements.errors() as parameter, and the current lang setting is stored in the elements.lang attribute. This is stated in the documentation, but we missed it. So the implicit lang parameter should not be used in the field template, because it contains wrong value.
The solution was this: #elements.errors(elements.lang)
#elements.input
<span class="errors">#elements.errors(elements.lang).mkString(", ")</span>

Related

Is "health.config.enabled" still being processed, and where?

Is the property "health.config.enabled" still valid and being processed in current Spring Cloud?
If yes, where in the code it is being done?
The property is in the current official documentation and has worked well for me so far (in cloud clients).
But as a whole string, it cannot be found anywhere in the current source code (besides the doc source).
For me as a beginner, it was easy to find in the old version of ConfigClientAutoConfiguration.java
Recent version of ConfigClientAutoConfiguration.java does not contain that whole property name, although I guess it's still being processed but in a more abstract way that I don't understand yet. Thus I'd appreciate even a hint in the form of "what used to be done on line "#ConditionalOnProperty(value = "health.config.enabled", matchIfMissing = true)" before is now roughly done on line XY".
Thanks.
It is replaced by #ConditionalOnEnabledHealthIndicator("config") (see here).
From the javadoc for that annotation
Blockquote
#Conditional that checks whether a default health indicator is enabled. Matches if the value of the management.health.<name>.enabled
So the new property is management.health.config.enabled

Apache Wicket event on Page "page was mouted on ..."

I have mount Page in this form (with one predefined parameter):
mountPage("/lista/${variant}", StronaEntityV2.class);
when parameter "variant" is given all is OK. But when parameter is absent (is OK too from application point of view) URL is build in form
wicket/bookmarkable/all....package...StronaEntityV2?8
It is ok too, but I will know that situation. In simple situation (with one predefined parameter) checking parameter is good, but in more complicated isn't so simple (and must maintain code in distinct places).
My ideal imaged solution is event
page.OnPageIsMountedOn(URL to_me)
I will accept wide range of solutions.
FORMAL: please integrate synonyms on tags wicket-1.6 & wicket-6, and create new wicket-7
Your page is configured to listen to /lista/${variant}.
When you do: setResponsePage(StronaEntityV2.class, paramsWithVariant) then Wicket will use the mount point and produce: /lista/variantValue.
But if you do: setResponsePage(StronaEntityV2.class), i.e. no PageParameters provided, then Wicket will ignore /lista/${variant} (because it doesn't match) and will produce a "default" page url, i.e. /wicket/bookmarkable/com.example.StronaEntityV2.
So the application controls which url should be used.
You can use optional parameter placeholder: /lista/#{variant}. Note that I use # instead of $ now. This way Wicket will produce /lista/ when there is no variant parameter provided. In the page constructor you will know that the url is always "/lista" but the parameter may be null, so better use: pageParameters.get("variant").toXyz(defaultValue) or .toOptionalXyz().

LibXML: Comment-out a block of Elements

IS there a way to add/initate a comment ( e.g. $dom->createComment ... ) such that it comments out an entire block of xml tags. Basically I want to turn-off the content between the comment.
For example, it would look like this:
<TT>
<AA>keep</AA>
<!-- comment to blocking
<BB>hideme1</BB>
<CC>hideme2</CC>
-->
<DD>d's content is good</DD>
</TT>
Actually this question is a pre-cursor to my attempt to figure-out a method to be able to markup/label/identify the changes to an xml files in support of new client software functionality, but be able to have the ability to remove / back-out these xml changes in the rare event the client needs to fall back to the previous software version (and no I can't just simply point back to the original xml file because the client is allowed to make minor modifications to existing node text values). This is all going to be controlled via a perl script and LibXML's core modules (I can't use modules the client doesn't have).
So basically I've identified three possible types of xml changes as a result of new client sw functionality:
1.) ADD new element node(s) (typically to support new sw functionality)
2.) DELETE element node(s), or blocks of (would be rare, but never-the-less a possibility)
3.) CHANGE node text values (rare, but the new sw may require a new value)
For all three types, the client needs the ability to back out the changes. One thing I was thinking to use is ATTRIBUTES since the existing xml files don't use them. For example, for an ADD change type, I could include an atribute like 'ADD="sw version 4.1"' . This way if it needs to be removed, I could just simply have the perl script find those attribute strings and delete them (using LibXML methods). Same thing with CHANGE change type - I could use an attribute like CHG="newvalue_oldvalue", then again use straight perl (or LibXML) to switch back the value based on the contents of the attribute. The DELETE change type is giving me a problem though (as welll as the others lol!). I want to be able to "keep" the deleted lines in the xml file soley for the purposes if the sw falls back a version (at some late point the perl script could eventually cleanup/delete them).
I know this is a lot, I'm new to LibXML (but not to perl). I was just wonder if any of you have any thoughts as to how to go about it or seen anything resembling this kind of request ... I'd be grateful for any kind of advice! Thank you...

GWT i18n - Plural Forms doesn't work at all?

I'm using GWT internationalization Messages. The documentation for Plural Forms says this should work:
#DefaultMessage("{0} {1,number} hours {2}")
#PluralText({"one", "an hour"})
String hours(String prefix, #PluralCount int count, String suffix);
Well, it doesn't. Whatever value of count it still delivers DefaultMessage (e.g. "1 hours ago"). Same if I use a .properties file:
hours[one]=an hour
hours[few]=some hours
hours={0} {1,number} hours {2}
Is there a bug in the docs or in GWT (I'm using GWT 2.0.3) or in me? If any of the two former, anyone knows of a workaround?
EDIT: More clues to this mystery. I can get plural handling to work if I don't rely on default locale handling. That is, I need:
In my module's gwt.xml file:
<extend-property name="locale" values="en"/>
In my Messages extentsion:
#DefaultLocale("en")
public interface MyMessages extends Messages { ...
Explicitly load the "en" locale by appending to the URL
&locale=en
See http://groups.google.com/group/google-web-toolkit/browse_thread/thread/80ae300213cc6adb where I have cross posted this question.
EDIT 2: The reason I entered this GWT plurals land is that I'm creating a "GWT HUman Readable Relative Timestamps" module. Open sourced at GitHub: http://github.com/PEZ/GWT-Relative-Time Please check it out. It'll very soon have correct singular forms and support for some languages. =)
Also I think it will save people time to know that the default English plural rule only supports "other" and "one".
DefaultRule_en.java uses DefaultRule_1_0n.java
So you have to redefine DefaultRule_en.java if you want to use "none","two",few"...
You can see the available rules in the package com.google.gwt.i18n.client.impl.plurals.
Getting used to answering my own questions =) Here's cross post of my "answer" on the GWT Google group:
There seems to be a bug with the default locale handling. Here's how I have reached that conclusion:
I wanted to add some locales to my module. Figured I could get a boiler plate for the properties file if I used the #Generate annotation. I noticed that it created both an _en.properties file and a _default.properties. What's more; the _en file completely lacked the plural form info! The _default file had them though.
I then moved the _defaults file to the same directory as my TimeMessages.java file and renamed it TimeMessages_default.properties.
With this in place I can remove <extend-property name="locale" values="en"/> from my module's .gwt.xml file and, more important, the &locale=en from the URL when running my app. I still need the #DefaultLocale("en") annotation though, even though the documentation clearly states that this is not necessary.
In conclusion, if you run into this problem, try:
generating properties files using #Generate
place YourMessages_default.properties side by side with YourMessages.java
prepend the YourMessages interface with a #DefaultLocale("en") annotation.
About that #Generate. This is what worked for me. Just before my extension of the Message interface:
#Generate(format = {"com.google.gwt.i18n.rebind.format.PropertiesFormat"})
The GWT log said it created my properties file, but I couldn't find it. I fixed that by adding the compiler flag -extra extras and then found the properties files generated in the extras directory. Including this info here since I spent more than an hour figuring it out.
Another solution from the gwt issue list here:
You have to define the #DefaultLocale in the MyMessages.java:
#DefaultLocale("en")
public interface MyMessages extends Messages {
public String items(#PluralCount #Optional int count);
}
and in MyMessages.properties:
items={0} items
items[one]=one item
One more thing I found is that you can define a fallback locale like this:
<set-property-fallback name="locale" value="en"/> in your module XML file

Query with toLocalizedTime in Plone

I'm using toLocalizedTime to output a date, as below
<span tal:content="python:here.toLocalisedTime(date.get('start_date'))"/>
This outputs eg. 2007/08/02, I'm just curious as to how one would alter the output so that it reads 02/08/2007
I'm not having much luck finding much info on toLocalizedTime, would someone point me in the right direction?
This depends on whether you have English selected as the site language (Site Setup >> Language). If so, then the default settings are used. You can change the defaults by dropping down into the ZMI, then into 'portal_properties', then 'site_properties'. The fields to change are either 'localTimeFormat' or 'localLongTimeFormat' depending on whether you pass in 'long_format=1' to the toLocalisedTime function.
If on the other hand, you have translations set up, the format may instead be pulled from the translation file for the locale selected. I'm not sure what is the easy way to change the format in this case (other than switching the site back to English). I guess you can register your own translation file but I've never needed to do that so you're going to have to look up the details.
Date string formatting follows the Python rules (http://docs.python.org/library/time.html#time.strftime).
Perhaps even more detail than you need:
here.toLocalizedTime()
is defined in the plone browser view at...
CMFPlone/browser/ploneview.py
which looks up the 'translation_service' utility, to call its 'ulocalized_time' function, defined at...
CMFPlone/TranslationServiceTool.py
which itself calls the 'ulocalized_time' function defined at...
CMFPlone/i18nl10n.py
As always, you can learn interesting things by grepping the source code ;-)
For an up to date answer for Plone 4.3 (after going through the source code)
These fields are now in the registry found at:
http://localhost:8080/yoursite/portal_registry
Then filter on "i18nl10n", which should give you the 4 fields you need to change.