1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

vue ui i18n: allowed embedded named string variables within translatable strings: e.g. "this {name1} with that {name2}"

This commit is contained in:
Ivan Velev 2022-02-07 18:26:16 -08:00
parent ec02333ba4
commit e6280500ff
3 changed files with 24 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -88,8 +88,8 @@ export default {
}
},
methods: {
_(id) {
return PywbI18N.instance.getText(id);
_(id, embeddedVariableStrings=null) {
return PywbI18N.instance.getText(id, embeddedVariableStrings);
},
gotoPeriod: function(newPeriod, onlyZoomToPeriod) {
if (this.timelineHighlight) {

View File

@ -24,7 +24,14 @@ export class PywbI18N {
getMonth(id, type='long') {
return decodeURIComponent(this.config[PywbI18N.monthIdPrefix[id]+'_'+type]);
}
getText(id) {
return decodeURIComponent(this.config[id] || id);
getText(id, embeddedVariableStrings=null) {
const translated = decodeURIComponent(this.config[id] || id);
if (embeddedVariableStrings && id.indexOf('{') >= 0 && id.indexOf('}') >= 0 ) {
return translated.replace(/{(\w+)}/, (match, stringId) => embeddedVariableStrings[stringId]);
}
return translated
}
_(id, embeddedVariableStrings=null) {
return this.getText(id, embeddedVariableStrings);
}
}