Context Specific Translation Feature is Merged

The English word ‘Submit’, when translated into German could be ‘Buchen’ or ‘Senden’. It depends on the context. In the context of submitting a sales invoice (accounting), it is ‘Buchen’. In the context of submitting a comment on a blog, it is ‘Senden’. While ERPNext has been ‘multi-lingual’ since 2012, now we have context-specific translations.

This enhancement was proposed and sponsored by members of the ERPNext community in Germany and Switzerland.

Thanks to

  1. ALYF GmbH (Raffael Meyer @rmeyer)

  2. //SEIBERT/MEDIA GmbH / Corp. (Martin Seibert @Martin_Seibert )

  3. libracore AG (Lars Muller @lasalesi )

  4. @itsdave GmbH (David Malinowski @itsdave )

  5. LIS Engineering GmbH (Achim Leitner)

Please find more information here.
https://github.com/frappe/frappe/issues/6989

This feature was developed by Suraj Shetty (@surajshetty)

Related: Translations should be context-specific!

8 Likes

Thank you for your work @surajshetty, @Basawaraj_Savalagi and thanks to the sponsors for making this possible!

2 Likes

Is this merge to v13 only or v12 also?
Because I can’t find it in the last version of v12.

And I still see that the same translation in the csv file is picked up when there are 2 different English words occur (which should have different translations).
Thank you

per my experience there is still bug in the code at least in v13.
frappe.translate.make_dict_from_messages to be changed as below.
def make_dict_from_messages(messages, full_dict=None, load_user_translation=True):

    """Returns translated messages as a dict in Language specified in `frappe.local.lang`

    :param messages: List of untranslated messages

    """

    out = {}

    if full_dict==None:

        if load_user_translation:

            full_dict = get_full_dict(frappe.local.lang)

        else:

            full_dict = load_lang(frappe.local.lang)

    for m in messages:      

        # check if msg with context as key exist eg. msg:context

        trans_with_context_exist = False

        if isinstance(m[0], str): 

            key = m[1] + ':' + m[0]

            if full_dict.get(key):

                trans_with_context_exist = True

                out[m[1]] = full_dict[key]

        if not trans_with_context_exist and m[1] in full_dict:

            out[m[1]] = full_dict[m[1]]

        if len(m) > 2 and m[2]:

            key = m[1] + ':' + m[2]

            if full_dict.get(key):

                out[key] = full_dict[key]

    return out

Thank you @szufisher.
So it is only for v13.

Also just a thought, why create new context? Because in the csv there is a reference column (first column) where the words exist in a file. I think it can be used as “context”. If this column is empty for an entry, it applied to all files.

@rahy

Will there be such reference column in v13? because I could not see any reference information in the new csv files in v13 beta translation folders.

If not, how will we be able to arrange meanings to specific contexts?

Or am I missing something obvious?

I have asked this question in this topic with details.

I don’t really know about version 13 as I have not tried it. Still on version 12 :slight_smile:

But I read somewhere in this forum (forgot the poster) that it will have different algorithm for context recognition. And will not use the first column.

Hello, I wonder the same thing. In csv file in v12 there is 3 column a “doctype context”, Original string, translation string
DocType: BOM Item,Basic Rate (Company Currency),TTranslated String
But Doctype seems never used.
And It’s no more available in csv in v13. there is only two column left.
According to this : https://frappeframework.com/docs/user/en/translations it’s now available and according this PR it’s done : https://github.com/frappe/frappe/pull/9636
But in tranlation tools there is no way to give a context.

I see some unmerged PR in frappe too regarding this feature.

Does anyone have more information about this feature and how it works ?

In v13 french translation are a bit funny, but as our users/customers are not all ready to have fun with their ERP, I try to fund a way to cover their needs.

I’ve also valided transaltion on translate.erpnext.com, more than 2 weeks ago and they not transform into PR yet on beta-13. I guess There is other important task to complete by erpnext/frappe Team. I’ll wait and hope.
(By the way translation tools in ERPNext instance is broken actually (frappe/frappe/hook.py translator_url = “https://translatev2.erpnext.com” => SSLCert error, I guess it’s jut a matter of time to update certificate as translate.erpnext.com server have just been migrated)