HTML-теги не поддерживаются XLIFF с использованием OKAPI - PullRequest
0 голосов
/ 08 января 2019

Я пытаюсь получить текст из файла xliff и затем скопировать его на карту. Проблема в том, что если в файле xliff для restype = "x-абзац" я не могу получить его правильно.

Вот файл 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.

...