Jump to content
Cuq

Python Script how to get the label in my native langage

Recommended Posts

Posted · Python Script how to get the label in my native langage

Hello,

 

I'm looking for a solution to get the translation of  a label  parameter. I can get the label or the description inthe default langage but I don't know how to get it the the right translated text.

 

        #   layer_height
        GetVal = Application.getInstance().getGlobalContainerStack().getProperty("layer_height", "value")
        GetLabel = Application.getInstance().getGlobalContainerStack().getProperty("layer_height", "label")

 

Share this post


Link to post
Share on other sites
Posted · Python Script how to get the label in my native langage

Getting the label indeed gets the untranslated one. You can translate it by passing it though the localisation catalog (i18nCatalog)


It would look a bit like this (it's untested code, so it might not work)

from UM.i18n import i18nCatalog

catalog = i18nCatalog("Cura")

untranslated_label = Application.getInstance().getGlobalContainerStack().getProperty("layer_height", "label")
translated_label = catalog.i18n(untranslated_label)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Posted · Python Script how to get the label in my native langage
50 minutes ago, nallath said:

catalog = i18nCatalog("Cura")

 

That should probably be

catalog = i18nCatalog("cura")

 

Share this post


Link to post
Share on other sites
Posted (edited) · Python Script how to get the label in my native langage

Hello @nallath and @ahoeben ,

 

Thanks for your help , None of these solutions seems to work, If it's just a word I've got a translation but a complex label is not translated.

 

Tested :

from UM.i18n import i18nCatalog

catalog = i18nCatalog("cura")

untranslated_label = Application.getInstance().getGlobalContainerStack().getProperty("layer_height", "label")
translated_label = catalog.i18n(untranslated_label)

and 

 

from UM.i18n import i18nCatalog

catalog = i18nCatalog("cura")

untranslated_label = Application.getInstance().getGlobalContainerStack().getProperty("layer_height", "label")
translated_label = catalog.i18nc("@label", untranslated_label)

 

with the same result 😞

Edited by Cuq

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!