REST API: language code in CroQL

Hi, I am using REST API to select specific texts with specific translations. I was very happy to find that CroQL exists, that gives a lot of flexibility in how to specify the selection criteria.

Here’s the CroQL string I am using to find the texts whose translation contains specific substring:

text contains "original_text" and count of translations where (text contains "translation_text") > 0

That works almost perfectly. But there is one problem: it does not check the translation language. So, I thought I’d add another criteria in the parenthesis:

text contains "original_text" and count of translations where (language = "lv" and text contains "translation_text") > 0

But I received error: Invalid logic in CroQL. Right operand must be 'int' or 'float', but 'string' given. Which is interesting because everywhere where we talk about languages, there’s only a string language code. I replaced "lv" with 1, and the error went away. Apparently, there’s an undisclosed nomenclature of int language codes. Well, knowing a specific translation in a specific language, I wrote a Python script to loop over all numbers from 1 to 100 to find my language (87 for Latvian), but that’s no fun to do for each language. Maybe there’s a reference list somewhere though?

Also, somewhat related question. How I can improve the query so that it searches only in the approved translations?

Hello @Passiday

Interesting observation, I double-check the nomenclature from my end. I assume you’re referring to this part of the CroQL context?

As for queries-improving solutions, adding the parameter "count of approvals: should solve this task.

You can use this application to create and troubleshoot your queries:

I’ve also noticed that there’s a possibility of using character-based language codes, like on this test sample, but this is for simpler queries:

count of translations where ( language = @language:"uk" and ( count of approvals > 0 or count of votes > 0 ) ) = 0

Would you be able to provide some details about your workflow, what is the reason you aim to find the texts whose translation contains specific substrings?

Perhaps, knowing the end result you are trying to achieve I can suggest an easier way or solution.

Hi @Dima

Thanks for the feedback. Yes, indeed, you pointed to the correct part of the CroQL context.

I tried to complement the query:

text contains "original_text" and count of translations where (language = 87 and text contains "translation_text"  and count of approvals > 0) > 0

But it picked up also cases where the translation_text was present only in translations without approvals. That is, the given text “X” has several translations, let’s say “A”, “B”, and “C”, but only “A” is with approval. If I’d search for translation of “X” that has an approved translation “C”, the above-mentioned query would happily return “X”.

I also tried to install the CroQL Tester, and after installation it said I’ll find the app under Project menu, Tools, but I can’t really find this UI. Perhaps the project managers have to enable this menu?

Using the syntax @language:"<code>" works, I was not aware of this prefixed approach.

This querying through API is used to find specific cases in a really, really large project (Khan Academy). Using the basic search is too slow and would take a lot of manual clicking and editing. Automated replacement in cases where the fix is in the part of translation that is math expression is much more effective. So I am making a simple web-based tool that would let user to select criteria, get a list of matches, propose automated translation, and let them edit and submit those translations pretty much all at once.

Hi @Passiday !

Regarding the language parameter, we have noticed that it’s miswritten in your request, please kindly check the screenshot below and rewrite it:

As for the approved translation filtering, we’re checking it with the developers. Also, about the CroQL Tester app, the project owner should install it and access should be given to all members, then you’ll see it in the Tools section

Dear @Passiday, sorry our developers just shared the CroQL request sample that works like a charm (they tested it on their test project), please kindly see it below and try to replicate on your project:

text contains “original_text” and count of translations where (language = @language:“lv” and text contains “translation_text” and count of approvals > 0) > 0

1 Like

Thanks, @Natalia, indeed, works like a charm. :slight_smile: Thanks!

Dear @Passiday , great to hear that and you’re welcome :slight_smile:

Hello @Passiday

To start with, I’m glad that after the conversation with @Natalia, you were able to complete the CroQL expression.

As promised, I’ve checked from my end the existence of integer language codes. You were right, but they exist only for our internal technical purposes, so that is the reason there’s no open documentation or any mention. We will disable the possibility of using integer-based codes soon.

As for now, even if you managed to extract them, we don’t recommend using integer codes, because all API-based requests, with 100% certainty can be completed with letter-based official language codes.

1 Like