rmraya / OpenXLIFF

An open source set of Java filters for creating, merging and validating XLIFF 1.2, 2.0 and 2.1 files.
https://www.maxprograms.com/products/openxliff.html
Eclipse Public License 1.0
67 stars 19 forks source link

How do I write a given <target> on XLIFF 2.0? #8

Closed handhikadj closed 3 years ago

handhikadj commented 3 years ago

I'm using okapi-lib-xliff2 to read-and-write a .xlf file which generated from OpenXLIFF's ./convert.sh. but after that, Word deems the file is corrupted when I merge the XLIFF file back using OpenXLIFF's ./merge.sh because the okapi-lib has different format of how they write-and-save the XLIFF file.

Any API/Library to write your generated .xlf file after ./convert.sh?

rmraya commented 3 years ago

I don't understand what your problem is. Is there anything wrong in OpenXLIFF that needs fixing?

handhikadj commented 3 years ago

not exactly. Here's the thing,

  1. I convert a docx file to .xlf (XLIFF 2.0) file using this library. let's call the generated .xlf file myxlf.xlf
  2. okapi-lib-xliff2 has API that can write a specific (XLIFF 2.0) without having to manually traverse/parse the myxlf.xlf file
  3. after I modify-and-save the myxlf.xlf and merge it back using this lib, Word deems the generated docx file is corrupted
  4. after I examine the myxlf.xlf, I notice that okapi-lib-xliff2overrode the .xlf to be in different format that OpenXLIFF has

So, what I need is is there any API that can write a given <target> text without manually traverse/parse the .xlf file?

I hope you can understand

rmraya commented 3 years ago

It seems that you have a bad XLIFF after processing. You need to fix or replace the tool that breaks the XLIFF.

OpenXLIFF already has all the code needed to read and write XLIFF files. It is the main library used by other tools like Swordfish for handling XLIFF

handhikadj commented 3 years ago

thank you for your ultra-fast response

yea, I know full well that the okapi-lib-xliff2 breaks your XLIFF after I examined it. Would you tell me the tutorial how to read and write a given <target> ?

rmraya commented 3 years ago

There is no special tutorial.

XLIFF is XML and OpenXLIFF has XML library for reading and processing the XML, as shown in the different tools that use it.

rmraya commented 3 years ago

Have you reported the problem to Okapi developers?

handhikadj commented 3 years ago

I've just examined the .xlf file using ./xliffchecker.sh and ./xliffchecker.sh says INFO: File is valid XLIFF 2.0 after I write-a-target-and-save it Hence I don't know what went wrong currently

rmraya commented 3 years ago

I can't comment if I don't see the file.

rmraya commented 3 years ago

BTW, why did you say that okapi breaks the XLIFF file?

handhikadj commented 3 years ago

you can check this out: https://gist.github.com/handhikadj/efc6a425280c8a28430eb048c12b4373#file-main-java-L94-L109 That's how okapi manipulate a .xlf file in a breeze. Notice the highlighted ones. That's how I write a given target

I can't find an API in OpenXLIFF similar to the okapi one. I hope you can provide this in the future / any time soon

rmraya commented 3 years ago

Your code does not handle target tags. You can have valid XLIFF but that XLIFF would be useless. Merged Word files would be broken and Word would complain when you try to open them.

Features similar to the Okapi API already exists in the tools that use OpenXLIFF. There are methods for reading, iterating, modifying, writing and saving XML files, including XLIFF, TMX, TBX, etc.

handhikadj commented 3 years ago

would you point me out to that?

rmraya commented 3 years ago

Sorry, but I can't help you.