diff --git a/GetItemGroups.py b/GetItemGroups.py index 6e51a27..940e319 100644 --- a/GetItemGroups.py +++ b/GetItemGroups.py @@ -1,8 +1,14 @@ +import FreeCAD as App +import FreeCADGui as Gui + globalGroups = [] itemGroups = None serializedItemGroups = None +# Define the translation +translate = App.Qt.translate + def onResultSelected(index, groupId): global globalGroups @@ -17,8 +23,11 @@ def onResultSelected(index, groupId): QtGui.QMessageBox.warning( None, - "Could not execute this action", - "Could not execute this action, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.", + translate("SearchBar", "Could not execute this action"), + translate( + "SearchBar", + "Could not execute this action, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.", + ), ) @@ -31,7 +40,10 @@ def getToolTip(groupId, setParent): if handlerName in SearchResults.toolTipHandlers: return SearchResults.toolTipHandlers[handlerName](nfo, setParent) else: - return "Could not load tooltip for this tool, it could be from a Mod that has been uninstalled. Try refreshing the list of tools." + return translate( + "SearchBar", + "Could not load tooltip for this tool, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.", + ) def getItemGroups(): diff --git a/InitGui.py b/InitGui.py index 295678e..f6c577b 100644 --- a/InitGui.py +++ b/InitGui.py @@ -1,9 +1,20 @@ +import FreeCAD as App +import FreeCADGui as Gui + # Avoid garbage collection by storing the action in a global variable wax = None sea = None tbr = None +def QT_TRANSLATE_NOOP(context, text): + return text + + +# Define the translation +translate = App.Qt.translate + + def addToolSearchBox(): import FreeCADGui from PySide import QtGui @@ -24,9 +35,13 @@ def addToolSearchBox(): if wax is None: wax = QtGui.QWidgetAction(None) - wax.setWhatsThis("Use this search bar to find tools, document objects, preferences and more") + wax.setWhatsThis( + translate("SearchBar", "Use this search bar to find tools, document objects, preferences and more") + ) - sea.setWhatsThis("Use this search bar to find tools, document objects, preferences and more") + sea.setWhatsThis( + translate("SearchBar", "Use this search bar to find tools, document objects, preferences and more") + ) wax.setDefaultWidget(sea) ##mbr.addWidget(sea) # mbr.addAction(wax) diff --git a/RefreshTools.py b/RefreshTools.py index b97887f..170d705 100644 --- a/RefreshTools.py +++ b/RefreshTools.py @@ -1,17 +1,20 @@ import os import FreeCAD as App +# Define the translation +translate = App.Qt.translate + def loadAllWorkbenches(): from PySide import QtGui import FreeCADGui activeWorkbench = FreeCADGui.activeWorkbench().name() - lbl = QtGui.QLabel("Loading workbench … (…/…)") + lbl = QtGui.QLabel(translate("SearchBar", "Loading workbench … (…/…)")) lbl.show() lst = FreeCADGui.listWorkbenches() for i, wb in enumerate(lst): - msg = "Loading workbench " + wb + " (" + str(i) + "/" + str(len(lst)) + ")" + msg = translate("SearchBar", "Loading workbench ") + wb + " (" + str(i) + "/" + str(len(lst)) + ")" print(msg) lbl.setText(msg) geo = lbl.geometry() @@ -88,8 +91,11 @@ def refreshToolsAction(): fw.clearFocus() reply = QtGui.QMessageBox.question( None, - "Load all workbenches?", - 'Load all workbenches? This can cause FreeCAD to become unstable, and this "reload tools" feature contained a bug that crashed freecad systematically, so please make sure you save your work before. It\'s a good idea to restart FreeCAD after this operation.', + translate("SearchBar", "Load all workbenches?"), + translate( + "SearchBar", + 'Load all workbenches? This can cause FreeCAD to become unstable, and this "reload tools" feature contained a bug that crashed freecad systematically, so please make sure you save your work before. It\'s a good idea to restart FreeCAD after this operation.', + ), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, ) diff --git a/ResultsDocument.py b/ResultsDocument.py index 2e0f8a1..41b6fa0 100644 --- a/ResultsDocument.py +++ b/ResultsDocument.py @@ -5,6 +5,9 @@ import FreeCADGui import SafeViewer import SearchBox +# Define the translation +translate = App.Qt.translate + def documentAction(nfo): act = nfo["action"] diff --git a/ResultsRefreshTools.py b/ResultsRefreshTools.py index d72d900..a4267f8 100644 --- a/ResultsRefreshTools.py +++ b/ResultsRefreshTools.py @@ -1,3 +1,6 @@ +import FreeCAD as App +import FreeCADGui as Gui + import os from PySide import QtGui import Serialize_SearchBar @@ -5,6 +8,9 @@ import Parameters_SearchBar as Parameters genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap)) +# Define the translation +translate = App.Qt.translate + def refreshToolsAction(nfo): import RefreshTools @@ -15,7 +21,12 @@ def refreshToolsAction(nfo): def refreshToolsToolTip(nfo, setParent): return ( Serialize_SearchBar.iconToHTML(genericToolIcon) - + "
Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.
" + + "" + + translate( + "SearchBar", + "Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.", + ) + + "
" ) diff --git a/ResultsToolbar.py b/ResultsToolbar.py index ec41db2..77967a4 100644 --- a/ResultsToolbar.py +++ b/ResultsToolbar.py @@ -1,7 +1,11 @@ +import FreeCAD as App from PySide import QtGui import FreeCADGui import Serialize_SearchBar +# Define the translation +translate = App.Qt.translate + def toolbarAction(nfo): act = nfo["action"] diff --git a/SafeViewer.py b/SafeViewer.py index 2832b95..dbf5a61 100644 --- a/SafeViewer.py +++ b/SafeViewer.py @@ -1,5 +1,8 @@ from PySide import QtGui -import FreeCAD +import FreeCAD as App + +# Define the translation +translate = App.Qt.translate class SafeViewer(QtGui.QWidget): @@ -7,7 +10,7 @@ class SafeViewer(QtGui.QWidget): FreeCAD's FreeCADGui.createViewer() puts the viewer widget inside an MDI window, and detaching it without causing segfaults on exit is tricky. This class contains some kludges to extract the viewer as a standalone widget and destroy it safely.""" - enabled = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool("PreviewEnabled", False) + enabled = App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").GetBool("PreviewEnabled", False) instances = [] def __init__(self, parent=None): @@ -27,11 +30,18 @@ class SafeViewer(QtGui.QWidget): self.lbl_warning.setReadOnly(True) self.lbl_warning.setAlignment(QtCore.Qt.AlignTop) self.lbl_warning.setText( - "Warning: the 3D preview has some stability issues. It can cause FreeCAD to crash (usually when quitting the application) and could in theory cause data loss, inside and outside of FreeCAD." + translate( + "SearchBar", + "Warning: the 3D preview has some stability issues. It can cause FreeCAD to crash (usually when quitting the application) and could in theory cause data loss, inside and outside of App.", + ) + ) + self.btn_enable_for_this_session = QtGui.QPushButton( + translate("SearchBar", "Enable 3D preview for this session") ) - self.btn_enable_for_this_session = QtGui.QPushButton("Enable 3D preview for this session") self.btn_enable_for_this_session.clicked.connect(self.enable_for_this_session) - self.btn_enable_for_future_sessions = QtGui.QPushButton("Enable 3D preview for future sessions") + self.btn_enable_for_future_sessions = QtGui.QPushButton( + translate("SearchBar", "Enable 3D preview for future sessions") + ) self.btn_enable_for_future_sessions.clicked.connect(self.enable_for_future_sessions) self.setLayout(QtGui.QVBoxLayout()) self.layout().addWidget(self.lbl_warning) @@ -46,7 +56,7 @@ class SafeViewer(QtGui.QWidget): def enable_for_future_sessions(self): if not SafeViewer.enabled: # Store in prefs - FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").SetBool("PreviewEnabled", True) + App.ParamGet("User parameter:BaseApp/Preferences/Mod/SearchBar").SetBool("PreviewEnabled", True) # Then enable as usual self.enable_for_this_session() diff --git a/SearchBox.py b/SearchBox.py index 3a81a68..45fd0be 100644 --- a/SearchBox.py +++ b/SearchBox.py @@ -1,4 +1,5 @@ -import FreeCADGui as Gui # just used for FreeCADGui.updateGui() +import FreeCAD as App +import FreeCADGui as Gui import os from PySide.QtCore import ( @@ -44,6 +45,9 @@ genericToolIcon = QIcon(Parameters.genericToolIcon_Pixmap) globalIgnoreFocusOut = False +# Define the translation +translate = App.Qt.translate + def easyToolTipWidget(html): foo = QTextEdit() @@ -170,7 +174,7 @@ class SearchBox(QLineEdit): mdl = QStandardItemModel() mdl.appendRow( [ - QStandardItem(genericToolIcon, "Please wait, loading results from cache…"), + QStandardItem(genericToolIcon, translate("SearchBar", "Please wait, loading results from cache…")), QStandardItem("0"), QStandardItem("-1"), ] diff --git a/translations/README.md b/translations/README.md new file mode 100644 index 0000000..ae84e37 --- /dev/null +++ b/translations/README.md @@ -0,0 +1,104 @@ +# About translating Ribbon Addon + +> [!NOTE] +> All commands **must** be run in `./translations/` directory. + +> [!IMPORTANT] +> If you want to update/release the files you need to have installed +> `lupdate` and `lrelease` from Qt6 version. Using the versions from +> Qt5 is not advised because they're buggy. + +## Updating translations template file + +To update the template file from source files you should use this command: + +```shell +./update_translation.sh -U +``` + +Once done you can commit the changes and upload the new file to CrowdIn platform +at