0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

crowdinのxliffファイルをpythonで読む。

Last updated at Posted at 2022-01-24

背景

crowdinにある翻訳依頼を翻訳者に割り振りするのに、copy string url相当のURLを生成したい!翻訳箇所を送りたい!

crowdinのxliff

xliff/file/body/trans-unit/target の属性stateがneeds-translationのものが未翻訳で翻訳が必要。このstringのtrans-unitのidとbase_urlを組み合わせると翻訳箇所を指すurlになる。

base_urlはenus(米国英語)からja(日本語)に翻訳する場合はこうなる。

copy string urlの構成

https://crowdin.com/translate/<project_name>/<file id>/enus-ja#<trans-unit id>

xliffをダウンロードしてurlを生成する

makeCopyStringUrl.py
from lxml import etree

folder=<your folder>
project_name= "<your_projectname>"

tree = etree.parse('./'+folder+'/crowdin_export.xliff')
root = tree.getroot()
mynsmap = dict()
mynsmap['x'] = root.nsmap[None]

target_lang = tree.xpath("//x:file/@target-language",namespaces=mynsmap)
file_id = tree.xpath("//x:file/@id",namespaces=mynsmap)
tus = tree.xpath("//x:target[contains(@state,'needs-translation')]/../@id",namespaces=mynsmap)

base_url = "https://crowdin.com/translate/"+project_name+"/"+file_id[0]+"/enus-"+target_lang[0]+"#"
for id in tus:
   print(base_url+id)

python3 makeCopyStringUrl.py > url.log

あとはurl.logを開いて、誰に何件送るかをごにょごにょしてタスクを回す。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?