使用OKAPI的XLIFF不支持HTML标签

时间:2019-01-08 09:36:51

标签: xliff

我正在尝试从xliff文件中获取一些文本,然后将其复制到地图中。问题是,如果在xliff文件中输入restype =“ x-paragraph”,我将无法正确获取它。

这是xliff文件:

<?xml version="1.0" encoding="UTF-8"?><xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:okp="okapi-framework:xliff-extensions" xmlns:its="http://www.w3.org/2005/11/its" xmlns:itsxlf="http://www.w3.org/ns/its-xliff/" its:version="2.0" version="1.2">
<file original="/content/geometrixx/de/demo" datatype="html" source-language="en">
<body>
<trans-unit id="1" resname="/abc/de/demo/jcr:content/jcr:title">
<source xml:lang="en">Demo</source>
<target xml:lang="de">Demo</target>
</trans-unit>
<trans-unit id="2" resname="/abc/de/demo/jcr:content/rightPaths_multivalued_0_key11">
<source xml:lang="en">value11</source>
<target xml:lang="de">value11</target>
</trans-unit>
<trans-unit restype="x-paragraph" id="3" resname="/abc/de/demo/jcr:content/rightPaths_multivalued_0_key21">
<source xml:lang="en">this is value21</source>
<target xml:lang="de">Dies ist value21</target>
</trans-unit>
<trans-unit restype="x-paragraph" id="4" resname="/abc/de/demo/jcr:content/rightPaths_multivalued_1_key22">
<source xml:lang="en">this is value22</source>
<target xml:lang="de">Dies ist value22</target>
</trans-unit>
<trans-unit id="5" resname="/abc/de/demo/jcr:content/rightPaths_multivalued_1_key12">
<source xml:lang="en">value12</source>
<target xml:lang="de">value12</target>
</trans-unit>
</body>
</file>
</xliff>

这是我的代码段:-

HtmlFilter htmlFilter;
                                    IFilterWriter filterWriter;
                                    if (!htmlFilterMap.containsKey(textUnitName)) {
                                        htmlFilter = new HtmlFilter();
                                        filterWriter = htmlFilter.createFilterWriter();
                                        filterWriter.setOptions(LocaleId.fromString(targetLanguage),
                                                XliffConstants.XLIFF_ENCODING_UTF_8);
                                        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                                        filterWriter.setOutput(outputStream);
                                        htmlFilter.open(
                                                new RawDocument(xmlPropertyText, LocaleId.fromString(sourceLanguage)));
                                        htmlFilterMap.put(textUnitName, htmlFilter);
                                        outputStreamMap.put(textUnitName, outputStream);
                                    }

                                    htmlFilter = htmlFilterMap.get(textUnitName);
                                    filterWriter = htmlFilter.getFilterWriter();
                                    textUnitMerger.setTrgLoc(LocaleId.fromString(targetLanguage));

                                    while (htmlFilter.hasNext()) {
                                        Event copyToEvent = htmlFilter.next();
                                        if (EventType.TEXT_UNIT.equals(copyToEvent.getEventType())) {
                                            TextUnit copyToTu = (TextUnit) copyToEvent.getResource();                                           
                                            //store TU id so we can restore later
                                            String originalId = copyToTu.getId();                                           
                                            //match HTML's TU id to XLIFF id and merge TU with XLIFF
                                            copyToTu.setId(textUnit.getId());
                                            textUnitMerger.mergeTargets(copyToTu, textUnit);                                            
                                            //restore TU's id for okapi referents
                                            //(e.g. embedded properties that reference other TUs)
                                            copyToTu.setId(originalId);                                         
                                            filterWriter.handleEvent(copyToEvent);
                                            break;
                                        } else {
                                            filterWriter.handleEvent(copyToEvent);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                Iterator htmlFilterMapIterator = htmlFilterMap.entrySet().iterator();

                while (htmlFilterMapIterator.hasNext()) {
                    Map.Entry entry = (Map.Entry) htmlFilterMapIterator.next();
                    HtmlFilter entryValueHtmlFilter = (HtmlFilter) entry.getValue();
                    IFilterWriter filterWriter = entryValueHtmlFilter.getFilterWriter();
                    String entryKey = (String) entry.getKey();
                    while (entryValueHtmlFilter.hasNext()) {
                        Event event = entryValueHtmlFilter.next();
                        filterWriter.handleEvent(event);
                    }

                    entryValueHtmlFilter.close();
                    filterWriter.close();
                    String translatedString = (outputStreamMap.get(entryKey))
                            .toString(XliffConstants.XLIFF_ENCODING_UTF_8);
                    translatedContentMap.put(entryKey, translatedString);
                }

输出:-

{/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_1_key12=value12<p>this is value22</p>&quot;}, /content/geometrixx/de/demo/jcr:contentrightPaths_multivalued_1_key22=Dies ist value22<p>this is value22</p>&quot;},/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_0_key11=value11<p>this is value21</p>&quot;},/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_0_key21=Dies ist value21<p>this is value21</p>&quot;}}

预期输出:-

{/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_1_key12=value12, /content/geometrixx/de/demo/jcr:contentrightPaths_multivalued_1_key22=<p>Dies ist value22</p>&quot;},/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_0_key11=value11},/content/geometrixx/de/demo/jcr:content/rightPaths_multivalued_0_key21=<p>Dies ist value21</p>}}

任何人都可以帮忙。因为我不知道OKAPI框架。

0 个答案:

没有答案