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. 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.
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?
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.
精彩评论