Skip to content

Commit

Permalink
modified the translation code : translate => Qtranslate
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolko-123 committed Feb 9, 2024
1 parent c2e658f commit af56ed7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 131 deletions.
20 changes: 10 additions & 10 deletions Asm4_Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#
# Asm4_Translate.py

import os
import FreeCADGui as Gui
import FreeCAD as App

Gui.addLanguagePath(os.path.join(os.path.dirname(__file__), "Resources/translations"))
import FreeCAD as App


def _atr(context: str, text: str) -> str:
"""Wrap strings which should be translated in in this function."""
return App.Qt.translate(context, text)
# dummy function for the QT translator
def QT_TRANSLATE_NOOP(context, text):
return text


def QT_TRANSLATE_NOOP(context: str, text: str) -> str:
"""NOP Marker Macro Alias for strings for which FreeCAD/Qt handles translations."""
return text
# use latest available translate function
if hasattr(App, "Qt"):
Qtranslate = App.Qt.translate
else:
print("Translations will not be available")

12 changes: 6 additions & 6 deletions FastenersDummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import FreeCADGui as Gui
import FreeCAD as App
from TranslateUtils import translate
#from FastenerBase import FSBaseObject

import Asm4_libs as Asm4
from Asm4_Translate import Qtranslate



Expand All @@ -34,25 +34,25 @@ def __init__(self, fastenerType):
self.fastenerType = fastenerType
# Screw:
if self.fastenerType=='Screw':
self.menutext = translate("Fasteners", "Insert Screw")
self.menutext = Qtranslate("Fasteners", "Insert Screw")
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Screw.svg')
# Nut:
elif self.fastenerType=='Nut':
self.menutext = translate("Fasteners", "Insert Nut")
self.menutext = Qtranslate("Fasteners", "Insert Nut")
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Nut.svg')
# Washer:
elif self.fastenerType=='Washer':
self.menutext = translate("Fasteners", "Insert Washer")
self.menutext = Qtranslate("Fasteners", "Insert Washer")
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Washer.svg')
# threaded rod:
elif self.fastenerType=='ThreadedRod':
self.menutext = translate("Fasteners", "Insert threaded rod")
self.menutext = Qtranslate("Fasteners", "Insert threaded rod")
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Rod.svg')


def GetResources(self):
return {"MenuText": self.menutext,
"ToolTip": 'FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners',
"ToolTip": Qtranslate("Fasteners", "FastenersWorkbench is not installed.\n \nYou can install it with the FreeCAD AddonsManager:\nMenu Tools > Addon Manager > fasteners",)
"Pixmap" : self.icon }


Expand Down
10 changes: 5 additions & 5 deletions FastenersLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import FastenersCmd as FS

import Asm4_libs as Asm4
from Asm4_Translate import Qtranslate

from TranslateUtils import translate


# icon to show in the Menu, toolbar and widget window
Expand Down Expand Up @@ -60,31 +60,31 @@ def __init__(self, fastenerType):
}
# Screw
if self.FSclass == 'Screw':
self.menutext = translate("Fasteners", "Insert Screw")
self.menutext = Qtranslate("Fasteners", "Insert Screw")
self.tooltip = "<p>Insert a Screw into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Screw.svg')
# Nut
elif self.FSclass == 'Nut':
self.menutext = translate("Fasteners", "Insert Nut")
self.menutext = Qtranslate("Fasteners", "Insert Nut")
self.tooltip = "<p>Insert a Nut into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Nut.svg')
# Washer
elif self.FSclass == 'Washer':
self.menutext = translate("Fasteners", "Insert Washer")
self.menutext = Qtranslate("Fasteners", "Insert Washer")
self.tooltip = "<p>Insert a Washer into the Assembly</p>"
self.tooltip += "<p>If another fastener is selected, a new fastener of the same type is created in the same assembly."
self.tooltip += "If an axis or LCS is selected, the new fastener will be attached to it."
self.tooltip += "If an assembly is selected, the new fastener will be inside that assembly.</p>"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Washer.svg')
# Threaded Rod (makes errors)
elif self.FSclass == 'ThreadedRod':
self.menutext = translate("Fasteners", "Insert threaded rod")
self.menutext = Qtranslate("Fasteners", "Insert threaded rod")
self.tooltip = "Insert threaded rod"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Rod.svg')

