Issue with Fetching Language File from Crowdin on Windows Platform

We are encountering with fetching language files from Crowdin on the Windows platform. On macOS, iOS, and Android, everything works fine, and we receive the correct JSON data. However, on Windows, we are facing problems.

We can successfully fetch data for the manifest file and receive valid JSON from the following

The issue arises when trying to get data for any language file. For example, using the following

We are not receiving valid JSON on the Windows platform. And Json.Parse through error -

ERROR: Uncaught SyntaxError: Unexpected token in JSON at position 0, location: undefined:0:0
STACK:
[0]xhr.onload@assets/main/index.16a57.js:607

Could you please check if everything is correct on the Windows platform? This issue might be related to cross-platform compatibility. We are testing with Cocos Creator, and the code snippet we are using is as follows:

const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = 'json';

xhr.onload = () => {
    if (xhr.status >= 200 && xhr.status < 300) {
        console.log("Response" + xhr.response.toString());
        resolve(xhr.response);
    } else {
        console.error(" Error loading data: "+ xhr.statusText);
        reject(new Error(xhr.statusText));
    }
};

xhr.onerror = () => {
    console.error('Network error');
    reject(new Error('Network error'));
};

xhr.send();

An issue I’m encountering when trying to retrieve data using Curl on macOS and Windows. Specifically, the JSON format returned is unreadable.

For example, running the following command on macOS results in a corrupted JSON file:

curl -o en.json 'https://distributions.crowdin.net/c44ec4e946bc731e756efe9n010/content/master/en_US.json?timestamp=1721119621'

However, fetching the Crowdin Manifest provides the correct result:

curl -o en.json https://distributions.crowdin.net/c44ec4e946bc731e756efe9n010/manifest.json

Interestingly, the same URL works fine when accessed through Postman.

@andrii-bodnar @TaniaM could you help me with this, I’m assuming if we solve this problem will solve window problem as well which i mentioned earlier.

Hello @dheeraj.yadav

Thanks for your details. I see that our support team is already having a conversation with you via email, and they are checking all the details right now.

We will keep you updated and email just once we have a solution on the matter.

The issue was that the server is sending compressed responses (gzip deflate), which were not correctly handled by the XMLHttpRequest.

This caused the JSON parsing error. By default, the browser handles this decompression, but it seems that explicit handling is required when using XMLHttpRequest.

updated curl command

curl --compressed -o en.json -H "Accept: application/json" 'https://distributions.crowdin.net/c44ec4e946bc731e756efe9n010/content/master/en_US.json?timestamp=1721119621'

Here’s the updated JavaScript code to handle the compressed responses:

const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = 'json';

// Set headers to accept compressed responses
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate");

xhr.onload = () => {
    if (xhr.status >= 200 && xhr.status < 300) {
        try {
            console.log("Response:", JSON.stringify(xhr.response));
            resolve(xhr.response);
        } catch (e) {
            console.error("JSON Parse Error:", e);
            reject(e);
        }
    } else {
        console.error("Error loading data: " + xhr.statusText);
        reject(new Error(xhr.statusText));
    }
};

xhr.onerror = () => {
    console.error('Network error');
    reject(new Error('Network error'));
};

xhr.send();

Alternativelly, you can use the fetch API, which has better support for handling compressed responses:

fetch(url, {
    headers: {
        "Accept-Encoding": "gzip, deflate",
        "Accept": "application/json"
    }
})
.then(response => {
    if (!response.ok) {
        throw new Error('Network response was not ok ' + response.statusText);
    }
    return response.json();
})
.then(data => {
    console.log("Response:", JSON.stringify(data));
    resolve(data);
})
.catch(error => {
    console.error('Fetch error:', error);
    reject(error);
});

Please let me know if you need any further assistance.

1 Like