我正在尝试localization
为用户定义的输入构建一个。示例:用户可以定义足球等类别,但可以使用多种语言。
模型实体可能有这样的文件:
@ManyToMany
@MapKeyColumn(name = "locale", insertable = false, updatable = false)
public Map<String, L18n> titles;
我想像这样存储本地化的字符串:
@Entity
public class L18n {
@Id
@Constraints.Required
@Formats.NonEmpty
public Integer id;
public String key;
public String locale;
@Column(columnDefinition = "TEXT")
public String text;
}
我们使用yaml来存储测试数据:
category:
- !!models.Category
...
titles:
- !!models.L18n
key: soccer
l18n:
- !!models.L18n
key: soccer
locale: de-CH
text: fdfdfsee
- !!models.L18n
key: soccer
locale: fr-CH
text: dlfkjsdlfj
使用此解决方案,我收到此错误:
[error] Caused by: org.yaml.snakeyaml.error.YAMLException: No suitable constructor with 1 arguments found for interface java.util.Map
[error] at org.yaml.snakeyaml.constructor.Constructor$ConstructSequence.construct(Constructor.java:574)
[error] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
[error] at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:296)
[error] ... 65 more