日期/时间占位符本地化

问题描述

我正在处理 Orbeon 2018 的表单运行器中日期/时间占位符的本地化(尽管这似乎在 2019 年和 2020 年都没有改变)。

我要找的东西定义在orbeon-form-runner.jar\xbl\orbeon\date\date.xbl(还有time/time.xbl,但就目前而言,我觉得讨论就够了第一个)文件,更具体地说:

<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"/> 

占位符变量组装在 html 输入上,这很清楚。

在我的语言中,YYYY、MM、DD 不是日期部分的正确占位符,因此我的要求是根据当前请求区域设置更改它们。

一开始我尝试扩展apps/fr/18n/resource.xml中的标签,然后用xxf:r('components.labels.MM ','|fr-fr-resources|')) 和类似的东西没有任何成功(好吧,占位符已显示,但与我修改前可见的认占位符相同)。

我的第二种方法是将这些标签放在同一个文件中,并以相同的方式引用它们:xxf:r('MM'),没有成功(结果与第一种情况相同)。

我的第三种方法,我现在在这里,是尝试对这些静态内容进行硬编码,并且只针对我的语言环境修复这些标签(使用 xsl:choose),我在这里:我无法找到如何我在这里获取请求语言环境(在 xbl 文件的上下文中)。 变量指向正确的当前请求区域设置(它们显示为“en”)。

你知道如何正确解决这个问题吗?

解决方法

您可以通过 oxf.xforms.format.input.date 属性定义输入格式。并且只能有一种输入格式,不能依赖于当前语言。

在占位符中,组件显示您在 oxf.xforms.format.input.date 中定义的格式,但更改字母 M(月)、D(日)和 Y(年)以匹配当前语言,即通过将 resource 添加到 orbeon-resources 来完成,它当前具有:

<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>