Jump to content

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")

 

  • 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)

     

  • 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
  • Link to post
    Share on other sites

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

    I think I have tested every combination possible without success. but I never give up.

     

    translated_label=catalog.i18n(key)
    untranslated_label=stack.getProperty(key,"label")
    translated_label=catalog.i18n(untranslated_label)
    definition_key=key + " label" 
    untranslated_label=stack.getProperty(key,"label")
    translated_label=catalog.i18nc(definition_key, untranslated_label)

     

    untranslated_label=stack.getProperty(key,"label")
    translated_label=catalog.i18nc("@label", untranslated_label)

     

    untranslated_label=stack.getProperty(key,"label").capitalize()
    translated_label=catalog.i18nc("@label", untranslated_label)

     

    untranslated_label=stack.getProperty(key,"label")
    translated_label=catalog.i18nc("@label", key)

     

    untranslated_label=stack.getProperty(key,"label")
    translated_label=catalog.i18nc(key, untranslated_label)

     

     

    Edited by Cuq
  • Link to post
    Share on other sites

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

    some help from Uranium translation Guide 

     

    https://github.com/Ultimaker/Uranium/blob/master/docs/translations.md

     

     

    https://github.com/Ultimaker/Uranium/blob/master/UM/i18n.py

     

        def i18nc(self, context: str, text: str, *args: Any) -> str:
            """Mark a string as translatable and provide a context for translators.
            :param context: The context of the string, i.e. something that explains
            the use of the text.
            :param text: The text to mark translatable.
            :param args: Formatting arguments. These will replace formatting elements
            in the translated string. See python ``str.format()``.
            :return: The translated text or the untranslated text if it was not found
            in this catalog.
            """

     

     

     

    Edited by Cuq
  • Link to post
    Share on other sites

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

    YES!!!! I finaly got the solution .

     

    The printing parameters are not define in the cura.po file but in fdmprinter.def.json.po  so the  catalog must be specified as

    i18n_catalog = i18nCatalog("fdmprinter.def.json")

     

    po_file.jpg

     

    from UM.i18n import i18nCatalog
    
    i18n_catalog = i18nCatalog("fdmprinter.def.json")
    
    #: fdmprinter.def.json
    # msgctxt "support_extruder_nr_layer_0 label"  -> Context 
    # msgid "First Layer Support Extruder"  -> Key 
    # msgstr "Extrudeuse de support de la première couche"  -> translated text
    
    definition_key=key + " label"
    untranslated_label=stack.getProperty(key,"label")
    translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
    Edited by Cuq
    • Like 1
    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
    • Our picks

      • UltiMaker Cura 5.9 stable released!
        Here comes Cura 5.9 and in this stable release we have lots of material and printer profiles for UltiMaker printers, including the newly released Sketch Sprint. Additionally, scarf seams have been introduced alongside even more print settings and improvements.  Check out the rest of this article to find out the details on all of that and more
          • Like
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Heart
          • Thanks
          • Like
        • 7 replies
    ×
    ×
    • Create New...