Expand Down
13 changes: 7 additions & 6 deletions HelpCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#
# HelpCmd.py

import os
import webbrowser
import Asm4_libs as Asm4
from TranslateUtils import translate
import os, webbrowser

import FreeCADGui as Gui

import Asm4_libs as Asm4
from Asm4_Translate import Qtranslate


"""
+-----------------------------------------------+
Expand All @@ -21,8 +22,8 @@
class Asm4Help():

def GetResources(self):
return {"MenuText": translate("Asm4_Help", "Help for Assembly4"),
"ToolTip": translate("Asm4_Help", "Show basic usage for FreeCAD and Assembly4"),
return {"MenuText": Qtranslate("Asm4_Help", "Help for Assembly4"),
"ToolTip": Qtranslate("Asm4_Help", "Show basic usage for FreeCAD and Assembly4"),
"Pixmap": os.path.join(Asm4.iconPath, 'Asm4_Help.svg')
}

Expand Down
58 changes: 15 additions & 43 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import os

import Asm4_locator
global Asm4_icon, Asm4_path, Asm4_trans
Asm4_path = os.path.dirname( Asm4_locator.__file__ )
Asm4_icon = os.path.join( Asm4_path , 'Resources/icons/Assembly4.svg' )
Asm4_trans = os.path.join(Asm4_path, "Resources/translations")

# I don't like this being here
import selectionFilter

global Asm4_icon, Asm4_path, Asm4_trans
Asm4_path = os.path.dirname(Asm4_locator.__file__)
Asm4_icon = os.path.join(Asm4_path, "Resources/icons/Assembly4.svg")
Asm4_trans = os.path.join(Asm4_path, "Resources/translations")


"""
+-----------------------------------------------+
Expand All @@ -54,7 +53,6 @@ def __init__(self):

def Activated(self):
"This function is executed when the workbench is activated"
# FreeCAD.Console.PrintMessage(translate("Asm4", "Activating Assembly4 WorkBench") + '\n')
# make buttons of the selection toolbar checkable
from PySide import QtGui
mainwin = Gui.getMainWindow()
Expand All @@ -71,7 +69,6 @@ def Activated(self):
def Deactivated(self):
"This function is executed when the workbench is deactivated"
selectionFilter.observerDisable()
# FreeCAD.Console.PrintMessage(translate("Asm4", "Leaving Assembly4 WorkBench") + "\n")
return

