rework language handling again
This commit is contained in:
parent
0188fcedd1
commit
548284fcda
|
@ -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.LanguageProducerLanguageSession;
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerSession;
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
|
||||
|
||||
|
||||
public class ResourceLanguageFileBuilder {
|
||||
|
||||
|
@ -75,7 +77,7 @@ public class ResourceLanguageFileBuilder {
|
|||
String ppath = path+"."+p.getName()+(p.isList() ? "["+i+"]" : "");
|
||||
i++;
|
||||
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()) {
|
||||
process(sess, pp, pid, ppath);
|
||||
|
|
|
@ -3,11 +3,38 @@ package org.hl7.fhir.utilities.i18n;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
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 {
|
||||
private String id;
|
||||
private Map<String, String> translations = new HashMap<>();
|
||||
|
@ -47,7 +74,7 @@ public abstract class LanguageFileProducer {
|
|||
|
||||
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 {
|
||||
|
@ -55,7 +82,7 @@ public abstract class LanguageFileProducer {
|
|||
protected String id;
|
||||
protected String baseLang;
|
||||
|
||||
protected LanguageProducerSession( String id, String baseLang) {
|
||||
protected LanguageProducerSession(String id, String baseLang) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.baseLang = baseLang;
|
||||
|
@ -78,5 +105,5 @@ public abstract class LanguageFileProducer {
|
|||
public abstract LanguageProducerSession startSession(String id, String baseLang) throws IOException;
|
||||
public abstract void finish();
|
||||
|
||||
public abstract List<Translations> loadTranslations(String id);
|
||||
public abstract List<TextUnit> loadTranslations(String baseLang, String targetLang);
|
||||
}
|
||||
|
|
|
@ -71,13 +71,13 @@ public class PoGetTextProducer extends LanguageFileProducer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void entry(String id, String src, String dst) {
|
||||
ln("#: "+id);
|
||||
public void entry(TextUnit unit) {
|
||||
ln("#: "+unit.getContext());
|
||||
// if (context != null) {
|
||||
// ln("#. "+context);
|
||||
// }
|
||||
ln("msgid \""+src+"\"");
|
||||
ln("msgstr \""+dst+"\"");
|
||||
ln("msgid \""+unit.getSrcText()+"\"");
|
||||
ln("msgstr \""+unit.getTgtText()+"\"");
|
||||
ln("");
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,7 @@ public class PoGetTextProducer extends LanguageFileProducer {
|
|||
|
||||
|
||||
@Override
|
||||
public List<Translations> loadTranslations(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
|
||||
|
||||
public class XLIFFProducer extends LanguageFileProducer {
|
||||
|
||||
|
@ -35,16 +36,16 @@ public class XLIFFProducer extends LanguageFileProducer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void entry(String id, String src, String dst) {
|
||||
public void entry(TextUnit unit) {
|
||||
i++;
|
||||
ln(" <trans-unit id=\""+id+"\" resname=\""+this.id+"\">");
|
||||
ln(" <trans-unit id=\""+id+"\" resname=\""+unit.getContext()+"\">");
|
||||
// if (context != null) {
|
||||
// ln(" <notes>");
|
||||
// ln(" <note id=\"n"+i+"\">"+Utilities.escapeXml(context)+"</note>");
|
||||
// ln(" </notes>");
|
||||
// }
|
||||
ln(" <source>"+Utilities.escapeXml(src)+"</source>");
|
||||
ln(" <target>"+Utilities.escapeXml(dst)+"</target>");
|
||||
ln(" <source>"+Utilities.escapeXml(unit.getSrcText())+"</source>");
|
||||
ln(" <target>"+Utilities.escapeXml(unit.getTgtText())+"</target>");
|
||||
ln(" </trans-unit>");
|
||||
}
|
||||
|
||||
|
@ -82,10 +83,10 @@ public class XLIFFProducer extends LanguageFileProducer {
|
|||
public void finish() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Translations> loadTranslations(String id) {
|
||||
// TODO Auto-generated method stub
|
||||
public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -829,7 +829,7 @@ public class IgLoader {
|
|||
else
|
||||
throw new FHIRException("Unsupported format for " + fn);
|
||||
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"))
|
||||
r = new XmlParser().parse(new ByteArrayInputStream(content));
|
||||
else if (fn.endsWith(".json") && !fn.endsWith("template.json"))
|
||||
|
|
|
@ -50,6 +50,8 @@ public class CliContext {
|
|||
@JsonProperty("htmlInMarkdownCheck")
|
||||
private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING;
|
||||
|
||||
@JsonProperty("langTransform")
|
||||
private String langTransform = null;
|
||||
@JsonProperty("map")
|
||||
private String map = null;
|
||||
@JsonProperty("output")
|
||||
|
@ -136,6 +138,17 @@ public class CliContext {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
@JsonProperty("langTransform")
|
||||
public String getLangTransform() {
|
||||
return langTransform;
|
||||
}
|
||||
|
||||
@JsonProperty("langTransform")
|
||||
public CliContext setLangTransform(String langTransform) {
|
||||
this.langTransform = langTransform;
|
||||
return this;
|
||||
}
|
||||
@JsonProperty("igs")
|
||||
public List<String> getIgs() {
|
||||
return igs;
|
||||
|
|
|
@ -107,7 +107,7 @@ public class ValidationService {
|
|||
public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception {
|
||||
VersionSourceInformation versions = new VersionSourceInformation();
|
||||
IgLoader igLoader = new IgLoader(
|
||||
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION),
|
||||
new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER),
|
||||
new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(),
|
||||
null);
|
||||
for (String src : cliContext.getIgs()) {
|
||||
|
@ -454,7 +454,7 @@ public class ValidationService {
|
|||
|
||||
public String determineVersion(CliContext cliContext, String sessionId) throws Exception {
|
||||
if (cliContext.getMode() != EngineMode.VALIDATION) {
|
||||
return "current";
|
||||
return "5.0";
|
||||
}
|
||||
System.out.println("Scanning for versions (no -version parameter):");
|
||||
VersionSourceInformation versions = scanForVersions(cliContext);
|
||||
|
|
|
@ -13,7 +13,7 @@ public class Common {
|
|||
public static String getVersion(String[] args) {
|
||||
String v = Params.getParam(args, "-version");
|
||||
if (v == null) {
|
||||
v = "current";
|
||||
v = "5.0";
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if ("-ig".equals(args[i])) {
|
||||
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";
|
||||
} else if ("1.4".equals(v)) {
|
||||
} else if (VersionUtilities.isR2BVer(v)) {
|
||||
v = "1.4";
|
||||
} else if ("3.0".equals(v)) {
|
||||
} else if (VersionUtilities.isR3Ver(v)) {
|
||||
v = "3.0";
|
||||
} else if ("4.0".equals(v)) {
|
||||
} else if (VersionUtilities.isR4Ver(v)) {
|
||||
v = "4.0";
|
||||
} else if (v.startsWith(Constants.VERSION)) {
|
||||
v = "current";
|
||||
} else if (VersionUtilities.isR4BVer(v)) {
|
||||
v = "4.3";
|
||||
} else if (VersionUtilities.isR5Ver(v)) {
|
||||
v = "5.0";
|
||||
} else if (VersionUtilities.isR6Ver(v)) {
|
||||
v = "6.0";
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
@ -49,7 +53,7 @@ public class Common {
|
|||
*/
|
||||
public static String getVersionFromIGName(String defaultValue, String igFileName) {
|
||||
if (igFileName.equals("hl7.fhir.core")) {
|
||||
defaultValue = "current";
|
||||
defaultValue = "5.0";
|
||||
} else if (igFileName.startsWith("hl7.fhir.core#")) {
|
||||
defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14));
|
||||
} 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")) {
|
||||
defaultValue = "4.0";
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class Display {
|
|||
}
|
||||
|
||||
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:");
|
||||
for (String s : args) {
|
||||
System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s);
|
||||
|
|
|
@ -4,6 +4,7 @@ public enum EngineMode {
|
|||
VALIDATION,
|
||||
COMPILE,
|
||||
TRANSFORM,
|
||||
LANG_TRANSFORM,
|
||||
NARRATIVE,
|
||||
SNAPSHOT,
|
||||
SCAN,
|
||||
|
|
|
@ -41,6 +41,7 @@ public class Params {
|
|||
public static final String NO_NATIVE = "-no-native";
|
||||
public static final String COMPILE = "-compile";
|
||||
public static final String TRANSFORM = "-transform";
|
||||
public static final String LANG_TRANSFORM = "-lang-transform";
|
||||
public static final String NARRATIVE = "-narrative";
|
||||
public static final String SNAPSHOT = "-snapshot";
|
||||
public static final String SCAN = "-scan";
|
||||
|
@ -237,6 +238,9 @@ public class Params {
|
|||
} else if (args[i].equals(TRANSFORM)) {
|
||||
cliContext.setMap(args[++i]);
|
||||
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)) {
|
||||
cliContext.setMap(args[++i]);
|
||||
cliContext.setMode(EngineMode.COMPILE);
|
||||
|
|
Loading…
Reference in New Issue