Skip to content

Commit 62f418f

Browse files
authored
Add German validation messages (#511)
* Fix grammatic error in validation message text * Add German translation for validation messages
1 parent 8fce164 commit 62f418f

File tree

3 files changed

+80
-37
lines changed

3 files changed

+80
-37
lines changed

src/main/resources/jsv-messages.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ unionType = {0}: {1} found, but {2} is required
3232
uniqueItems = {0}: the items in the array must be unique
3333
uuid = {0}: {1} is an invalid {2}
3434
id = {0}: {1} is an invalid segment for URI {2}
35-
exclusiveMaximum = {0}: must have a exclusive maximum value of {1}
36-
exclusiveMinimum = {0}: must have a exclusive minimum value of {1}
35+
exclusiveMaximum = {0}: must have an exclusive maximum value of {1}
36+
exclusiveMinimum = {0}: must have an exclusive minimum value of {1}
3737
false = Boolean schema false is not valid
3838
const = {0}: must be a constant value {1}
3939
contains = {0}: does not contain an element that passes these validations: {1}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
additionalProperties = {0}.{1} ist nicht im Schema definiert und das Schema verbietet 'additionalProperties'
2+
allOf = {0} muss gültig für alle Schemata {1} sein
3+
anyOf = {0} muss gültig für mindestens ein Schema {1} sein
4+
crossEdits = {0}: Ein Fehler mit 'cross edits' ist aufgetreten
5+
dependencies = {0} hat einen Fehler mit Abhängigkeiten {1}
6+
dependentRequired = {0} fehlt eine Eigenschaft, welche 'dependentRequired' {1} ist
7+
dependentSchemas = {0}: Ein Fehler mit 'dependentSchemas' {1} ist aufgetreten
8+
edits = {0}: Ein Fehler mit 'edits' ist aufgetreten
9+
enum = {0}: Ein Wert in der Aufzählung {1} fehlt
10+
format = {0} muss dem Format {1} entsprechen {2}
11+
items = {0}[{1}]: kein Validator an diesem Index gefunden
12+
maximum = {0} darf den Wert {1} nicht überschreiten
13+
maxItems = {0}: Es dürfen höchstens {1} Elemente in diesem Array sein
14+
maxLength = {0} darf höchstens {1} Zeichen lang sein
15+
maxProperties = {0} darf höchstens {1} Eigenschaften haben
16+
minimum = {0} muss mindestens den Wert {1} haben
17+
minItems = {0} es müssen mindestens {1} Elemente in diesem Array sein
18+
minLength = {0} muss mindestens {1} Zeichen lang sein
19+
minProperties = {0} muss mindestens {1} Eigenschaften haben
20+
multipleOf = {0} muss ein Vielfaches von {1} sein
21+
notAllowed = {0}.{1} ist nicht erlaubt und darf folglich nicht auftreten
22+
not = {0} soll nicht gültig sein für das Schema {1}
23+
oneOf = {0} darf nur für ein einziges Schema {1} gültig sein
24+
patternProperties = {0} stimmt nicht überein mit dem Format definiert in 'pattern properties'
25+
pattern = {0} stimmt nicht mit dem regulären Ausdruck {1} überein
26+
properties = {0}: Ein Fehler mit 'properties' ist aufgetreten
27+
readOnly = {0} ist ein schreibgeschütztes Feld und kann nicht verändert werden
28+
$ref = {0}: Ein Fehler mit 'refs' ist aufgetreten
29+
required = {0}.{1} ist ein Pflichtfeld aber fehlt
30+
type = {0}: {1} wurde gefunden aber {2} erwartet
31+
unionType = {0}: {1} wurde gefunden aber {2} wird verlangt
32+
uniqueItems = {0} die Elemente des Arrays müssen einmalig sein
33+
uuid = {0}: {1} ist ein ungültiges {2}
34+
id = {0}: {1} ist ein ungültiges Segment für die URI {2}
35+
exclusiveMaximum = {0} muss größer sein als {1}
36+
exclusiveMinimum = {0} muss kleiner sein als {1}
37+
false = Boolean schema false is not valid
38+
const = {0} muss den konstanten Wert {1} annehmen
39+
contains = {0} beinhaltet kein Element, das diese Validierung besteht: {1}
40+
propertyNames = Eigenschaftsname {0} ist ungültig für die Validierung: {1}

src/test/java/com/networknt/schema/Issue471Test.java

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,63 @@
1111
import java.util.Locale;
1212
import java.util.Map;
1313
import java.util.Set;
14+
import java.util.stream.Collectors;
1415

1516
public class Issue471Test {
17+
private final String DATA_PATH = "/data/issue471.json";
18+
private final String SCHEMA_PATH = "/schema/issue471-2019-09.json";
1619

17-
private JsonSchema getJsonSchemaFromStreamContentV201909(InputStream schemaContent) {
18-
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
19-
return factory.getSchema(schemaContent);
20-
}
21-
22-
private JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
23-
ObjectMapper mapper = new ObjectMapper();
24-
return mapper.readTree(content);
25-
}
26-
27-
// Only one test method is allowed at a time
20+
// Only one test method is allowed at a time as the ResourceBundle is statically initialized
2821

2922
@Test
3023
@Disabled
3124
public void shouldFailV201909_with_enUS() throws Exception {
3225
Locale.setDefault(Locale.US);
33-
Set<ValidationMessage> errors = validate();
34-
Map<String, String> errorMsgMap = transferErrorMsg(errors);
35-
Assertions.assertTrue(errorMsgMap.containsKey("$.title"), "error message must contains key: $.title");
36-
Assertions.assertTrue(errorMsgMap.containsKey("$.pictures"), "error message must contains key: $.pictures");
37-
Assertions.assertEquals("$.title: may only be 10 characters long", errorMsgMap.get("$.title"));
38-
Assertions.assertEquals("$.pictures: there must be a maximum of 2 items in the array", errorMsgMap.get("$.pictures"));
26+
Map<String, String> errorsMap = validate();
27+
Assertions.assertEquals("$.title: may only be 10 characters long", errorsMap.get("$.title"));
28+
Assertions.assertEquals("$.pictures: there must be a maximum of 2 items in the array", errorsMap.get("$.pictures"));
3929
}
4030

4131
@Test
4232
@Disabled
4333
public void shouldFailV201909_with_zhCN() throws Exception {
4434
Locale.setDefault(Locale.CHINA);
45-
Set<ValidationMessage> errors = validate();
46-
Map<String, String> errorMsgMap = transferErrorMsg(errors);
47-
Assertions.assertTrue(errorMsgMap.containsKey("$.title"), "error message must contains key: $.title");
48-
Assertions.assertTrue(errorMsgMap.containsKey("$.pictures"), "error message must contains key: $.pictures");
49-
Assertions.assertEquals("$.title:可能只有 10 个字符长", errorMsgMap.get("$.title"));
50-
Assertions.assertEquals("$.pictures:数组中最多必须有 2 个项目", errorMsgMap.get("$.pictures"));
35+
Map<String, String> errorsMap = validate();
36+
Assertions.assertEquals("$.title:可能只有 10 个字符长", errorsMap.get("$.title"));
37+
Assertions.assertEquals("$.pictures:数组中最多必须有 2 个项目", errorsMap.get("$.pictures"));
38+
}
39+
40+
@Test
41+
@Disabled
42+
public void shouldFailV201909_with_deDE() throws Exception {
43+
Locale.setDefault(Locale.GERMANY);
44+
Map<String, String> errorsMap = validate();
45+
Assertions.assertEquals("$.title darf höchstens 10 Zeichen lang sein", errorsMap.get("$.title"));
46+
Assertions.assertEquals("$.pictures: Es dürfen höchstens 2 Elemente in diesem Array sein", errorsMap.get("$.pictures"));
5147
}
5248

53-
private Set<ValidationMessage> validate() throws Exception {
54-
String schemaPath = "/schema/issue471-2019-09.json";
55-
String dataPath = "/data/issue471.json";
56-
InputStream schemaInputStream = Issue471Test.class.getResourceAsStream(schemaPath);
49+
private Map<String, String> validate() throws Exception {
50+
InputStream schemaInputStream = Issue471Test.class.getResourceAsStream(SCHEMA_PATH);
5751
JsonSchema schema = getJsonSchemaFromStreamContentV201909(schemaInputStream);
58-
InputStream dataInputStream = Issue471Test.class.getResourceAsStream(dataPath);
52+
InputStream dataInputStream = Issue471Test.class.getResourceAsStream(DATA_PATH);
5953
JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
60-
return schema.validate(node);
54+
55+
Set<ValidationMessage> validationMessages = schema.validate(node);
56+
return convertValidationMessagesToMap(validationMessages);
57+
}
58+
59+
private Map<String, String> convertValidationMessagesToMap(Set<ValidationMessage> validationMessages) {
60+
return validationMessages.stream().collect(Collectors.toMap(ValidationMessage::getPath, ValidationMessage::getMessage));
6161
}
6262

63-
private Map<String, String> transferErrorMsg(Set<ValidationMessage> validationMessages) {
64-
Map<String, String> pathToMessage = new HashMap<>();
65-
validationMessages.forEach(msg -> {
66-
pathToMessage.put(msg.getPath(), msg.getMessage());
67-
});
68-
return pathToMessage;
63+
private JsonSchema getJsonSchemaFromStreamContentV201909(InputStream schemaContent) {
64+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
65+
return factory.getSchema(schemaContent);
6966
}
67+
68+
private JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
69+
ObjectMapper mapper = new ObjectMapper();
70+
return mapper.readTree(content);
71+
}
72+
7073
}

0 commit comments

Comments
 (0)