Translating external workbenches

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Translating external workbenches

Post by vocx »

Kunda1 wrote: Wed Mar 11, 2020 1:30 pm Nice! Are you on Github? Can you link to your fork? Actually link to the line number you edited?
It should be after these two lines.

https://github.com/yorikvanhavre/BIM_Wo ... #L320-L322

Code: Select all

        FreeCADGui.addLanguagePath(BimCommands.getLanguagePath())
        Log ('Loading BIM module... done\n')
        FreeCADGui.updateLocale() # refresh the language according to current locale.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
alex.zhang
Posts: 12
Joined: Wed Jan 08, 2020 6:47 am

Re: Translating external workbenches

Post by alex.zhang »

vocx wrote: Wed Mar 11, 2020 7:46 pm
Kunda1 wrote: Wed Mar 11, 2020 1:30 pm Nice! Are you on Github? Can you link to your fork? Actually link to the line number you edited?
It should be after these two lines.

https://github.com/yorikvanhavre/BIM_Wo ... #L320-L322

Code: Select all

        FreeCADGui.addLanguagePath(BimCommands.getLanguagePath())
        Log ('Loading BIM module... done\n')
        FreeCADGui.updateLocale() # refresh the language according to current locale.
Yes, the code let FreeCAD to refresh translation.
User avatar
alex.zhang
Posts: 12
Joined: Wed Jan 08, 2020 6:47 am

Re: Translating external workbenches

Post by alex.zhang »

https://github.com/yorikvanhavre/BIM_Wo ... ui.py#L208

Code: Select all

        # load rebar tools (Reinforcement addon)

        try:
            import RebarTools
        except ImportError:
            pass
        else:
            # create popup group for Rebar tools
            class RebarGroupCommand:
                def GetCommands(self):
                    return tuple(["Arch_Rebar"]+RebarTools.RebarCommands)
                def GetResources(self):
                    return { 'MenuText': 'Reinforcement tools','ToolTip': 'Reinforcement tools'}
                def IsActive(self):
                    return not FreeCAD.ActiveDocument is None
            FreeCADGui.addCommand('Arch_RebarTools', RebarGroupCommand())
            self.bimtools[self.bimtools.index("Arch_Rebar")] = "Arch_RebarTools"
One other issue about rebar addon, RebarGroupCommand menu not translated, while sub menus are translated. Pls see attached.

Any idea?
Attachments
rebar_menu.png
rebar_menu.png (49.85 KiB) Viewed 3312 times
User avatar
alex.zhang
Posts: 12
Joined: Wed Jan 08, 2020 6:47 am

Re: Translating external workbenches

Post by alex.zhang »

Same issue in Arch Module. Arch_AxisTools as example.

I found all menu (group) with sub menus not translated.
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Translating external workbenches

Post by yorik »

Hi all,
I just started a new crowdin project named "FreeCAD-addons". The idea is to be easy for everybody, translators will find all addons in one place, and addon developers can get more visibility:

https://crowdin.com/project/freecad-addons

Addon developers willing to get your WB translated, you should create a "master" (untranslated) .ts file for your workbench, then create a crowdin account and contact me to get added to that project. Then you'll be able to upload your file there (manually or via script), and download the translations anytime (again, manually or via script).
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: Translating external workbenches

Post by galou_breizh »

I received a new hope with the FreeCADGui.updateLocale() function to be able to translate macros. I gave it another try this morning but was unsuccessful.

Does someone know how to debug i18n issues? For example, how to get a list of loaded translation files, a list of translation files that FreeCAD searched but didn't find, a list of translation strings, a list of translation contexts, etc.

Thanks a lot!
Gaël
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Re: Translating external workbenches

Post by JOE_FU »

alex.zhang wrote: Thu Mar 12, 2020 3:31 am Same issue in Arch Module. Arch_AxisTools as example.

I found all menu (group) with sub menus not translated.
I encountered the same problem, can't the group name be translated?
EdgarRobles
Posts: 72
Joined: Fri Jul 31, 2015 1:35 pm
Location: Mexico
Contact:

Re: Translating external workbenches

Post by EdgarRobles »

I Finally managed to translate almost whole dodo workbench to spanish.
The main issue came from

Code: Select all

FreeCADGui.addLanguagePath(pForms.getLanguagePath())
this part of code is the right way to add a translating path. getLanguagePath is a function defined on pForms module and it contains

Code: Select all

def getLanguagePath():
    import os
    return os.path.join(os.path.dirname(__file__),"translations")
I got stuck on translating drop down menu header.

Code: Select all

self.appendMenu(QT_TRANSLATE_NOOP("dodo","Frame tools"),self.frameList)
    self.appendMenu(QT_TRANSLATE_NOOP("dodo","Pype tools"),self.pypeList)
    self.appendMenu(QT_TRANSLATE_NOOP("dodo","Utils"),self.utilsList)
    self.appendMenu(QT_TRANSLATE_NOOP("dodo","QkMenus"),self.qm)
    Log ('Loading Pipe tools: done\n')
    FreeCADGui.updateLocale()
pipe tools.jpg
pipe tools.jpg (75.46 KiB) Viewed 3102 times
pipe tools2.jpg
pipe tools2.jpg (93.71 KiB) Viewed 3102 times
EdgarRobles
Posts: 72
Joined: Fri Jul 31, 2015 1:35 pm
Location: Mexico
Contact:

Re: Translating external workbenches

Post by EdgarRobles »

It done team!

dodo workbench is fully translated to spanish
Here is a example or a small pipe and created objects
Translated#1.jpg
Translated#1.jpg (22.77 KiB) Viewed 3051 times
Translated#2.jpg
Translated#2.jpg (29.74 KiB) Viewed 3051 times
Translated#3.jpg
Translated#3.jpg (13.22 KiB) Viewed 3051 times
Here you have a example to send a translation to ts file and translate the object name

Code: Select all

a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",translate("Part::FeaturePython","Tube"))
each module you translate you must place these lines at the begining of de module

Code: Select all

from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftGui import translate
Make sure these lines are placed in InitGui.py module in the order showed

Code: Select all

FreeCADGui.addLanguagePath(pForms.getLanguagePath())
    FreeCADGui.updateLocale()

If you want to check the full workbench code check here
https://github.com/EdgarJRobles/dodo.git
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Translating external workbenches

Post by yorik »

Excellent! If you are interested, I would advise you to create a main .ts file (without language code in it), and add it to https://crowdin.com/project/freecad-addons (send me your crowdin username and I'll give you access rights). Then FreeCAD translators can then easily find it. When you have access right, you also have access to the crowdin API and automate all the process of uploading/retrieving translations, check the translation scripts I did for the BIM WB at https://github.com/yorikvanhavre/BIM_Wo ... ster/utils
Post Reply