Skip to content

PR #511: Improve validation messages (German and default) #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main/java/com/networknt/schema/I18nSupport.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.networknt.schema;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
Expand All @@ -8,10 +9,36 @@
* @author leaves chen [email protected]
*/
public class I18nSupport {

private static final String BASE_NAME = "jsv-messages";
private static ResourceBundle bundle = ResourceBundle.getBundle(BASE_NAME);
private static final ResourceBundle bundle;

static {
ResourceBundle tmpBundle = null;
try {
tmpBundle = ResourceBundle.getBundle(BASE_NAME);
} catch (MissingResourceException mre) {
// Need to avoid by all means that we fail loading ValidatorTypeCode with a
// "java.lang.NoClassDefFoundError: Could not initialize class com.networknt.schema.ValidatorTypeCode"
// due to the fact that a ResourceBundle is incomplete
mre.printStackTrace();
System.exit(1);
}
bundle = tmpBundle;
}

public static String getString(String key) {
return bundle.getString(key);
String retval = null;
try {
retval = bundle.getString(key);
} catch (MissingResourceException mre) {
// Need to avoid by all means that we fail loading ValidatorTypeCode with a
// "java.lang.NoClassDefFoundError: Could not initialize class com.networknt.schema.ValidatorTypeCode"
// due to the fact that a ResourceBundle is incomplete
mre.printStackTrace();
System.exit(2);
}
return retval;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/ValidatorTypeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public JsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSc
TYPE("type", "1029", new MessageFormat(I18nSupport.getString("type")), TypeValidator.class, 15),
UNION_TYPE("unionType", "1030", new MessageFormat(I18nSupport.getString("unionType")), UnionTypeValidator.class, 15),
UNIQUE_ITEMS("uniqueItems", "1031", new MessageFormat(I18nSupport.getString("uniqueItems")), UniqueItemsValidator.class, 15),
DATETIME("date-time", "1034", new MessageFormat(I18nSupport.getString("date-time")), null, 15),
DATETIME("dateTime", "1034", new MessageFormat(I18nSupport.getString("dateTime")), null, 15),
UUID("uuid", "1035", new MessageFormat(I18nSupport.getString("uuid")), null, 15),
ID("id", "1036", new MessageFormat(I18nSupport.getString("id")), null, 15),
IF_THEN_ELSE("if", "1037", null, IfValidator.class, 12), // V7|V201909
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/jsv-messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ anyOf = {0} muss g
const = {0} muss den konstanten Wert {1} annehmen
contains = {0} beinhaltet kein Element, das diese Validierung besteht: {1}
crossEdits = {0}: Ein Fehler mit 'cross edits' ist aufgetreten
date-time = {0}: {1} ist ein ung�ltiges {2}
dateTime = {0}: {1} ist ein ung�ltiges {2}
dependencies = {0} hat einen Fehler mit Abh�ngigkeiten {1}
dependentRequired = {0} fehlt eine Eigenschaft, welche 'dependentRequired' {1} ist
dependentSchemas = {0}: Ein Fehler mit 'dependentSchemas' {1} ist aufgetreten
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/jsv-messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ anyOf = {0}\uFF1A\u5E94\u8BE5\u5BF9\u4EFB\u4F55\u67B6\u6784 {1} \u90FD\u6709\u65
const = {0}\uFF1A\u5FC5\u987B\u662F\u5E38\u91CF\u503C {1}
contains = {0}\uFF1A\u4E0D\u5305\u542B\u901A\u8FC7\u8FD9\u4E9B\u9A8C\u8BC1\u7684\u5143\u7D20\uFF1A{1}
crossEdits = {0}\uFF1A\u201C\u4EA4\u53C9\u7F16\u8F91\u201D\u6709\u9519\u8BEF
# "datetime" translation to be reviewed by a native speaker
# "dateTime" translation to be reviewed by a native speaker
dateTime = {0}\uFF1A{1} \u662F\u65E0\u6548\u7684 {2}
dependencies = {0}\uFF1A\u4F9D\u8D56\u9879 {1} \u6709\u9519\u8BEF
dependentRequired = {0}\u7f3a\u5c11\u4f9d\u8d56\u9879\u6240\u9700\u7684\u5c5e\u6027 {1}
Expand Down