rework language handling again

This commit is contained in:
Grahame Grieve 2023-04-02 23:08:17 +10:00
parent 0188fcedd1
commit 548284fcda
11 changed files with 83 additions and 30 deletions

View File

@ -15,6 +15,8 @@ import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer; import org.hl7.fhir.utilities.i18n.LanguageFileProducer;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerLanguageSession; import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerLanguageSession;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerSession; import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerSession;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
public class ResourceLanguageFileBuilder { public class ResourceLanguageFileBuilder {
@ -75,7 +77,7 @@ public class ResourceLanguageFileBuilder {
String ppath = path+"."+p.getName()+(p.isList() ? "["+i+"]" : ""); String ppath = path+"."+p.getName()+(p.isList() ? "["+i+"]" : "");
i++; i++;
if (isTranslatable(p, b, pid)) { if (isTranslatable(p, b, pid)) {
sess.entry(ppath, b.primitiveValue(), getTranslation(b, target)); sess.entry(new TextUnit(ppath, b.primitiveValue(), getTranslation(b, target)));
} }
for (Property pp : b.children()) { for (Property pp : b.children()) {
process(sess, pp, pid, ppath); process(sess, pp, pid, ppath);

View File

@ -3,11 +3,38 @@ package org.hl7.fhir.utilities.i18n;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
import java.util.HashMap; import java.util.HashMap;
public abstract class LanguageFileProducer { public abstract class LanguageFileProducer {
public static class TextUnit {
private String context;
private String srcText;
private String tgtText;
public TextUnit(String context, String srcText, String tgtText) {
super();
this.context = context;
this.srcText = srcText;
this.tgtText = tgtText;
}
public String getContext() {
return context;
}
public String getSrcText() {
return srcText;
}
public String getTgtText() {
return tgtText;
}
}
public class Translations { public class Translations {
private String id; private String id;
private Map<String, String> translations = new HashMap<>(); private Map<String, String> translations = new HashMap<>();
@ -47,7 +74,7 @@ public abstract class LanguageFileProducer {
public abstract void finish() throws IOException; public abstract void finish() throws IOException;
public abstract void entry(String id, String src, String dst); public abstract void entry(TextUnit unit);
} }
public abstract class LanguageProducerSession { public abstract class LanguageProducerSession {
@ -78,5 +105,5 @@ public abstract class LanguageFileProducer {
public abstract LanguageProducerSession startSession(String id, String baseLang) throws IOException; public abstract LanguageProducerSession startSession(String id, String baseLang) throws IOException;
public abstract void finish(); public abstract void finish();
public abstract List<Translations> loadTranslations(String id); public abstract List<TextUnit> loadTranslations(String baseLang, String targetLang);
} }

View File

@ -71,13 +71,13 @@ public class PoGetTextProducer extends LanguageFileProducer {
} }
@Override @Override
public void entry(String id, String src, String dst) { public void entry(TextUnit unit) {
ln("#: "+id); ln("#: "+unit.getContext());
// if (context != null) { // if (context != null) {
// ln("#. "+context); // ln("#. "+context);
// } // }
ln("msgid \""+src+"\""); ln("msgid \""+unit.getSrcText()+"\"");
ln("msgstr \""+dst+"\""); ln("msgstr \""+unit.getTgtText()+"\"");
ln(""); ln("");
} }
@ -85,8 +85,7 @@ public class PoGetTextProducer extends LanguageFileProducer {
@Override @Override
public List<Translations> loadTranslations(String id) { public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
// TODO Auto-generated method stub
return null; return null;
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
public class XLIFFProducer extends LanguageFileProducer { public class XLIFFProducer extends LanguageFileProducer {
@ -35,16 +36,16 @@ public class XLIFFProducer extends LanguageFileProducer {
} }
@Override @Override
public void entry(String id, String src, String dst) { public void entry(TextUnit unit) {
i++; i++;
ln(" <trans-unit id=\""+id+"\" resname=\""+this.id+"\">"); ln(" <trans-unit id=\""+id+"\" resname=\""+unit.getContext()+"\">");
// if (context != null) { // if (context != null) {
// ln(" <notes>"); // ln(" <notes>");
// ln(" <note id=\"n"+i+"\">"+Utilities.escapeXml(context)+"</note>"); // ln(" <note id=\"n"+i+"\">"+Utilities.escapeXml(context)+"</note>");
// ln(" </notes>"); // ln(" </notes>");
// } // }
ln(" <source>"+Utilities.escapeXml(src)+"</source>"); ln(" <source>"+Utilities.escapeXml(unit.getSrcText())+"</source>");
ln(" <target>"+Utilities.escapeXml(dst)+"</target>"); ln(" <target>"+Utilities.escapeXml(unit.getTgtText())+"</target>");
ln(" </trans-unit>"); ln(" </trans-unit>");
} }
@ -84,8 +85,8 @@ public class XLIFFProducer extends LanguageFileProducer {
} }
@Override @Override
public List<Translations> loadTranslations(String id) { public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
// TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -829,7 +829,7 @@ public class IgLoader {
else else
throw new FHIRException("Unsupported format for " + fn); throw new FHIRException("Unsupported format for " + fn);
r = VersionConvertorFactory_10_50.convertResource(res, new org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor5()); r = VersionConvertorFactory_10_50.convertResource(res, new org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor5());
} else if (fhirVersion.startsWith("5.0") || "current".equals(fhirVersion)) { } else if (fhirVersion.startsWith("5.0")) {
if (fn.endsWith(".xml") && !fn.endsWith("template.xml")) if (fn.endsWith(".xml") && !fn.endsWith("template.xml"))
r = new XmlParser().parse(new ByteArrayInputStream(content)); r = new XmlParser().parse(new ByteArrayInputStream(content));
else if (fn.endsWith(".json") && !fn.endsWith("template.json")) else if (fn.endsWith(".json") && !fn.endsWith("template.json"))

View File

@ -50,6 +50,8 @@ public class CliContext {
@JsonProperty("htmlInMarkdownCheck") @JsonProperty("htmlInMarkdownCheck")
private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING; private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING;
@JsonProperty("langTransform")
private String langTransform = null;
@JsonProperty("map") @JsonProperty("map")
private String map = null; private String map = null;
@JsonProperty("output") @JsonProperty("output")
@ -136,6 +138,17 @@ public class CliContext {
return this; return this;
} }
@JsonProperty("langTransform")
public String getLangTransform() {
return langTransform;
}
@JsonProperty("langTransform")
public CliContext setLangTransform(String langTransform) {
this.langTransform = langTransform;
return this;
}
@JsonProperty("igs") @JsonProperty("igs")
public List<String> getIgs() { public List<String> getIgs() {
return igs; return igs;

View File

@ -107,7 +107,7 @@ public class ValidationService {
public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception { public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception {
VersionSourceInformation versions = new VersionSourceInformation(); VersionSourceInformation versions = new VersionSourceInformation();
IgLoader igLoader = new IgLoader( IgLoader igLoader = new IgLoader(
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION), new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER),
new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(), new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(),
null); null);
for (String src : cliContext.getIgs()) { for (String src : cliContext.getIgs()) {
@ -454,7 +454,7 @@ public class ValidationService {
public String determineVersion(CliContext cliContext, String sessionId) throws Exception { public String determineVersion(CliContext cliContext, String sessionId) throws Exception {
if (cliContext.getMode() != EngineMode.VALIDATION) { if (cliContext.getMode() != EngineMode.VALIDATION) {
return "current"; return "5.0";
} }
System.out.println("Scanning for versions (no -version parameter):"); System.out.println("Scanning for versions (no -version parameter):");
VersionSourceInformation versions = scanForVersions(cliContext); VersionSourceInformation versions = scanForVersions(cliContext);

View File

@ -13,7 +13,7 @@ public class Common {
public static String getVersion(String[] args) { public static String getVersion(String[] args) {
String v = Params.getParam(args, "-version"); String v = Params.getParam(args, "-version");
if (v == null) { if (v == null) {
v = "current"; v = "5.0";
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if ("-ig".equals(args[i])) { if ("-ig".equals(args[i])) {
if (i + 1 == args.length) if (i + 1 == args.length)
@ -24,16 +24,20 @@ public class Common {
} }
} }
} }
} else if ("1.0".equals(v)) { } else if (VersionUtilities.isR2Ver(v)) {
v = "1.0"; v = "1.0";
} else if ("1.4".equals(v)) { } else if (VersionUtilities.isR2BVer(v)) {
v = "1.4"; v = "1.4";
} else if ("3.0".equals(v)) { } else if (VersionUtilities.isR3Ver(v)) {
v = "3.0"; v = "3.0";
} else if ("4.0".equals(v)) { } else if (VersionUtilities.isR4Ver(v)) {
v = "4.0"; v = "4.0";
} else if (v.startsWith(Constants.VERSION)) { } else if (VersionUtilities.isR4BVer(v)) {
v = "current"; v = "4.3";
} else if (VersionUtilities.isR5Ver(v)) {
v = "5.0";
} else if (VersionUtilities.isR6Ver(v)) {
v = "6.0";
} }
return v; return v;
} }
@ -49,7 +53,7 @@ public class Common {
*/ */
public static String getVersionFromIGName(String defaultValue, String igFileName) { public static String getVersionFromIGName(String defaultValue, String igFileName) {
if (igFileName.equals("hl7.fhir.core")) { if (igFileName.equals("hl7.fhir.core")) {
defaultValue = "current"; defaultValue = "5.0";
} else if (igFileName.startsWith("hl7.fhir.core#")) { } else if (igFileName.startsWith("hl7.fhir.core#")) {
defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14)); defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14));
} else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) { } else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) {
@ -61,7 +65,9 @@ public class Common {
} else if (igFileName.startsWith("hl7.fhir.r4.core#") || igFileName.equals("hl7.fhir.r4.core")) { } else if (igFileName.startsWith("hl7.fhir.r4.core#") || igFileName.equals("hl7.fhir.r4.core")) {
defaultValue = "4.0"; defaultValue = "4.0";
} else if (igFileName.startsWith("hl7.fhir.r5.core#") || igFileName.equals("hl7.fhir.r5.core")) { } else if (igFileName.startsWith("hl7.fhir.r5.core#") || igFileName.equals("hl7.fhir.r5.core")) {
defaultValue = "current"; defaultValue = "5.0";
} else if (igFileName.startsWith("hl7.fhir.r6.core#") || igFileName.equals("hl7.fhir.r6.core")) {
defaultValue = "6.0";
} }
return defaultValue; return defaultValue;
} }

View File

@ -22,7 +22,7 @@ public class Display {
} }
public static void printCliArgumentsAndInfo(String[] args) throws IOException { public static void printCliArgumentsAndInfo(String[] args) throws IOException {
System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).getFolder()); System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).getFolder());
System.out.print(" Params:"); System.out.print(" Params:");
for (String s : args) { for (String s : args) {
System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s); System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s);

View File

@ -4,6 +4,7 @@ public enum EngineMode {
VALIDATION, VALIDATION,
COMPILE, COMPILE,
TRANSFORM, TRANSFORM,
LANG_TRANSFORM,
NARRATIVE, NARRATIVE,
SNAPSHOT, SNAPSHOT,
SCAN, SCAN,

View File

@ -41,6 +41,7 @@ public class Params {
public static final String NO_NATIVE = "-no-native"; public static final String NO_NATIVE = "-no-native";
public static final String COMPILE = "-compile"; public static final String COMPILE = "-compile";
public static final String TRANSFORM = "-transform"; public static final String TRANSFORM = "-transform";
public static final String LANG_TRANSFORM = "-lang-transform";
public static final String NARRATIVE = "-narrative"; public static final String NARRATIVE = "-narrative";
public static final String SNAPSHOT = "-snapshot"; public static final String SNAPSHOT = "-snapshot";
public static final String SCAN = "-scan"; public static final String SCAN = "-scan";
@ -237,6 +238,9 @@ public class Params {
} else if (args[i].equals(TRANSFORM)) { } else if (args[i].equals(TRANSFORM)) {
cliContext.setMap(args[++i]); cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.TRANSFORM); cliContext.setMode(EngineMode.TRANSFORM);
} else if (args[i].equals(LANG_TRANSFORM)) {
cliContext.setLangTransform(args[++i]);
cliContext.setMode(EngineMode.LANG_TRANSFORM);
} else if (args[i].equals(COMPILE)) { } else if (args[i].equals(COMPILE)) {
cliContext.setMap(args[++i]); cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.COMPILE); cliContext.setMode(EngineMode.COMPILE);