JHipster-在后端获取选定的语言 [英] JHipster - get selected language in the backend

查看:55
本文介绍了JHipster-在后端获取选定的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用数据库中的i18n文本做一个博客应用程序.

I want to do a blog application with i18n text in the database.

如何在后端获得前端选择的语言?

How can I get in the backend the frontend selected language?

JHipster是否提供任何方法来访问后端中的所选语言?

Does JHipster provides any way to access to the selected language in the backend?

谢谢

推荐答案

好,我明白了.我会尝试解释它是否对某人有用.

Ok, I got it. I'll try to explain it if it would be useful for someone.

在JHipster的前端中,该语言由JhiLanguageService管理.

In JHipster's frontend the language is managed by JhiLanguageService.

将其注入要在后端使用i18n的组件的构造函数中:

Inject this in the constructor of a component where you want to use i18n in the backend:

 private languageService: JhiLanguageService

,并在查询调用中添加以下参数:

and in the query call add the following parameter:

language: this.languageService.currentLang

例如:

   this.moviesService.query({
        language: this.languageService.currentLang
    })

然后在后端中,将Locale作为参数添加到RestController中您需要的地方,由于LocaleConfiguration类,您可以在那里选择前端语言.

Then in the backend, add the Locale as a parameter in the RestController where you need it and there you have the front-end selected language thanks to the LocaleConfiguration class.

这篇关于JHipster-在后端获取选定的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