How regularly is the archive with translations in crowdin updates?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

kisolre wrote: Sun Sep 12, 2021 11:47 am Not to be ungrateful but my idea was more like a full automation of downloading all ts files for selected language one by one and converting to qm.
Crowdin does not allow you to upload *.ts directly from the link. Write this program is not to be able.
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

Evgeniy wrote: Sun Sep 12, 2021 2:14 pm Crowdin does not allow you to upload *.ts directly from the link.
I don't think it's necessary to upload, just to download. Can't we just add something like

Code: Select all

LANG_CODE = "bg"
import urllib.request
with urllib.request.urlopen(f'https://crowdin.com/backend/download/project/freecad/{LANG_CODE}.zip') as response:
   zip_data = response.read()
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

chennes wrote: Sun Sep 12, 2021 8:31 pm
Evgeniy wrote: Sun Sep 12, 2021 2:14 pm Crowdin does not allow you to upload *.ts directly from the link.
I don't think it's necessary to upload, just to download. Can't we just add something like

Code: Select all

LANG_CODE = "bg"
import urllib.request
with urllib.request.urlopen(f'https://crowdin.com/backend/download/project/freecad/{LANG_CODE}.zip') as response:
   zip_data = response.read()
We can and it works. But kisolre wants an archive with the latest changes. And if you download the archive in the way you suggested, there will still be translations from September 6, and today is already the 13th. Recent translations can be downloaded only one file at a time through the Crowdin interface. Although the method you proposed is good for saving traffic.

I think you can download fresh translations only manually, then throw them into \ts folder and the my script will do everything by itself.

Maybe there is something like in the Crowdin REST API?:

Code: Select all

https://crowdin.com/backend/download/project/freecad/ru/Arch.ts
Last edited by Evgeniy on Sun Sep 12, 2021 10:34 pm, edited 1 time in total.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

chennes wrote: Sun Sep 12, 2021 8:31 pm
Evgeniy wrote: Sun Sep 12, 2021 2:14 pm Crowdin does not allow you to upload *.ts directly from the link.
I don't think it's necessary to upload, just to download. Can't we just add something like
I'm look REST API of Crowdin.

May be that?

https://support.crowdin.com/ru/api/pre-translate/

Is possible to send POST request from FreeCAD? And get response?
Last edited by Evgeniy on Sun Sep 12, 2021 10:42 pm, edited 2 times in total.
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

Make sure you are using APIv2: https://support.crowdin.com/api/v2/

And yes, you can use Python to sent a POST request, so if you wanted this to be a FreeCAD WB that would be possible.

ETA: In particular, this looks promising... https://support.crowdin.com/api/v2/#ope ... files.post
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

I think there is no such possibility through the REST API...
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

As far as I can tell, you can access every single feature of CrowdIn through the API -- in this case, sending a POST request to:

Code: Select all

https://crowdin.com/api/v2/projects/freecad/translations/builds/files/{fileId}
with a payload like:

Code: Select all

{
    "targetLanguageId": "bg",
    "exportAsXliff": false,
    "skipUntranslatedStrings": false,
    "skipUntranslatedFiles": false,
    "exportApprovedOnly": false
}
Should give a response like:

Code: Select all

{
    "data": 

    {
        "url": "https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62",
        "expireIn": "2019-09-20T10:31:21+00:00",
        "etag": "ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62"
    }

}
where that url is a location you can download the translation from. Presumably there's an API call to get a list of the fileIDs, but I haven't looked for it yet. Did this not work for you? I haven't tested it, but it certainly looks from the documentation like exactly what we need.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

chennes wrote: Mon Sep 13, 2021 2:01 am As far as I can tell, you can access every single feature of CrowdIn through the API -- in this case, sending a POST request to:

Code: Select all

https://crowdin.com/api/v2/projects/freecad/translations/builds/files/{fileId}
with a payload like:

Code: Select all

{
    "targetLanguageId": "bg",
    "exportAsXliff": false,
    "skipUntranslatedStrings": false,
    "skipUntranslatedFiles": false,
    "exportApprovedOnly": false
}
Should give a response like:

Code: Select all

{
    "data": 

    {
        "url": "https://production-enterprise-importer.downloads.crowdin.com/992000002/2/14.xliff?response-content-disposition=attachment%3B%20filename%3D%22APP.xliff%22&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIGJKLQV66ZXPMMEA%2F20190920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190920T093121Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=439ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62",
        "expireIn": "2019-09-20T10:31:21+00:00",
        "etag": "ebd69a1b7e4c23e6d17891a491c94f832e0c82e4692dedb35a6cd1e624b62"
    }

}
where that url is a location you can download the translation from. Presumably there's an API call to get a list of the fileIDs, but I haven't looked for it yet. Did this not work for you? I haven't tested it, but it certainly looks from the documentation like exactly what we need.
Better if you showed code on python... instead requests and response.

Code: Select all

from urllib import parse, request

data ={
    "targetLanguageId": "bg",
    "exportAsXliff": False,
    "skipUntranslatedStrings": False,
    "skipUntranslatedFiles": False,
    "exportApprovedOnly": False
}

data = json.dumps(data)
data = parse.urlencode(data).encode()
req =  request.Request("https://crowdin.com/api/v2/projects/freecad/translations/builds/files/549", data=data) # this will make the method "POST"
resp = request.urlopen(req)
My code return 404.
And where get {fileId}?

Other variant:

Code: Select all

import requests
import json

url = "https://crowdin.com/api/v2/projects/freecad/translations/builds/files/549"
body ={
    "targetLanguageId": "bg",
    "exportAsXliff": False,
    "skipUntranslatedStrings": False,
    "skipUntranslatedFiles": False,
    "exportApprovedOnly": False
}
headers = {'content-type': 'application/json'}

req = requests.post(url, data=json.dumps(body), headers=headers)
print(req.text)
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

I'm just pasting in information from the documentation:
https://support.crowdin.com/api/v2/#ope ... files.post

That page says you get the file ID from the List Files command:
https://support.crowdin.com/api/v2/#ope ... es.getMany
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

chennes wrote: Mon Sep 13, 2021 2:08 pm I'm just pasting in information from the documentation:
https://support.crowdin.com/api/v2/#ope ... files.post

That page says you get the file ID from the List Files command:
https://support.crowdin.com/api/v2/#ope ... es.getMany
I understand this.

Code: Select all

import requests
import json

url = "https://crowdin.com/api/v2/projects/286/files"
body ={
}

headers = {'content-type': 'application/json'}

req = requests.post(url, data=json.dumps(body), headers=headers)
print(req.text)
But this API requires authorization, then need to take the file ID, then download it.
And if I understand correctly, the user must create a token in the profile. A fairly complex script.
Of course, it is convenient when everything is done with one button, but I am not so familiar with the Crowdin API...
And diving into this API may take a lot of time...
It's probably better to make do with what we have for now.
Post Reply