Search code examples
orbeon

Date/Time placeholder localization


I am coping with the localization of the Date/Time placeholders in form-runner of Orbeon 2018 (albeit it seems this has not been changed in 2019 and 2020 neither).

What I am looking for is defined in orbeon-form-runner.jar\xbl\orbeon\date\date.xbl (and time/time.xbl, but for now, I think it is enough to discuss the first one) file, more specifically here:

<xf:var
    name="placeholder"
    value="
        let $format      := xxf:property('oxf.xforms.format.input.date'),
            $cleaned     := translate($format, '[01]', ''),
            $duplicate   := replace(replace(replace($cleaned,
                            'M', 'MM'),
                            'D', 'DD'),
                            'Y', 'YYYY'),
            $format-en   := instance('orbeon-resources')/resource[@xml:lang = 'en']/format,
            $format-lang := xxf:r('format'),
            $translated  := translate($duplicate, $format-en, $format-lang)
        return
            $translated
    "/>
<xh:input type="text" placeholder="{$placeholder}" id="input"/> 

The placeholder variable is assembled over the html input, this is clear.

In my language, the YYYY, MM, DD is not the right placeholder for date parts, so my requirement is to change them depending on the current request locale.

At first I tried to extend the labels in the apps/fr/18n/resource.xml, and I replaced the static 'MM', 'DD', etc. constants with xxf:r('components.labels.MM', '|fr-fr-resources|')) and similar things without any success (okay, the placeholder has been displayed, but the same default placeholder that was visible before my modification).

My second approach was to put these labels to the same file, and refer them on the same way: xxf:r('MM'), no success (the same result as in the first case).

My third approach, and I am here now, was to trying to hardcode these static things and only fix these labels for my locale (using an xsl:choose) and here I am: I can't find how on earth could I grab the request locale here (in the context of xbl files). Neither the <xf:var name="lang" value="xxf.instance('fr-language-instance')"/>, nor the <xf:var name="fr-lang" value="xxf.instance('fr-fr-language-instance')"/> variables pointed to the right current request locale (they showed as "en").

Do you have any idea how to solve this properly?


Solution

  • You define the input format through the oxf.xforms.format.input.date property. And there can be only one input format, which can't depend on the current language.

    In the placeholder, the component shows the format you defined through in oxf.xforms.format.input.date, but changing the letter M (month), D (day), and Y (year) to match the current language, and that is done by adding a resource to orbeon-resources, which has currently:

    <resource xml:lang="en"><format>MDY</format></resource>
    <resource xml:lang="fr"><format>MJA</format></resource>
    <resource xml:lang="de"><format>MTJ</format></resource>
    <resource xml:lang="pl"><format>YMD</format></resource>