Skip to content

Commit

Permalink
Translatable modes and sources #209
Browse files Browse the repository at this point in the history
  • Loading branch information
sbs20 committed Apr 26, 2021
1 parent acec67b commit 73655da
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions webui/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

<v-select v-if="'--source' in device.features"
:label="$t('scan.source')" v-model="request.params.source"
:items="device.features['--source']['options']"></v-select>
:items="sources" item-value="value" item-text="text"></v-select>

<v-select
:label="$t('scan.resolution')" v-model="request.params.resolution"
:items="device.features['--resolution']['options']"></v-select>

<v-select
:label="$t('scan.mode')" v-model="request.params.mode"
:items="device.features['--mode']['options']"></v-select>
:items="modes" item-value="value" item-text="text"></v-select>

<v-select v-if="'--disable-dynamic-lineart' in device.features"
:label="$t('scan.dynamic-lineart')" v-model="request.params.mode"
Expand Down Expand Up @@ -135,6 +135,10 @@ function round(n, dp) {
return Math.round(n * f) / f;
}
function sanitiseLocaleKey(s) {
return s.toLowerCase().replace('[', '(').replace(']', ')');
}
export default {
name: 'Scan',
components: {
Expand Down Expand Up @@ -195,6 +199,17 @@ export default {
});
},
modes() {
return this.device.features['--mode'].options.map(mode => {
const key = `mode.${sanitiseLocaleKey(mode)}`;
let translation = this.$t(key);
return {
text: translation === key ? mode : translation,
value: mode
};
});
},
paperSizes() {
const deviceSize = {
x: this.device.features['-x'].limits[1],
Expand All @@ -219,6 +234,17 @@ export default {
value: p
};
});
},
sources() {
return this.device.features['--source'].options.map(source => {
const key = `source.${sanitiseLocaleKey(source)}`;
let translation = this.$t(key);
return {
text: translation === key ? source : translation,
value: source
};
});
}
},
Expand Down Expand Up @@ -400,9 +426,9 @@ export default {
return this._fetch(url).then(context => {
window.clearTimeout(timer);
this.context = context;
if (context.devices.length > 0) {
if (context.devices && context.devices.length > 0) {
this.context = context;
this.device = context.devices[0];
this.request = this.buildRequest();
for (let test of context.diagnostics) {
Expand Down

0 comments on commit 73655da

Please sign in to comment.