API: get project id from slug, download public files without token

I’m trying to make sss_translate use the crowdin api instead of downloading via https://crowdin.com/backend/download/project/...

I’ve started running into issues with using https://crowdin.com/backend/download/project/... so I’m hoping the API will give me more control and information.

I’m starting with this

Credentials credentials = new Credentials("", null);

Client client = new Client(credentials);
client
    .getSourceFilesApi()
    .listFiles(projectId, null, null, null, null, null, null)
    .getData()
    .forEach(fileInfo -> System.out.println(fileInfo.getData()));
  1. is there a way for me to obtain projectId from a project slug like "sss-translate"?
  2. will I be able to download files without supplying a token (passing an empty string) to Credentials so long as those files are publicly available?

Hi,

  1. to get the project ID with the API v2 feel free to run the List projects endpoint by following the URL below:
    Crowdin API v2 Reference (File-based)
  2. To use the API you need to authorize first, so you can’t export translations via API without providing a token. Kindly check more in our documentation:
    Crowdin API v2 Reference (File-based)

Requiring a token isn’t an option for sss_translate, so it sounds like using Crowdin API isn’t an option for me.

So I guess downloading via https://crowdin.com/backend/download/project/... will have to do.

Do you have any idea why downloading via https://crowdin.com/backend/download/project/sss-translate.zip would be inconsistent?

I’ve also tried with two of my other projects, meticulous and wither-cage-fix, with the same results.

It was working fine but now it’s giving me empty zip files.

If I go to that url in my browser it usually 404s for a few attempts, then downloads correctly.

The only thing I can think of that I’ve changed is that I’ve added a lot more target languages to all my projects.

I download via those links here: base/src/main/java/net/sssubtlety/sss_translate/base/SssTranslate.java · 45bdff1a3891f564034cb741e8acd9570168011b · supersaiyansubtlety-group / Minecraft Mods / sss_translate · GitLab

Do you have any idea why downloading via https://crowdin.com/backend/download/project/sss-translate.zip would be inconsistent?

Is this the URL to you exporting zip translations from the project? In case so, it should work consistently. If it’s giving empty files, maybe you don’t have newly added translations that you didn’t download yet or you have specific export options enabled in the project settings

Currently, I don’t see any error logs connected to the zip export translations. Please try exporting languages in several batches and check if it is working fine for you?

I’m not sure how I would go about downloading languages in batches, especially since I don’t know which languages are available before I download them.

It seems the issue is with the contents of the zip file, not that it’s actually empty:

  • java.util.zip.ZipInputStream can’t read it and behaves as though it’s empty.
  • if I try reading using org.apache.commons.compress.archivers.zip.ZipArchiveInputStream instead it gives an informative error:

java.util.zip.ZipException: Cannot find zip signature within the first 4096 bytes

I read from the zip file here: base/src/main/java/net/sssubtlety/sss_translate/base/SssTranslate.java · 45bdff1a3891f564034cb741e8acd9570168011b · supersaiyansubtlety-group / Minecraft Mods / sss_translate · GitLab

Hello @supersaiyansubtlety,

Have you looked into Build Project Translation API call? After doing it, use List Project Builds and Download Project Translations.

This should work for you!

Tetiana said that using the API requires a token, which means it’s not suitable for sss_translate.

Hi @supersaiyansubtlety!

Would you mind recording a video showing how you download translations and how the file is empty on the result and sending the video to support@crowdin.com?

It would just be a video of me running this test and getting the exception

java.util.zip.ZipException: Cannot find zip signature within the first 4096 bytes

Is that what you mean?

@supersaiyansubtlety,

Just to clarify, do you download translations via UI (translations tab) and get a 404 error and when you try to use API it also fails as you don’t use the API key?

Sorry for back and forth questions, just trying to understand all of your steps, so we can recreate the issue.

No, the issue isn’t occurring when I download via the UI.

There are two issues, both related to downloading via https://crowdin.com/backend/download/project/<project-slug>.zip, I don’t know if they’re related:

  1. when I download from a url like that in sss_translate here, the file can’t be read by either
    java.util.zip.ZipInputStream or
    org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
  2. when I navigate to a url like that in my browser, it usually fails the first try (it redirects me to https://crowdin.com/download/project/<project-slug>.zip and 404s); after the first try it starts a download as expected.

The problem I need help with is 1; 2 is just something I noticed while troubleshooting 1 and thought it might be relevant.

@supersaiyansubtlety
You’ve mentioned this:
"There are two issues, both related to downloading via https://crowdin.com/backend/download/project/<project-slug>.zip "

are you trying to use our API to export translations? In case so, the request should look different, it is a wrong URL. Where you take this URL from? Kindly provide the link to our documentation
I would suggest checking our API documentation below:
https://developer.crowdin.com/api/v2/?q=api#tag/Translations/operation/api.projects.translations.builds.download.download

If you’re using the Crowdin JavaScript client, please check our repo on the matter with all the hints for configurations:

I’m not using the API because it doesn’t suite my needs: sss_translate cannot require users to provide authorization tokens (because it downloads translations at runtime, in production).

I don’t actually know where the https://crowdin.com/backend/download/project/<project-slug>.zip url came from, I picked up this project after it was abandoned by its former maintainer, and that url was part of the project.

If you go to that url in a browser it (usually) downloads a zip file containing the project’s translations. The file downloaded seems to be the same as what’s downloaded when you click “Build & Download” in the website UI (going to the url doesn’t cause the project to re-build, though). From what I can tell from searching the web for that url, the Crowdin UI used to have a “Download” button that used that url.

Each time you want to export translations, the new URL should be generating. Meaning, you won’t be able to use one url to always export translations as the system should update itself under the hood to apply ALL recent translations on export

In order to help you, we need to know which integration you’re using and how it was configured. As it may be that your set up requires some twigs and it runs with an error

I’m not using an integration.
I’m working on sss_translate, which I’ve linked many times now.

Each time you want to export translations, the new URL should be generating. Meaning, you won’t be able to use one url to always export translations as the system should update itself under the hood to apply ALL recent translations on export

This is demonstrably not true: please navigate to https://crowdin.com/backend/download/project/sss-translate.zip in your browser and observer that the most recently built translations download (you may have to try twice, as I’ve said, it sometimes redirects to a 404 on the first try).

Hi @supersaiyansubtlety ,

Let me check everything from my end. Will keep you posted

I’ve created simple test cases showcasing the issue I’m having:

I dumped the contents of the url stream to a file and found it’s the html for Crowdin’s login page.

Did Crowdin recently add a requirement to login before downloading a project build?
Is there a project setting that would allow downloading without logging in?

Hi!
We’re still investigating your case
As for your questions, there were no changes deployed regarding the downloading a project build. We don’t have settings to disable this. In order to export build you need to be logged in

I’m not sure what changed, but at least up until August 4 (probably even a little more recently than that, but I’m certain of August 4), I was able to download without logging in.
Maybe that was a bug?