Merge branch 'i18nUtilities' into i18n_fixes

This commit is contained in:
patrick-werner 2020-03-13 18:45:26 +01:00
commit fe4b4acc3f
14 changed files with 56 additions and 96 deletions

View File

@ -1179,38 +1179,4 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return corePath+"snomed.html";
return null;
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}
}

View File

@ -31,7 +31,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
@ -95,7 +94,7 @@ import org.hl7.fhir.r5.utils.TranslatingUtilities;
import org.hl7.fhir.r5.utils.formats.CSVWriter;
import org.hl7.fhir.r5.utils.formats.XLSXWriter;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.validation.ValidationOptions;
@ -266,7 +265,6 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean newSlicingProcessing;
private String defWebRoot;
private boolean autoFixSliceNames;
private ResourceBundle i18nMessages;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp) {
super();

View File

@ -22,7 +22,6 @@ package org.hl7.fhir.r5.context;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -32,7 +31,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
@ -83,7 +81,8 @@ import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.client.ToolingClientLogger;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nBase;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.OIDUtils;
import org.hl7.fhir.utilities.TranslationServices;
import org.hl7.fhir.utilities.Utilities;
@ -95,10 +94,7 @@ import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import com.google.gson.JsonObject;
public abstract class BaseWorkerContext implements IWorkerContext {
private ResourceBundle i18Nmessages;
private Locale locale;
public abstract class BaseWorkerContext extends I18nBase implements IWorkerContext{
public class MetadataResourceVersionComparator<T extends CanonicalResource> implements Comparator<T> {
@ -1282,37 +1278,4 @@ public abstract class BaseWorkerContext implements IWorkerContext {
public Map<String, byte[]> getBinaries() {
return binaries;
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale);
}
}

View File

@ -25,14 +25,10 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@ -48,16 +44,13 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
import org.hl7.fhir.r5.context.SimpleWorkerContext.ILoadFilter;
import org.hl7.fhir.r5.formats.IParser;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.ParserType;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.Questionnaire;
import org.hl7.fhir.r5.model.Resource;
@ -73,7 +66,7 @@ import org.hl7.fhir.r5.utils.INarrativeGenerator;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.hl7.fhir.utilities.CSFileInputStream;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.cache.NpmPackage;
@ -81,7 +74,6 @@ import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
import ca.uhn.fhir.fluentpath.IFluentPath;
import ca.uhn.fhir.parser.DataFormatException;
/*

View File

@ -26,7 +26,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
@ -45,7 +44,7 @@ import org.hl7.fhir.r5.formats.JsonCreatorCanonical;
import org.hl7.fhir.r5.formats.JsonCreatorGson;
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser;

View File

@ -35,7 +35,7 @@ import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;

View File

@ -46,7 +46,7 @@ import org.hl7.fhir.r5.utils.formats.Turtle.TTLList;
import org.hl7.fhir.r5.utils.formats.Turtle.TTLLiteral;
import org.hl7.fhir.r5.utils.formats.Turtle.TTLObject;
import org.hl7.fhir.r5.utils.formats.Turtle.TTLURL;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;

View File

@ -40,7 +40,6 @@ import javax.xml.transform.sax.SAXSource;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
@ -54,7 +53,7 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.formats.XmlLocationAnnotator;
import org.hl7.fhir.r5.utils.formats.XmlLocationData;
import org.hl7.fhir.utilities.ElementDecoration;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;

View File

@ -22,7 +22,6 @@ package org.hl7.fhir.r5.terminologies;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -46,7 +45,7 @@ import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.hl7.fhir.utilities.validation.ValidationOptions.ValueSetMode;

View File

@ -0,0 +1,44 @@
package org.hl7.fhir.utilities.i18n;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;
public abstract class I18nBase {
private Locale locale;
private ResourceBundle i18Nmessages;
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale);
}
}

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.utilities;
package org.hl7.fhir.utilities.i18n;
public class I18nConstants {

View File

@ -126,7 +126,7 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.I18nConstants;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.validation.BaseValidator;
import org.hl7.fhir.validation.instance.EnableWhenEvaluator.QStack;
import org.hl7.fhir.validation.XVerExtensionManager;