Javascript Orbeon表单本地化使用当前站点';会话语言
我在SAP Commerce(Hybris)内部使用ORBEON 2018.2.3.201905172253 PE。从Orbeon文档和我运行的测试中,我了解到表单本地化通过每个表单中的语言下拉选择器工作。问题是,像往常一样,我已经为我的整个网站设置了一个语言选择器 假设一个用户进入我的网站,默认语言是英语。之后,他将网站的语言改为中文。他正在用中文浏览我的网站,并导航到默认语言为英语的表单。他需要再次使用表单语言选择器将其更改为中文!从用户体验的角度来看,我认为我们都同意这不是一个好主意 我的想法是在加载表单时通过javascript设置表单的语言,使用ajax调用获取当前会话语言。到目前为止,尝试了3种方法,但均无效:Javascript Orbeon表单本地化使用当前站点';会话语言,javascript,localization,hybris,orbeon,xforms,Javascript,Localization,Hybris,Orbeon,Xforms,我在SAP Commerce(Hybris)内部使用ORBEON 2018.2.3.201905172253 PE。从Orbeon文档和我运行的测试中,我了解到表单本地化通过每个表单中的语言下拉选择器工作。问题是,像往常一样,我已经为我的整个网站设置了一个语言选择器 假设一个用户进入我的网站,默认语言是英语。之后,他将网站的语言改为中文。他正在用中文浏览我的网站,并导航到默认语言为英语的表单。他需要再次使用表单语言选择器将其更改为中文!从用户体验的角度来看,我认为我们都同意这不是一个好主意 我的
变量语言代码=
但由于这是2014年的承诺,我想有一种新的方式来实现这一点。当代码运行时,我得到一个JS错误,说FormRunner是一个未定义的对象
设置选择器控件的值:
ORBEON.xforms.Document.setValue(“fr语言选择器”、“fr”);
但它也不起作用
设置DOM属性(有效),然后分派语言更新事件(无效果):
log('language:'+ORBEON.util.Dom.getAttribute(document.documentElement,“lang”));
ORBEON.util.Dom.setAttribute(document.documentElement,“lang”,“fr”);
log('language2:'+ORBEON.util.Dom.getAttribute(document.documentElement,“lang”);
ORBEON.xforms.Document.dispatchEvent(
{
targetId:'fr资源模型',
eventName:“fr更新语言”
}
);
从Orbeon文档中,我可以通过以下方式设置语言:
但是,在表单初始化期间,如何设置fr语言请求参数或会话属性的值
我想知道我是否在实现我想要的目标的正确路径上,如果是的话,我如何在加载表单时/之前切换表单的语言
提前感谢,,
David您可以扩展de.hybris.platforms.proxy.impl.DefaultProxyService
重写URL
方法,并在用户语言上传递ORB,如下所示:
URIBuilder builder = null;
try
{
builder = new URIBuilder(this.orbeonAddress + path);
}
catch (final URISyntaxException e)
{
LOG.error("Error occurred while building the URL : " + e);
throw new MalformedURLException(e.getMessage());
}
// if the original URl had a QueryString...
builder.setQuery(u.getQuery());
// If the form should be embeddable
if (embeddable)
{
builder.addParameter("orbeon-embeddable", "true");
builder.addParameter("fr-language", getCommonI18NService().getCurrentLanguage().getIsocode());
}
final String newURL = builder.toString();
LOG.debug("Rewritten URL [" + newURL + "]");
return newURL;
希望对您有所帮助太棒了,谢谢。这肯定是Hybris ootb的一部分。
<xf:action id="say-hi">
<xf:action event="fr-run-form-load-action-after-controls" ev:observer="fr-form-model"
if="true()"
type="javascript">
ORBEON.xforms.Document.setValue("fr-language-selector", "fr");
</xf:action>
</xf:action>
<xf:action id="say-hi">
<xf:action event="fr-run-form-load-action-after-controls" ev:observer="fr-form-model"
if="true()"
type="javascript">
console.log('language:' + ORBEON.util.Dom.getAttribute(document.documentElement, "lang"));
ORBEON.util.Dom.setAttribute(document.documentElement, "lang", "fr");
console.log('language2:' + ORBEON.util.Dom.getAttribute(document.documentElement, "lang"));
ORBEON.xforms.Document.dispatchEvent(
{
targetId: 'fr-resources-model',
eventName: 'fr-update-language'
}
);
</xf:action>
</xf:action>
URIBuilder builder = null;
try
{
builder = new URIBuilder(this.orbeonAddress + path);
}
catch (final URISyntaxException e)
{
LOG.error("Error occurred while building the URL : " + e);
throw new MalformedURLException(e.getMessage());
}
// if the original URl had a QueryString...
builder.setQuery(u.getQuery());
// If the form should be embeddable
if (embeddable)
{
builder.addParameter("orbeon-embeddable", "true");
builder.addParameter("fr-language", getCommonI18NService().getCurrentLanguage().getIsocode());
}
final String newURL = builder.toString();
LOG.debug("Rewritten URL [" + newURL + "]");
return newURL;