ProtonMail / WebClients

Monorepo hosting the proton web clients
GNU General Public License v3.0
4.24k stars 538 forks source link

How to convert translation XLIFF to JSON ? There are some errors. #321

Closed xet7 closed 1 year ago

xet7 commented 1 year ago

Hi, How to convert translation XLIFF to JSON ? I get these errors with both with XLIFF and filtered XLIFF.

When I try to convert webapp.xliff to JSON using step 8 of this page:

https://github.com/wekan/wekan/wiki/ProtonMail

Using this command:

python3 convert.py --input ../webapp.xliff --output ../fi_FI.json --locale fi_FI

Error at Debian 11 using Python 3.9.2:

Traceback (most recent call last):
  File "/root/xliff-to-JSON-ttag/convert.py", line 140, in <module>
    main()
  File "/root/xliff-to-JSON-ttag/convert.py", line 135, in main
    convert(file=Path(args.input), output_path=Path(args.output), locale=args.locale)
  File "/root/xliff-to-JSON-ttag/convert.py", line 115, in convert
    for translation in find_translations(xliff, namespace):
  File "/root/xliff-to-JSON-ttag/lib/translations.py", line 135, in find_translations
    translation = get_translation(trans_unit, namespace, all_states=all_states)
  File "/root/xliff-to-JSON-ttag/lib/translations.py", line 89, in get_translation
    context = note.text.split("\n")[0].strip().split("Context:")[1].strip()
IndexError: list index out of range

Error at Ubuntu 23.04 with Python 3.11.2:

Traceback (most recent call last):
  File "/home/wekan/repos/xliff-to-JSON-ttag/convert.py", line 140, in <module>
    main()
  File "/home/wekan/repos/xliff-to-JSON-ttag/convert.py", line 135, in main
    convert(file=Path(args.input), output_path=Path(args.output), locale=args.locale)
  File "/home/wekan/repos/xliff-to-JSON-ttag/convert.py", line 115, in convert
    for translation in find_translations(xliff, namespace):
  File "/home/wekan/repos/xliff-to-JSON-ttag/lib/translations.py", line 135, in find_translations
    translation = get_translation(trans_unit, namespace, all_states=all_states)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wekan/repos/xliff-to-JSON-ttag/lib/translations.py", line 89, in get_translation
    context = note.text.split("\n")[0].strip().split("Context:")[1].strip()
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
dhoko commented 1 year ago

:wave: I wasn't able to replicate with the test files from the repo. The issue comes from the type of download file you use: filtered XLIFF

You need to pick Download option, download

As we upload a source xliff the download option is going to give you the translations as a xliff too.

It's because when you export to xliff the file, crowdin is going to remove some informations for all plurals and it creates a broken file we can't really process (as we won't be able to build the JSON from it with plurals attached to their context)

It's a known issue with crowdin, they can't handle well context and plurals when the source file is xliff :/

Edit: Added this how to to the Readme of the lib https://github.com/dhoko/xliff-to-JSON-ttag

xet7 commented 1 year ago

Thanks! Now converting translation works!