Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup translation infrastructure for A2+ #416

Closed
wants to merge 2 commits into from

Conversation

luzpaz
Copy link
Contributor

@luzpaz luzpaz commented Feb 18, 2021

Addresses #44

  • Add translations/ directory
  • Add import for translation library to *.py files that require it
  • Translated all MenuText
  • Translated all tooltips
  • Translated all relevant print() statments
  • Add a2plus to crowdin (link)
  • Automate

Questions:

Following directions from https://wiki.freecadweb.org/Translating_an_external_workbench

- Add translations/ directory
- Add import for translation library to *.py files that require it
@kbwbe
Copy link
Owner

kbwbe commented Feb 19, 2021

Whowww !! Thanks.

Small Problem: Devel branch is far away from my master branch and cannot be used in public area at moment. Are your changes automated somehow and you can apply them to master branch ? If not, it doesn't matter and i merge things manually.

@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 19, 2021

@kbwbe sorry about that! yikes, tried to rebase and there was sooo much work to do. Maybe it's worth doing it manually now in to a new rebased branch on master ?

@kbwbe
Copy link
Owner

kbwbe commented Feb 19, 2021

I will merge the changes manually at weekend to a2+ master branch. Thank's again.

@kbwbe
Copy link
Owner

kbwbe commented Feb 20, 2021

A new branch "translations" with A2plus has been started. [WIP]
I decided to do a setup similar to Yorik's BIM WB.
from a2p_translateUtils import *

@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 20, 2021

I decided to do a setup similar to Yorik's BIM WB.
from a2p_translateUtils import *

@kbwbe can you document here how you set that up ? I'd love to add that to the wiki

@kbwbe
Copy link
Owner

kbwbe commented Feb 20, 2021

@luzpaz
I will try to get some few german translations for testing purposes. If i have success with that, i will document here how i got this running.

@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 20, 2021

@kbwbe there is also some good advice from vocx in shaise/FreeCAD_SheetMetal#105 (comment)

BTW, I have no idea how to wrap a multi-line variable with a translation function. Example the various tooltips like this one https://github.com/luzpaz/A2plus/blob/ccfb98abefc39dbc293cdc464819d7e47e25b9fc/a2p_recursiveUpdatePlanner.py#L101-L116

@kbwbe
Copy link
Owner

kbwbe commented Feb 21, 2021

@luzpaz
Thanks for your hints, i had a look at them. Nevertheless i have difficulties to get any translation to run.

Some details to my setup...
if introduced a new file a2p_translateUtils.py with following contents:

import FreeCAD

if FreeCAD.GuiUp:
    from PySide.QtCore import QT_TRANSLATE_NOOP
    from DraftGui import translate
else:
    def QT_TRANSLATE_NOOP(context, text):
        return text

    def translate(context, text):
        return text
    
def tr_(text):
    return translate("A2plus", text) 

This file is included everywhere in my .py files
Then i modifed the A2plusWorkbench.Initialize() function and added a languagePath...

def Initialize(self):
        from a2p_translateUtils import QT_TRANSLATE_NOOP
        from a2p_translateUtils import translate
        from a2p_translateUtils import tr_
        
        import sys
        PyVersion = sys.version_info[0]
        if PyVersion == 2:
            import a2p_Resources2
        else:
            import a2p_Resources3
        import a2plib
        
        # add translations path
        FreeCADGui.addLanguagePath(a2plib.getLanguagePath())
        print("languagePath of A2plus Workbench is: {}".format(a2plib.getLanguagePath()))
        

At least your macros for translating the menu entries are included, e.g.

        return {
            'Pixmap'  : ':/icons/a2p_PartsList.svg',
            'MenuText': QT_TRANSLATE_NOOP("A2plus_CreatePartlist", "Create a spreadsheet with a parts list of this file"),
            'ToolTip' : toolTip
            }

Also i tried to translate a multi-line tooltip...

toolTip = translate("A2plus",
'''
Create a spreadsheet with a
parts list of this file.

This function will read out
the #PARTINFO# spreadsheet of
all involved parts of the
assembly and create a new
spreadsheet containing the
parts list.

This button will open a dialog
with the Question:
- Iterate recursively over
     all subassenblies?

Answer Yes:
All parts of all subassemblies are
collected to the partlist

Answer No:
Only the parts within the
recent assembly are collected.
'''
)

After doing all this, i created a .ts file within the new translations/ directory.

pyside-lupdate *.py -ts translations/A2plus.ts -verbose

Then i used the QtLinguist and tried two small translations (only for testing)

After that i released the .ts file to a .qm file...

lrelease "translations/A2plus.ts

FreeCAD starts up without complaining about anything, but ignores my german translations, even when switching the language settings of FC. I think i am missing something important.

Everything can be found in a2+ branch translations. It is up to date.

Any help is appreciated.

Edit: code has been newly formatted.

@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 21, 2021

yikes, the formatting of that post is messed up. Can you format it so the indentation is correct?

@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 21, 2021

@yorikvanhavre can you weigh in when you get a moment ?

@kbwbe
Copy link
Owner

kbwbe commented Feb 28, 2021

@luzpaz
I have merged branch A2p/translations as is to the master branch. So changes do not get lost. Translations still do not work, but i am sure that it is only a small mistake, which can be fixed later.

@kbwbe kbwbe closed this Feb 28, 2021
@luzpaz
Copy link
Contributor Author

luzpaz commented Feb 28, 2021

is there an error ?

@kbwbe
Copy link
Owner

kbwbe commented Feb 28, 2021

@luzpaz
I think there is a little error, because i am not able to get any text to be translated. At moment i do not know why. I am sure that cannot be much to change so that translations get working. So i merged things as they are to prevent them from getting lost in some time.

@yorikvanhavre
Copy link

It's hard to know what's wrong, but I would try something like this to test:

  1. Switch FreeCAd to a language you have translated (ex. German)
  2. Load your translation into FreeCAD, ex. FreeCADGui.addTranslationPath("/path/to/the/folder/containing/qmfile")
  3. Test something, ex. FreeCAD.Qt.tramslate("your context","some string")
    Make sure you are using a context and string that actually are in the ts/qm file of course. This should give you the german translation. If this works ok, then the basic setup is OK. Then we can look at something else. For ex, command names should always use a special context that is the name of the command as registered to FreeCAD.

@luzpaz
Copy link
Contributor Author

luzpaz commented Mar 1, 2021

@yorikvanhavre
Copy link

@luzpaz thanks!!

@kbwbe
Copy link
Owner

kbwbe commented Mar 1, 2021

@yorikvanhavre , thx !
I will try to debug what's going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants