#924 ✓resolved
Matthias Kurz

Fixes for internationalization and fallbacks when retrieving messages

Reported by Matthias Kurz | June 20th, 2011 @ 01:01 PM | in 1.3 (closed)

Framework version: 1.2.x branch
Platform you're using: Ubuntu 11.04

Details:

Play accepts locales with country codes (e.g. "fr_FR") from the "Accept" http header as well as in the application.langs key in application.conf.
But this doesn't work well at the moment.

I fixed some bugs relating these issues and some more bugs relating internationalisation:

  • Fixed LocaleBinder to now correctly accept locales containing a country (e.g. "fr_FR"). The current implementation never worked.
    And now LocaleBinder returns null when it couldn't bind a Locale (and not Locale.getDefault like before). See documentation: "Note that if the parameter is missing in the HTTP Request, or if automatic conversion fails, Object types will be set to null and native types will be set to their default values."

  • Fixed Lang.getLocale() to accept locales containing a country (e.g. "fr_FR")

  • Fixed the non-argument version of the format() java extension to use the current locale to translate month and week day names.

    Reproduction steps
    In application.conf:

    application.langs=de
    date.format.de=dd.MMMM.yyyy
    
    in a view:
    ${new Date(2011-1900,0,1,20,10).format()}
    

    The month should be displayed in german, but it isn't.
    It seems other people had problems with this before: https://groups.google.com/group/play-framework/browse_thread/thread...

  • Fixed all asdate() and format() java extensions to correctly translate month and week day names when using locales containing country codes (e.g. "fr_FR")
    As you can define locales in application.conf like "de_DE", "fr_FR", etc. these extensions should take care for the country too.

    Reproduction steps
    In application.conf:

    application.langs=fr_FR
    date.format.fr_FR=dd.MMMM.yyyy
    
    in a view:
    ${new Date(2011-1900,0,1,20,10).format('dd MMMM yyyy hh:mm:ss')}
    ${new Date(2011-1900,0,1,20,10).format('dd MMMM yyyy hh:mm:ss', play.i18n.Lang.get())}
    ${1263910970000.asdate('dd MMMM yyyy hh:mm:ss')}
    

    Result: The month names never get translated.

  • Added a non-argument version of the asdate() Java extension as equivalent to the non-argument version of .format()

    Reproduction steps
    When using eg.

    ${1263910970000.asdate()}
    

    in a view you get a "Template execution error" with a "MethodSelectionException"

  • Enhanced the way Messages.getMessage() and Messages.all() retrieve messages:
    Now fallbacks from specific message files to more general message files occur.
    E.g. when defining "fr_FR" and "fr" in application.langs in the application.conf. A key is looked up first in messages.fr_FR, if not found in messages.fr, if not found in messages, if not found in the play defaults message file defined in PLAY_HOME/resources/messages (which at the moment contain the since.* and validation.* keys) This enhancement also addresses bug 499 (http://play.lighthouseapp.com/projects/57987/tickets/499-should-be-...) and this discussion on the mailing list: https://groups.google.com/group/play-framework/browse_thread/thread...

  • Added "fr_FR" and "fr_BE" as comment for the application.langs key in the default application.conf. This should make it more obvious that and how it's possible to also use locales containing country codes when creating a new project.

It would be great if this will make it in 1.3!

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2>Play framework</h2>

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the <a href="http://www.playframework.org">http://www.playframework.org</a> website.<br><br>

<h2>Source code is hosted on github</h2>Check out our repository at <a href="http://github.com/playframework/play">http://github.com/playframework/play</a><br><br>

<h2>Contributing, creating a patch</h2> Please read the <a href="http://play.lighthouseapp.com/projects/57987/contributor-guide">contributor guide</a><br><br>

<h2>Reporting Security Vulnerabilities</h2> Since all bug reports are public, please report any security vulnerability directly to <em>guillaume dot bort at gmail dot com</em>.<br><br>

<h2>Creating a bug report</h2> Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.<br><br>

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.<br><br>

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.

Tags

Referenced by

Pages