gpt4 book ai didi

带有资源包的 Freemarker - 如何避免转义撇号

转载 作者:行者123 更新时间:2023-12-04 03:20:35 24 4
gpt4 key购买 nike

我正在向这样的模型添加一个资源包:

        Map<String, Object> root = new HashMap<String, Object>();

Locale locale = org.apache.commons.lang3.LocaleUtils.toLocale(request.getLanguage());

BeansWrapper beansWrapper = new BeansWrapperBuilder(Configuration.VERSION_2_3_21).build();

ResourceBundle bundle = ResourceBundle.getBundle("templates/bundles/messages", locale);

root.put("bundle", new ResourceBundleModel(bundle, beansWrapper));

但是,我的 l10n 团队不希望在我的模板中转义撇号(单引号字符),例如:

bundle.value = You''re account is ready!

我可以在我的配置中设置什么来按原样输出文本,避免需要转义单引号吗?

最佳答案

如果您没有 MessageFormat 参数,则不必(实际上不必)转义撇号。例如,如果这是您的 .properties 文件:

m1={0}''s house
m2=Foo''s house
m3=Foo's house

这是你的模板:

${bundle.m1}
${bundle.m2}
${bundle.m3}

${bundle('m1', 'Bar')}

然后这将是输出:

{0}''s house
Foo''s house
Foo's house

Bar's house

如您所见,'' 仅在上一个版本中是必需的。

关于带有资源包的 Freemarker - 如何避免转义撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38627192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com