Trying to use primefaces calendar with localization. I thought about adding the javascript properties array into the corresponding locale message properties file.
http://code.google.com/p/primefaces/wiki/PrimeFacesLocales
primefacesLocale=PrimeFaces.locales['de'] = \u007B closeText: 'Schlie\u00DFen', prevText: 'Zur\u00FCck', nextText: 'Weiter', {0} weekHeader: 'Woche', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: '', timeOnlyTitle: 'Nur Zeit', timeText: 'Zeit', hourText: 'Stunde', minuteText: 'Minute', secondText: 'Sekunde', currentText: 'Aktuelles Datum', ampm: false, month: 'Monat', week: 'Woche', day: 'Tag', allDayText: 'Ganzer Tag'\u007D;
Using it like:
<script type="text/javascript">
<h:outputFormat value="#{msg.primefacesLocale}" escape="false">
<f:param value="test"/>
</h:outputFormat>
</script>
Month- and weekday names should be retrieved via el functions, test value is just for testing
Results in:
java.lang.IllegalArgumentException: can't parse argument number: closeText: 'Schließen'
at java.text.MessageFormat.makeFormat(MessageFormat.java:1420)
at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
at java.text.MessageFormat.<init>(MessageFormat.java:381)
at com.sun.faces.renderkit.html_basic.OutputMessageRenderer.encodeEnd(OutputMessageRenderer.java:113)
Whats wrong here?
Edit:
Using: <h:outputText value="#{msg.primefacesLocale}" escape="false"> works fine.
The
MessageFormatAPI has some special characters. The{,}and'. The{and}represents the start and end of format argument index. The'is an escape character (like as\is in strings).The
\u007Bwhich you’ve there in the beginning represents the{. It should actually have been escaped by surrounding it with'. The same for the ending\u007Dwhich represents the}.You can by the way also just put those
{and}plain vanilla in the string.Note: as said, the
'is an escape character, if you want to represent it as-is, use two of them.This is in turn however invalid JSON. The string keys and values should be doublequoted (although most webbrowsers are forviging in this).