[英]Best practice for entities localization in java spring web applications
i am seeking for the best way to localize dynamic(user generated) content on my web. 我正在寻找在我的网站上本地化动态(用户生成的)内容的最佳方法。 I am using spring-mvc which i found very good framework but now i need to make several entities available in multiple languages. 我正在使用spring-mvc,我发现它非常好的框架,但现在我需要使用多种语言提供多个实体。 I found out that for static texts i18n is best way which i agree but if i understood it right it can't be used to localize something stored in database. 我发现对于静态文本i18n是我同意的最佳方式,但如果我理解它,它不能用于本地化存储在数据库中的东西。
There for i have to store both localized and original content within database and now i need to know what is the best way to do so for example i have entity : 因为我必须在数据库中存储本地化和原始内容,现在我需要知道这样做的最佳方式是什么,例如我有实体:
@Entity
public class Article {
private Long id;
private String title;
private String body;
}
how should it look if i want it to support localization? 如果我希望它支持本地化,应该怎么看?
@Entity
public class Article {
private Long id;
@OneToMany
private Set<LocalizedTitle> localizedTitles;
private String body;
}
i don't like this solution tbh but i can't come up with a better way that's why i am coming to this place ... may be there is something built in in jpa/hibernate that i can use? 我不喜欢这个解决方案,但是我无法想出一个更好的方法,这就是为什么我要来这个地方...可能有jpa / hibernate内置的东西,我可以使用?
Thank you for your help 谢谢您的帮助
I would make the whole article localizable: 我会使整篇文章可以本地化:
Article container: 物品容器:
@Entity
public class Article{
@Id
private Long id;
@OneToMany(mappedBy="container")
private Set<LocalizedArticle> localizedArticles;
}
Localized versions: 本地化版本:
@Entity
public class LocalizedArticle{
@ManyToOne
private Article container;
@Id
private Long id;
private String body;
private String title;
private String locale;
}
And in your queries, you would look up the localized versions by locale. 在查询中,您将按区域设置查找本地化版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.