Skip to content

Commit bcba2ab

Browse files
authored
Add translation special cases section
1 parent 5f6ca27 commit bcba2ab

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

technical/translation.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,48 @@ print(translate("MyMod", "There are {} widgets present, out of {} total").format
134134

135135
(Note that the string sent to translators is "There are {} widgets present, out of {} total" -- the format function is called on the string that is *returned* from the translate function).
136136

137+
## Special Cases
138+
139+
There are several places in FreeCAD where specific procedures must be followed to ensure translations are correct:
140+
141+
### Preference Pages
142+
143+
Whether using `addPreferencePage` in Python, or `new Gui::PrefPageProducer` in C++, the "Group" of the page must use the NOOP-functions and the `QObject` context.
144+
145+
In Python this is:
146+
```python
147+
FreeCADGui.addPreferencePage("somePage.ui", QT_TRANSLATE_NOOP("QObject", "SomeGroupName"))
148+
```
149+
and in C++,
150+
```cpp
151+
new Gui::PrefPageProducer<SomeClass> (QT_TRANSLATE_NOOP("QObject","SomeGroupName"));
152+
```
153+
154+
### Exceptions
155+
156+
C++ exceptions that may end up displayed to the user should be put inside a QT_TRANSLATE_NOOP with the `Exception` context, e.g.
157+
```cpp
158+
throw MyException(QT_TRANSLATE_NOOP("Exception", "Something bad happened"));
159+
```
160+
161+
### Commands
162+
163+
When creating a new command, use the following template:
164+
```cpp
165+
CmdDoAThing::CmdDoAThing()
166+
:Command("MyWorkbench_DoAThing")
167+
{
168+
sAppModule = "MyWorkbench";
169+
sGroup = "MyWorkbench";
170+
sMenuText = QT_TR_NOOP("Do a thing");
171+
sToolTipText = QT_TR_NOOP("A longer explanation of doing a thing");
172+
sWhatsThis = "MyWorkbench_DoAThing";
173+
sStatusTip = sToolTipText;
174+
sPixmap = "MyWorkbench_DoAThing";
175+
}
176+
```
177+
Note that `sGroup` should not be translated here (you will still find many counterexamples in older code, however).
178+
137179
## UI Files
138180

139181
For the most part, all strings in UI files are automatically subject to translation. In some circumstances you may want to *disable* that translation. Using Qt Designer, uncheck the "translatable" checkbox on the widget that you want to disable translation for.

0 commit comments

Comments
 (0)