Tag: 语言环境

Spring Boot Controller语言环境不随参数更改

我在使用Kotlin的Spring Boot来处理区域设置时遇到了一些麻烦。 我在我的application.properties文件中创建了这些设置: spring.messages.basename=messages/messages spring.messages.cache-seconds=-1 spring.messages.encoding=UTF-8 然后在我的控制器中创建一个MessageSource的自动装配实例: @Autowired lateinit var messageSource: MessageSource 当把url中的语言环境作为参数时,当我调用LocaleContextHolder.getLocale()时,这个参数似乎没有被拾取,所以它总是en_US。 虽然,我可以使用@RequestParam(value="locale") locale: Locale作为我的控制器函数的一个参数手动提取,并在控制器函数中使用它,但不能在其他函数中使用它。 我认为,春季启动LocaleContextHolder应该保持当前的区域设置基于请求的URL自动为整个会话。 我读了一篇较老的文章,提到在主类中使用LocaleChangeInterceptor bean以及MessageSource和LocaleResolver的bean,但另一篇文章则说Spring Boot并不需要这样做。 无论如何,我尝试了没有区别。 这些是我使用的功能: @Bean open fun localeResolver(): LocaleResolver { val slr = SessionLocaleResolver() slr.setDefaultLocale(Locale.US) return slr } @Bean open fun localeChangeInterceptor(): LocaleChangeInterceptor { val localeChangeInterceptor = LocaleChangeInterceptor() localeChangeInterceptor.paramName = "locale" return localeChangeInterceptor } @Bean open fun […]

以印度编号格式显示货币

我有一个关于格式化卢比货币(印度卢比 – INR)的问题。 通常450500的值被格式化并显示为450,500 。 在印度,同样的价值显示为4,50,500 例如,这里的数字表示为: 1 10 100 1,000 10,000 1,00,000 10,00,000 1,00,00,000 10,00,00,000 参考印度编号系统 分隔符在两位数之后,除了最后一组,数以千计。 我在互联网上搜索和人们已经要求使用语言环境en_GB或模式#,##,##,##,##0.00 我试图通过使用下面的标记JSTL: <fmt:formatNumber value="${product.price}" type="currency" pattern="#,##,##,##,###.00"/> 但是这似乎并没有解决这个问题。 任何帮助在这个问题将不胜感激。 谢谢

“Kotlin”编程中的语言更改语言环境由于语言环境适用于Java Fine,但Kotlin语言不起作用

我在应用程序中使用kotlin语言,并在更改语言环境时遇到一些困难。 正如我已经做了,我已经创建了一个全球性的类,即在Java和这个类上,我已经写了语言改变语言环境代码的代码和语言代码函数我打电话给基础应用程序类在我的项目是在Kotlin。 这是我的源代码: 全局类(Java代码) public void changelanguage(Context context) { Locale locale = Locale.getDefault(); Locale.setDefault(locale); System.out.println("GlobalLocale" +locale.toString()); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } 基本申请分类代码:( Kotlin) class CrashApplicationClass : Application() { val TAG = CrashApplicationClass::class.java.simpleName lateinit var sDefSystemLanguage: String val gc = GlobalClass.getInstance() override fun onCreate() { // TODO Auto-generated method stub […]