def GetClassName(self):
Expand All @@ -83,10 +80,9 @@ def GetClassName(self):
| This is where all is defined |
+-----------------------------------------------+
"""

def Initialize(self):
from TranslateUtils import translate

# Translations
from Asm4_Translate import Qtranslate
FreeCADGui.addLanguagePath(Asm4_trans)
FreeCADGui.updateLocale()

Expand All @@ -99,33 +95,15 @@ def Initialize(self):
Asm4_version = metadata.Version
# with file VERSION (FreeCAD ≤0.20)
except:
'''
FCVersion = App.Version()[0]+'.'+App.Version()[1]
if FCVersion=='0.19':
FCDate = " from "+App.Version()[4][0:4]
elif FCVersion=='0.20':
FCDate = " from "+App.Version()[5][0:4]
else :
FCDate = ""
message = "You seem to be using FreeCAD version "+FCVersion+FCDate+" which is quite old. "
message += "Some functionality of latest versions might be missing\n"
FreeCAD.Console.PrintMessage(message)
'''
versionPath = os.path.join( Asm4_path, 'VERSION' )
versionFile = open(versionPath,"r")
# read second line
version = versionFile.readlines()[1]
versionFile.close()
# remove trailing newline
Asm4_version = version[:-1]
Asm4_version = version[:-1]

FreeCAD.Console.PrintMessage(
translate("Asm4", "Initializing Assembly4 workbench")
+ " ("
+ Asm4_version
+ ") ."
)

FreeCAD.Console.PrintMessage(Qtranslate("Asm4", "Initializing Assembly4 workbench")+ ' ('+Asm4_version+') .')
FreeCADGui.updateGui()
# import all stuff
import newAssemblyCmd # created an App::Part container called 'Assembly'
Expand Down Expand Up @@ -187,7 +165,7 @@ def Initialize(self):

# Define Menus
# commands to appear in the Assembly4 menu 'Assembly'
self.appendMenu(translate("Workbench", "&Assembly"), self.assemblyMenuItems())
self.appendMenu("&Assembly", self.assemblyMenuItems())
self.dot()

# put all constraints related commands in a separate menu
Expand All @@ -197,23 +175,21 @@ def Initialize(self):
# self.appendMenu("&Geometry",["Asm4_newPart"])

# additional entry in the Help menu
self.appendMenu(translate("Workbench", "&Help"), ["Asm4_Help"])
self.appendMenu(Qtranslate("Workbench", "&Help"), ["Asm4_Help"])
self.dot()

# Define Toolbars
# commands to appear in the Assembly4 toolbar
self.appendToolbar(translate("Asm4", "Assembly"), self.assemblyToolbarItems())
self.appendToolbar("Assembly", self.assemblyToolbarItems())
self.dot()

# build the selection toolbar
self.appendToolbar(
translate("Asm4", "Selection Filter"), self.selectionToolbarItems()
)
self.appendToolbar("Selection Filter", self.selectionToolbarItems())
self.dot()

# self.appendToolbar("Geometry",["Asm4_newPart"])

FreeCAD.Console.PrintMessage(" " + translate("Asm4", "done") + ".\n")
FreeCAD.Console.PrintMessage(" " + Qtranslate("Asm4", "done") + ".\n")
"""
+-----------------------------------------------+
| Initialisation finished |
Expand Down Expand Up @@ -357,12 +333,8 @@ def ContextMenu(self, recipient):

self.appendContextMenu("", "Separator")
self.appendContextMenu("", contextMenu) # add commands to the context menu
self.appendContextMenu(
translate("Asm4", "Assembly"), assemblySubMenu
) # add commands to the context menu
self.appendContextMenu(
translate("Asm4", "Create"), createSubMenu
) # add commands to the context menu
self.appendContextMenu("Assembly", assemblySubMenu) # add commands to the context menu
self.appendContextMenu(Qtranslate("Asm4", "Create"), createSubMenu) # add commands to the context menu
self.appendContextMenu("", "Separator")


Expand Down
39 changes: 0 additions & 39 deletions TranslateUtils.py

This file was deleted.

9 changes: 4 additions & 5 deletions gotoDocumentCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@



import math, re, os
import os

from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
import Part

import Asm4_libs as Asm4
from TranslateUtils import translate
from Asm4_Translate import Qtranslate



Expand All @@ -33,8 +32,8 @@ def __init__(self):


def GetResources(self):
return {"MenuText": translate("Asm4_gotoDocument", "Open Document"),
"ToolTip": translate("Asm4_gotoDocument", "Activates the document of the selected linked part"),
return {"MenuText": Qtranslate("Asm4_gotoDocument", "Open Document"),
"ToolTip": Qtranslate("Asm4_gotoDocument", "Activates the document of the selected linked part"),
"Pixmap": os.path.join(Asm4.iconPath, 'Asm4_openDocument.svg')
}

Expand Down
7 changes: 3 additions & 4 deletions newAssemblyCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import FreeCAD as App

import Asm4_libs as Asm4
from Asm4_Translate import Qtranslate



from TranslateUtils import translate

class newAssemblyCmd:
"""
+-----------------------------------------------+
Expand All @@ -38,9 +37,9 @@ def makeAssembly():
"""
def GetResources(self):
tooltip = translate("Commands", "<p>Create a new Assembly container</p>")
tooltip = Qtranslate("Commands", "<p>Create a new Assembly container</p>")
iconFile = os.path.join( Asm4.iconPath , 'Asm4_Model.svg')
return {"MenuText": translate("Commands", "New Assembly"), "ToolTip": tooltip, "Pixmap" : iconFile }
return {"MenuText": "New Assembly", "ToolTip": tooltip, "Pixmap" : iconFile }


def IsActive(self):
Expand Down
Loading

0 comments on commit af56ed7

Please sign in to comment.