gpt4 book ai didi

grails - 每个区域的Stripe Grails配置

转载 作者:行者123 更新时间:2023-12-02 14:04:12 26 4
gpt4 key购买 nike

Grails中有没有一种方法可以按语言环境剥离配置?

例如这样:

locale {
fr-FR {
grails.serverURL = "http://www.mysite.fr"
}
en-GB {
grails.serverURL = "http://www.mysite.co.uk"
}
}

我们开始针对多个国家/地区/语言对我们的网站进行国际化,并且某些配置必须针对特定国家/地区。

谢谢

最佳答案

如果配置值是字符串(如上所述),则可以将它们放在message*.properties文件中,而不是Config.groovy中。然后,您可以使用messageSource Spring bean或message标记来检索当前Locale的值。

更新资料

除了下面关于在资源包中混合配置信息的注释之外,另一种方法是以编程方式进行操作-记住Config.groovy是.groovy文件,因此您可以将代码与配置数据混合。类似于以下内容的东西应该起作用:

locale {    
def serverUrls = [Locale.FRANCE: "http://www.mysite.fr",
Locale.UK: "http://www.mysite.co.uk"]

def currentLocale = org.springframework.context.i18n.LocaleContextHolder.locale
def serverlUrl = serverUrls[currentLocale]
assert serverUrl, "no serverUrl found for Locale $currentLocale"

grails.serverURL = serverUrl
}

如果您有多个配置参数要根据区域设置进行更改,则类似以下内容的内容会更整洁
def currentLocale = org.springframework.context.i18n.LocaleContextHolder.locale

switch (currentLocale) {
case Locale.FRANCE:
// config params for France
break;
case Locale.UK:
// config params for UK
break;
}

关于grails - 每个区域的Stripe Grails配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7306299/

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