Skip to content

Commit

Permalink
Merge pull request Zolko-123#464 from hasecilu/feat/translation_suppo…
Browse files Browse the repository at this point in the history
…rt_enhanced

WIP: Add translation support, initial testing
  • Loading branch information
Zolko-123 authored Feb 9, 2024
2 parents ba381d2 + d2b48e2 commit c2e658f
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 305 deletions.
9 changes: 5 additions & 4 deletions FastenersDummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

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


Expand Down
10 changes: 5 additions & 5 deletions FastenersLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import Asm4_libs as Asm4


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 = "Insert Screw"
self.menutext = translate("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 = "Insert Nut"
self.menutext = translate("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 = "Insert Washer"
self.menutext = translate("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 = "Insert threaded rod"
self.menutext = translate("Fasteners", "Insert threaded rod")
self.tooltip = "Insert threaded rod"
self.icon = os.path.join( Asm4.iconPath , 'Asm4_Rod.svg')

Expand Down
6 changes: 3 additions & 3 deletions HelpCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import webbrowser
import Asm4_libs as Asm4
from Asm4_Translate import QT_TRANSLATE_NOOP as Qtranslate
from TranslateUtils import translate
import FreeCADGui as Gui


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

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

Expand Down
50 changes: 34 additions & 16 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@


import os
from Asm4_Translate import _atr, QT_TRANSLATE_NOOP

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

# 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 @@ -43,7 +44,6 @@ class Assembly4Workbench(Workbench):

global Asm4_icon
global selectionFilter
global _atr, QT_TRANSLATE_NOOP
MenuText = "Assembly 4"
ToolTip = "Assembly 4 workbench"
Icon = Asm4_icon
Expand All @@ -54,7 +54,7 @@ def __init__(self):

def Activated(self):
"This function is executed when the workbench is activated"
# FreeCAD.Console.PrintMessage(_atr("Asm4", "Activating Assembly4 WorkBench") + '\n')
# 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 +71,7 @@ def Activated(self):
def Deactivated(self):
"This function is executed when the workbench is deactivated"
selectionFilter.observerDisable()
# FreeCAD.Console.PrintMessage(_atr("Asm4", "Leaving Assembly4 WorkBench") + "\n")
# FreeCAD.Console.PrintMessage(translate("Asm4", "Leaving Assembly4 WorkBench") + "\n")
return

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

def Initialize(self):
from TranslateUtils import translate

FreeCADGui.addLanguagePath(Asm4_trans)
FreeCADGui.updateLocale()

# Assembly4 version info
# with file package.xml (FreeCAD ≥0.21)
packageFile = os.path.join( Asm4_path, 'package.xml' )
Expand Down Expand Up @@ -112,8 +118,14 @@ def Initialize(self):
versionFile.close()
# remove trailing newline
Asm4_version = version[:-1]

FreeCAD.Console.PrintMessage(_atr("Asm4", "Initializing Assembly4 workbench")+ ' ('+Asm4_version+') .')
Asm4_version = version[:-1]

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

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

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

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

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

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

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

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

self.appendContextMenu("", "Separator")
self.appendContextMenu("", contextMenu) # add commands to the context menu
self.appendContextMenu(_atr("Asm4", "Assembly"), assemblySubMenu) # add commands to the context menu
self.appendContextMenu(_atr("Asm4", "Create"), createSubMenu) # 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("", "Separator")


Expand Down
Binary file added Resources/translations/asm4_es-ES.qm
Binary file not shown.
171 changes: 171 additions & 0 deletions Resources/translations/asm4_es-ES.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="es_ES" sourcelanguage="en">
<context>
<name>Asm4</name>
<message>
<location filename="../../InitGui.py" line="124"/>
<source>Initializing Assembly4 workbench</source>
<translation>Inicializando en entorno de trabajo Assembly4</translation>
</message>
<message>
<location filename="../../InitGui.py" line="361"/>
<location filename="../../InitGui.py" line="205"/>
<source>Assembly</source>
<translation>Ensamblaje</translation>
</message>
<message>
<location filename="../../InitGui.py" line="210"/>
<source>Selection Filter</source>
<translation>Filtro de selección</translation>
</message>
<message>
<location filename="../../InitGui.py" line="216"/>
<source>done</source>
<translation>hecho</translation>
</message>
<message>
<location filename="../../InitGui.py" line="364"/>
<source>Create</source>
<translation>Crear</translation>
</message>
</context>
<context>
<name>Asm4_Help</name>
<message>
<location filename="../../HelpCmd.py" line="24"/>
<source>Help for Assembly4</source>
<translation>Ayuda para Assembly4</translation>
</message>
<message>
<location filename="../../HelpCmd.py" line="25"/>
<source>Show basic usage for FreeCAD and Assembly4</source>
<translation>Mostrar ayuda de uso básico para FreeCAD y Assembly4</translation>
</message>
</context>
<context>
<name>Asm4_gotoDocument</name>
<message>
<location filename="../../gotoDocumentCmd.py" line="36"/>
<source>Open Document</source>
<translation>Abrir documento</translation>
</message>
<message>
<location filename="../../gotoDocumentCmd.py" line="37"/>
<source>Activates the document of the selected linked part</source>
<translation>Activa el documento de la parte enlazada seleccionada</translation>
</message>
</context>
<context>
<name>Asm4_hideLcs</name>
<message>
<location filename="../../showHideLcsCmd.py" line="55"/>
<source>Hide LCS</source>
<translation>Ocultar LCS</translation>
</message>
<message>
<location filename="../../showHideLcsCmd.py" line="56"/>
<source>Hide LCS and Datums of selected part and its children</source>
<translation>Ocultar LCS y datums de la parte seleccionada y sus hijos</translation>
</message>
</context>
<context>
<name>Asm4_showLcs</name>
<message>
<location filename="../../showHideLcsCmd.py" line="28"/>
<source>Show LCS</source>
<translation>Mostrar LCS</translation>
</message>
<message>
<location filename="../../showHideLcsCmd.py" line="29"/>
<source>Show LCS and Datums of selected part and its children</source>
<translation>Mostrar LCS y datums de la parte seleccionada y sus hijos</translation>
</message>
</context>
<context>
<name>Commands</name>
<message>
<location filename="../../newAssemblyCmd.py" line="41"/>
<source>&lt;p&gt;Create a new Assembly container&lt;/p&gt;</source>
<translation>&lt;p&gt;Crear un nuevo contenedor Ensamblaje&lt;/p&gt;</translation>
</message>
<message>
<location filename="../../newAssemblyCmd.py" line="43"/>
<source>New Assembly</source>
<translation>Nuevo ensamblaje</translation>
</message>
</context>
<context>
<name>Commands1</name>
<message>
<location filename="../../newPartCmd.py" line="35"/>
<source>New Part</source>
<translation>Nueva parte</translation>
</message>
<message>
<location filename="../../newPartCmd.py" line="36"/>
<source>Create a new Part</source>
<translation>Crear una nueva parte</translation>
</message>
<message>
<location filename="../../newPartCmd.py" line="40"/>
<source>New Body</source>
<translation>Nuevo cuerpo</translation>
</message>
<message>
<location filename="../../newPartCmd.py" line="41"/>
<source>Create a new Body</source>
<translation>Crear un nuevo cuerpo</translation>
</message>
<message>
<location filename="../../newPartCmd.py" line="45"/>
<source>New Group</source>
<translation>Nuevo grupo</translation>
</message>
<message>
<location filename="../../newPartCmd.py" line="46"/>
<source>Create a new Group</source>
<translation>Crear un nuevo grupo</translation>
</message>
</context>
<context>
<name>Fasteners</name>
<message>
<location filename="../../FastenersLib.py" line="63"/>
<location filename="../../FastenersDummy.py" line="37"/>
<source>Insert Screw</source>
<translation>Insertar perno</translation>
</message>
<message>
<location filename="../../FastenersLib.py" line="71"/>
<location filename="../../FastenersDummy.py" line="41"/>
<source>Insert Nut</source>
<translation>Insertar tuerca</translation>
</message>
<message>
<location filename="../../FastenersLib.py" line="79"/>
<location filename="../../FastenersDummy.py" line="45"/>
<source>Insert Washer</source>
<translation>Insertar arandela</translation>
</message>
<message>
<location filename="../../FastenersLib.py" line="87"/>
<location filename="../../FastenersDummy.py" line="49"/>
<source>Insert threaded rod</source>
<translation>Insertar barra roscada</translation>
</message>
</context>
<context>
<name>Workbench</name>
<message>
<location filename="../../InitGui.py" line="190"/>
<source>&amp;Assembly</source>
<translation>&amp;Ensamblaje</translation>
</message>
<message>
<location filename="../../InitGui.py" line="200"/>
<source>&amp;Help</source>
<translation>&amp;Ayuda</translation>
</message>
</context>
</TS>
Binary file removed Resources/translations/asm4_es.qm
Binary file not shown.
Loading

0 comments on commit c2e658f

Please sign in to comment.