Jump to content

Python Script how to get the label in my native langage


Cuq

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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 20 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...