PolRaguénès
PolRaguénès

Reputation: 160

Django translation : assess if a string is a translation in any available language

I can't find a way to identify if a given string (say "xxxxxxxxxx") is a translation of a defined string (say "hello world"), in any available language (the languages my application is translated into). I'm inputted a string, and would like to identify if it's a translation of "hello world" in any of my available languages (PO files then). Any idea ?

EDIT for context : The application previously exported a database in a fixed XLS format, for future imports. During the import, a formatting check is done and an error message is thrown if format is wrong. That formatting check begins with reading the tabs name. If it's good --> then the XLS is read, if not the error is thrown. During that first check, I want to discriminate between (i) a real error in formatting and (ii) the user importing an XLS previously exported in a different language (but I don't know which one). So I have the tab name and just want to check if that tab name is just a translation of the default tab name : that would allow me to throw a different error message advising to change to the correct language for importing.

Upvotes: 0

Views: 50

Answers (1)

Nafees Anwar
Nafees Anwar

Reputation: 6608

I don't think what you are trying to do is achievable using django. (Why do you want to do this BTW?)

There is a library out there named polib. It handles .po and .mo files very nicely. You can read its documentation here.

You can create a pofile object with it using

import polib

po = polib.pofile('<FILE_PATH>')

And then iterate over it like this

for entry in po:
    msgid, msgstr = po.msgid, po.msgstr
    # you can do your comparison here

Upvotes: 1

Related Questions