-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combine and reuse translations? #315
Comments
Good idea. Not sure if statically appending will be applicable in every language (sometimes prepending might be needed?), but i18next's "nesting" combined with "interpolation" worked for me: diff --git a/js/index.js b/js/index.js
index cc19ee7..519241e 100644
--- a/js/index.js
+++ b/js/index.js
@@ -78,7 +78,7 @@
function() {
routing.reverse();
},
- i18next.t('map.reverse-route')
+ i18next.t('keyboard.generic-shortcut', { action: '$t(map.reverse-route)', key: 'R' })
);
var deletePointButton = L.easyButton(
diff --git a/js/plugin/stravaSegments.js b/js/plugin/stravaSegments.js
index a4de7ec..626a9db 100644
--- a/js/plugin/stravaSegments.js
+++ b/js/plugin/stravaSegments.js
@@ -1,8 +1,8 @@
BR.stravaSegments = function(map, layersControl) {
var stravaControl = L.control
.stravaSegments({
- runningTitle: i18next.t('map.strava-running'),
- bikingTitle: i18next.t('map.strava-biking'),
+ runningTitle: i18next.t('map.strava-shortcut', { action: '$t(map.strava-running)', key: 'S' }),
+ bikingTitle: i18next.t('map.strava-shortcut', { action: '$t(map.strava-biking)', key: 'S' }),
loadingTitle: i18next.t('map.loading'),
stravaToken: BR.keys.strava
})
diff --git a/locales/en.json b/locales/en.json
index 56573bf..cc25042 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -126,12 +126,13 @@
"opacity-slider": "Set transparency of route track and markers\n(Hold M key to mute temporarily)",
"preview": "Preview",
"privacy": "Privacy",
- "reverse-route": "Reverse route (R key)",
+ "reverse-route": "Reverse route",
"route-quality-altitude": "Altitude coding (C key to toggle)",
"route-quality-cost": "Cost coding (C key to toggle)",
"route-quality-incline": "Incline coding (C key to toggle)",
- "strava-biking": "Show Strava biking segments\n(S key to toggle layer, click to reload for current area)",
- "strava-running": "Show Strava running segments\n(S key to toggle layer, click to reload for current area)",
+ "strava-biking": "Show Strava biking segments",
+ "strava-running": "Show Strava running segments",
+ "strava-shortcut": "{{action}}\n({{key}} key to toggle layer, click to reload for current area)",
"zoomInTitle": "Zoom in (+ key)",
"zoomOutTitle": "Zoom out (- key)"
},
@@ -266,5 +267,8 @@
"temporary-profile": "<strong>Note:</strong> Uploaded custom profiles are only cached temporarily on the server.<br/>Please save your edits to your local PC.",
"tracks-load-error": "Error loading tracks: {{error}}",
"upload-error": "Upload error: {{error}}"
+ },
+ "keyboard": {
+ "generic-shortcut": "{{action}} ({{key}} Key)"
}
} Let me know if I should continue with this approach and send a PR. |
PR: #317 Couldn't get
Therefore, I'm using |
Probably that needs to be set here (not tested). |
Thanks for the tip. I already tried this before, but it did not help. However, now that I tried it again, I noticed I have to remove Updated PR. |
Hm, Ok, good to know. |
#314 appends keyboard shortcuts to tooltip texts like this (see en.json diff):
I wonder if we can make translator's life easier by combining the tooltip text itself and the key appendix in a more generic fashion.
Maybe by using nesting, leaving the original translations untouched and using a new translation key that concatenates both, e.g. (untested):
Or, maybe if append works with attributes like this (also untested):
with
The text was updated successfully, but these errors were encountered: