-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.qmd
More file actions
154 lines (107 loc) · 3.95 KB
/
i18n.qmd
File metadata and controls
154 lines (107 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Translating Your Module {#sec-i18n}
JASP is used worldwide. Every user-visible string — in QML forms, R output, and C++ code — must be marked for translation so that volunteer translators can localise JASP via Weblate.
## How Translation Works
```{mermaid}
flowchart LR
A[Developer marks strings] --> B[Weblate extracts marked strings]
B --> C[Translators provide translations]
C --> D[JASP displays translated text at runtime]
```
- **QML**: `qsTr("text")` → extracted by Qt's `lupdate` tool.
- **R**: `gettext("text")` / `gettextf("text %s", var)` → extracted by R's translation tooling.
- **C++**: `tr("text")` → extracted by Qt's `lupdate` tool.
## QML Translation
Wrap every user-visible string in `qsTr()`:
```qml
CheckBox { name: "meanDifference"; label: qsTr("Mean difference") }
Group
{
title: qsTr("Statistics")
CheckBox { name: "effectSize"; label: qsTr("Effect size") }
}
```
### Parameters in QML
Use `%1`, `%2`, etc. for substitutions:
```qml
text: qsTr("Group %1 vs Group %2").arg(group1Name).arg(group2Name)
```
## R Translation
### gettext() — Simple Strings
```r
table$addColumnInfo(name = "estimate", title = gettext("Estimate"), type = "number")
```
### gettextf() — Strings with Parameters
Use `sprintf`-style format specifiers:
```r
message <- gettextf("Variable '%s' has %d observations.", varName, nObs)
```
### Numbered Arguments
When a string has multiple parameters, use numbered format specifiers (`%1$s`, `%2$d`) so translators can reorder them:
```r
# Good — translators can reorder
gettextf("Compared %1$s with %2$s using %3$s.", group1, group2, method)
# Bad — translators cannot reorder
gettextf("Compared %s with %s using %s.", group1, group2, method)
```
### Plurals with ngettext()
```r
msg <- ngettext(nObs,
"Only 1 observation. At least 2 are required.",
"Only %d observations. At least 2 are required."
)
```
### Unicode Characters
Use `\uXXXX` escapes, never raw Unicode characters or `intToUtf8()`:
```r
# Good
"\u2260" # ≠
# Bad
"≠" # fails on some locales
intToUtf8(8800) # not translatable
```
## Common Patterns
### Converting paste() to gettextf()
`paste()` concatenation cannot be translated because word order differs across languages. Always convert to `gettextf()`:
```r
# Bad — untranslatable
message <- paste("Variable", varName, "has", nObs, "observations")
# Good — translatable
message <- gettextf("Variable '%1$s' has %2$d observations.", varName, nObs)
```
### Wrapping Expressions
If you construct expressions for display:
```r
# Wrap the template, not the variable name
title <- gettextf("P(%1$s | data)", hypothesis)
```
### Table Titles and Column Names
Every `title` in `createJaspTable()` and `addColumnInfo()` must be wrapped:
```r
table <- createJaspTable(title = gettext("Descriptive Statistics"))
table$addColumnInfo(name = "mean", title = gettext("Mean"), type = "number")
table$addColumnInfo(name = "sd", title = gettext("SD"), type = "number")
table$addColumnInfo(name = "n", title = gettext("N"), type = "integer")
```
### Footnotes and Error Messages
```r
table$addFootnote(message = gettext("Levene's test is significant (p < .05)."))
table$setError(gettext("The dependent variable contains only missing values."))
```
## What NOT to Translate
- Option names (`name:` in QML, keys in `options[[...]]` in R)
- Column/row name keys (the `name` parameter in `addColumnInfo`)
- Internal log messages
- Code comments
- Variable names used in computation
## C++ Translation
Use `tr()` inside QObject-derived classes:
```cpp
QString message = tr("Analysis complete");
```
For non-QObject code, use `QCoreApplication::translate()`.
## Quick Reference
| Language | Simple string | With parameters | Plural |
|----------|--------------|-----------------|--------|
| QML | `qsTr("text")` | `qsTr("x %1").arg(v)` | — |
| R | `gettext("text")` | `gettextf("x %s", v)` | `ngettext(n, "one", "many")` |
| C++ | `tr("text")` | `tr("x %1").arg(v)` | — |