Skip to content

Commit e28ed81

Browse files
committed
Add tr function to simplify translations
1 parent c465d98 commit e28ed81

13 files changed

+68
-55
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ pot:
8181
--add-comments=TRANSLATORS: \
8282
--no-wrap \
8383
*/*.py
84+
8485
xgettext \
8586
--output=$(POT_FILE) \
8687
--language=JavaScript \
8788
--from-code=UTF-8 \
8889
--join-existing \
90+
--keyword=tr:1 \
8991
--keyword=qsTranslate:2 \
9092
--add-comments=TRANSLATORS: \
9193
--no-wrap \
9294
*/*.qml
95+
9396
cat */*.json \
9497
| grep '^ *"_' \
9598
| sed 's/: *\("[^"]*"\)/: _(\1)/' \

qml/AboutPage.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ Page {
3333
width: parent.width
3434

3535
PageHeader {
36-
title: qsTranslate("", "About Pan Transit")
36+
title: app.tr("About Pan Transit")
3737
}
3838

3939
ListItemLabel {
4040
height: Theme.itemSizeExtraSmall
4141
horizontalAlignment: Text.AlignHCenter
42-
text: qsTranslate("", "version %1").arg(py.evaluate("pan.__version__"))
42+
text: app.tr("version %1", py.evaluate("pan.__version__"))
4343
}
4444

4545
Button {
4646
anchors.horizontalCenter: parent.horizontalCenter
4747
height: Theme.itemSizeLarge
4848
preferredWidth: Theme.buttonWidthMedium
49-
text: qsTranslate("", "GitHub page")
49+
text: app.tr("GitHub page")
5050
onClicked: Qt.openUrlExternally("https://github.com/otsaloma/pan-transit");
5151
}
5252

@@ -63,12 +63,12 @@ Page {
6363
horizontalAlignment: implicitWidth >
6464
parent.width - anchors.leftMargin - anchors.rightMargin ?
6565
Text.AlignLeft : Text.AlignHCenter
66-
text: qsTranslate("", "Pan Transit is free software released under the GNU General Public License (GPL), version 3 or later.")
66+
text: app.tr("Pan Transit is free software released under the GNU General Public License (GPL), version 3 or later.")
6767
wrapMode: Text.WordWrap
6868
}
6969

7070
SectionHeader {
71-
text: qsTranslate("", "Translated by")
71+
text: app.tr("Translated by")
7272
}
7373

7474
ListItemLabel {
@@ -80,7 +80,7 @@ Page {
8080
// Thus, you should translate it to your name. You can also include other
8181
// translators who have contributed to this translation; in that case, please
8282
// write them on separate lines seperated by newlines (\n).
83-
text: qsTranslate("", "translator-credits")
83+
text: app.tr("translator-credits")
8484
visible: text && text !== "translator-credits"
8585
}
8686

@@ -90,15 +90,15 @@ Page {
9090
horizontalAlignment: implicitWidth >
9191
parent.width - anchors.leftMargin - anchors.rightMargin ?
9292
Text.AlignLeft : Text.AlignHCenter
93-
text: qsTranslate("", "You can add new user interface translations or contribute to existing ones at Transifex.")
93+
text: app.tr("You can add new user interface translations or contribute to existing ones at Transifex.")
9494
wrapMode: Text.WordWrap
9595
}
9696

9797
Button {
9898
anchors.horizontalCenter: parent.horizontalCenter
9999
height: Theme.itemSizeLarge
100100
preferredWidth: Theme.buttonWidthMedium
101-
text: qsTranslate("", "Transifex page")
101+
text: app.tr("Transifex page")
102102
onClicked: Qt.openUrlExternally("https://www.transifex.com/otsaloma/pan-transit/");
103103
}
104104

qml/AddFavoritePage.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ Dialog {
6060
anchors.right: parent.right
6161
anchors.rightMargin: Theme.horizontalPageMargin
6262
currentIndex: 0
63-
label: qsTranslate("", "Favorite")
63+
label: app.tr("Favorite")
6464
menu: ContextMenu {
65-
MenuItem { text: qsTranslate("", "Create new") }
66-
MenuItem { text: qsTranslate("", "Add to existing") }
65+
MenuItem { text: app.tr("Create new") }
66+
MenuItem { text: app.tr("Add to existing") }
6767
}
6868
onCurrentIndexChanged: {
6969
// Show either nameField or view.
@@ -85,7 +85,7 @@ Dialog {
8585
anchors.right: parent.right
8686
anchors.rightMargin: Theme.horizontalPageMargin
8787
height: visible ? implicitHeight : 0
88-
label: qsTranslate("", "Name")
88+
label: app.tr("Name")
8989
text: page.name
9090
EnterKey.enabled: text.length > 0
9191
EnterKey.onClicked: page.accept();

qml/EditFavoritePage.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Dialog {
7070
ContextMenu {
7171
id: contextMenu
7272
MenuItem {
73-
text: qsTranslate("", "Remove")
73+
text: app.tr("Remove")
7474
onClicked: {
7575
// Mark stop to be removed once dialog is accepted.
7676
page.removals.push(model.id);
@@ -99,7 +99,7 @@ Dialog {
9999
anchors.leftMargin: Theme.horizontalPageMargin
100100
anchors.right: parent.right
101101
anchors.rightMargin: Theme.horizontalPageMargin
102-
label: qsTranslate("", "Name")
102+
label: app.tr("Name")
103103
text: page.name
104104
EnterKey.enabled: text.length > 0
105105
EnterKey.iconSource: "image://theme/icon-m-enter-close"
@@ -108,7 +108,7 @@ Dialog {
108108

109109
SectionHeader {
110110
id: titleLabel
111-
text: qsTranslate("", "Stops")
111+
text: app.tr("Stops")
112112
}
113113

114114
Component.onCompleted: page.nameField = nameField;

qml/FavoritePage.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Page {
5757
visible: !page.loading || false
5858

5959
MenuItem {
60-
text: qsTranslate("", "Filter lines")
60+
text: app.tr("Filter lines")
6161
onClicked: {
6262
var options = {"stops": page.stops, "ignores": page.ignores};
6363
var dialog = pageStack.push("LineFilterPage.qml", options);
@@ -67,7 +67,7 @@ Page {
6767
view.model.clear();
6868
page.loading = true;
6969
page.title = "";
70-
busy.text = qsTranslate("", "Loading");
70+
busy.text = app.tr("Loading");
7171
page.populate();
7272
});
7373
}
@@ -99,7 +99,7 @@ Page {
9999
view.model.clear();
100100
page.loading = true;
101101
page.title = "";
102-
busy.text = qsTranslate("", "Loading");
102+
busy.text = app.tr("Loading");
103103
} else if (page.status === PageStatus.Active) {
104104
page.populate();
105105
}
@@ -135,7 +135,7 @@ Page {
135135
}
136136
} else {
137137
silent || (page.title = "");
138-
silent || (busy.error = qsTranslate("", "No departures found"));
138+
silent || (busy.error = app.tr("No departures found"));
139139
}
140140
page.downloadTime = Date.now();
141141
page.loading = false;

qml/LineFilterPage.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ Dialog {
7373
id: menu
7474
visible: !page.loading && view.model.count > 0
7575
MenuItem {
76-
text: qsTranslate("", "Mark all")
76+
text: app.tr("Mark all")
7777
onClicked: menu.setAllChecked(true);
7878
}
7979
MenuItem {
80-
text: qsTranslate("", "Unmark all")
80+
text: app.tr("Unmark all")
8181
onClicked: menu.setAllChecked(false);
8282
}
8383
function setAllChecked(checked) {
@@ -97,7 +97,7 @@ Dialog {
9797

9898
Component.onCompleted: {
9999
page.loading = true;
100-
busy.text = qsTranslate("", "Loading")
100+
busy.text = app.tr("Loading")
101101
page.populate();
102102
}
103103

@@ -131,7 +131,7 @@ Dialog {
131131
view.model.append(results[i]);
132132
}
133133
} else {
134-
busy.error = qsTranslate("", "No lines found");
134+
busy.error = app.tr("No lines found");
135135
}
136136
page.loading = false;
137137
});

qml/MenuPage.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Page {
4545
menu: ContextMenu {
4646
id: contextMenu
4747
MenuItem {
48-
text: qsTranslate("", "Edit")
48+
text: app.tr("Edit")
4949
onClicked: page.editFavorite(model.index);
5050
}
5151
MenuItem {
52-
text: qsTranslate("", "Remove")
52+
text: app.tr("Remove")
5353
onClicked: page.removeFavorite(listItem, model.index);
5454
}
5555
onActiveChanged: view.menuOpen = contextMenu.active;
@@ -69,17 +69,17 @@ Page {
6969
PullDownMenu {
7070

7171
MenuItem {
72-
text: qsTranslate("", "About")
72+
text: app.tr("About")
7373
onClicked: app.pageStack.push("AboutPage.qml");
7474
}
7575

7676
MenuItem {
77-
text: qsTranslate("", "Preferences")
77+
text: app.tr("Preferences")
7878
onClicked: app.pageStack.push("PreferencesPage.qml");
7979
}
8080

8181
MenuItem {
82-
text: qsTranslate("", "Search")
82+
text: app.tr("Search")
8383
onClicked: {
8484
app.pageStack.push("SearchPage.qml");
8585
app.pageStack.pushAttached("SearchResultsPage.qml");
@@ -88,7 +88,7 @@ Page {
8888

8989
MenuItem {
9090
enabled: gps.ready
91-
text: qsTranslate("", "Nearby")
91+
text: app.tr("Nearby")
9292
onClicked: app.pageStack.push("NearbyPage.qml");
9393
}
9494

@@ -97,7 +97,7 @@ Page {
9797
ViewPlaceholder {
9898
id: viewPlaceholder
9999
enabled: false
100-
text: qsTranslate("", "Once added, favorites appear here. Pull down to select a provider and to search for stops.")
100+
text: app.tr("Once added, favorites appear here. Pull down to select a provider and to search for stops.")
101101
}
102102

103103
BusyIndicator {
@@ -164,7 +164,7 @@ Page {
164164

165165
function removeFavorite(listItem, index) {
166166
// Remove favorite at index.
167-
listItem.remorseAction(qsTranslate("", "Removing"), function() {
167+
listItem.remorseAction(app.tr("Removing"), function() {
168168
var item = view.model.get(index);
169169
py.call_sync("pan.app.favorites.remove", [item.key]);
170170
view.model.remove(index);

qml/NearbyPage.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Page {
7171
view.model.clear();
7272
page.loading = true;
7373
page.title = "";
74-
busy.text = qsTranslate("", "Searching");
74+
busy.text = app.tr("Searching");
7575
} else if (page.status === PageStatus.Active) {
7676
page.populate();
7777
}
@@ -88,12 +88,12 @@ Page {
8888
busy.error = results.message;
8989
} else if (results && results.length > 0) {
9090
page.results = results;
91-
page.title = qsTranslate("", "%1 Stops").arg(results.length);
91+
page.title = app.tr("%1 Stops", results.length);
9292
for (var i = 0; i < results.length; i++)
9393
view.model.append(results[i]);
9494
} else {
9595
page.title = "";
96-
busy.error = qsTranslate("", "No stops found");
96+
busy.error = app.tr("No stops found");
9797
}
9898
page.loading = false;
9999
page.populated = true;

qml/PreferencesPage.qml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ Page {
3434
anchors.fill: parent
3535

3636
PageHeader {
37-
title: qsTranslate("", "Preferences")
37+
title: app.tr("Preferences")
3838
}
3939

4040
ValueButton {
4141
id: providerButton
42-
label: qsTranslate("", "Provider")
42+
label: app.tr("Provider")
4343
height: Theme.itemSizeSmall
4444
value: py.evaluate("pan.app.provider.name")
4545
width: parent.width
@@ -52,13 +52,13 @@ Page {
5252
}
5353

5454
SectionHeader {
55-
text: qsTranslate("", "Display")
55+
text: app.tr("Display")
5656
}
5757

5858
TextField {
5959
id: radiusField
6060
inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
61-
label: qsTranslate("", "Favorite highlight radius (m)")
61+
label: app.tr("Favorite highlight radius (m)")
6262
text: app.conf.get("favorite_highlight_radius").toString()
6363
validator: RegExpValidator { regExp: /^[0-9]+$/ }
6464
width: parent.width
@@ -77,7 +77,7 @@ Page {
7777
TextField {
7878
id: cutOffField
7979
inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
80-
label: qsTranslate("", "Departure time cutoff (min)")
80+
label: app.tr("Departure time cutoff (min)")
8181
text: app.conf.get("departure_time_cutoff").toString()
8282
validator: RegExpValidator { regExp: /^[0-9]+$/ }
8383
width: parent.width
@@ -97,18 +97,18 @@ Page {
9797
color: Theme.secondaryColor
9898
font.pixelSize: Theme.fontSizeSmall
9999
height: implicitHeight + 2 * Theme.paddingMedium
100-
text: qsTranslate("", "When the time remaining to departure is below cutoff, it is shown as minutes remaining instead of the departure time.")
100+
text: app.tr("When the time remaining to departure is below cutoff, it is shown as minutes remaining instead of the departure time.")
101101
verticalAlignment: Text.AlignVCenter
102102
wrapMode: Text.WordWrap
103103
}
104104

105105
ComboBox {
106106
id: unitsComboBox
107-
label: qsTranslate("", "Units")
107+
label: app.tr("Units")
108108
menu: ContextMenu {
109-
MenuItem { text: qsTranslate("", "Metric") }
110-
MenuItem { text: qsTranslate("", "American") }
111-
MenuItem { text: qsTranslate("", "British") }
109+
MenuItem { text: app.tr("Metric") }
110+
MenuItem { text: app.tr("American") }
111+
MenuItem { text: app.tr("British") }
112112
}
113113
property var values: ["metric", "american", "british"]
114114
Component.onCompleted: {

qml/SearchPage.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Page {
4949
ContextMenu {
5050
id: contextMenu
5151
MenuItem {
52-
text: qsTranslate("", "Remove")
52+
text: app.tr("Remove")
5353
onClicked: {
5454
py.call_sync("pan.app.history.remove", [model.name]);
5555
var index = page.history.indexOf(model.name);
@@ -74,12 +74,12 @@ Page {
7474

7575
PageHeader {
7676
id: header
77-
title: qsTranslate("", "Search")
77+
title: app.tr("Search")
7878
}
7979

8080
SearchField {
8181
id: searchField
82-
placeholderText: qsTranslate("", "Stop name or number")
82+
placeholderText: app.tr("Stop name or number")
8383
width: parent.width
8484
EnterKey.enabled: text.length > 0
8585
EnterKey.onClicked: app.pageStack.navigateForward();

0 commit comments

Comments
 (0)