Skip to content

Commit

Permalink
refactor: override typings for $t and remove string casting
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga committed Dec 30, 2020
1 parent 8e05e3c commit 7c559ab
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 26 deletions.
24 changes: 12 additions & 12 deletions components/Buttons/TypeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ export default Vue.extend({
switch (this.type) {
case 'movies':
return [
{ name: this.$t('movies').toString(), value: 'Movie' },
{ name: this.$t('collections').toString(), value: 'BoxSet' },
{ name: this.$t('actors').toString(), value: 'Actor' },
{ name: this.$t('genres').toString(), value: 'Genre' },
{ name: this.$t('studios').toString(), value: 'Studio' }
{ name: this.$t('movies'), value: 'Movie' },
{ name: this.$t('collections'), value: 'BoxSet' },
{ name: this.$t('actors'), value: 'Actor' },
{ name: this.$t('genres'), value: 'Genre' },
{ name: this.$t('studios'), value: 'Studio' }
];
case 'music':
return [
{ name: this.$t('albums').toString(), value: 'MusicAlbum' },
{ name: this.$t('artists').toString(), value: 'MusicArtist' },
{ name: this.$t('genres').toString(), value: 'MusicGenre' }
{ name: this.$t('albums'), value: 'MusicAlbum' },
{ name: this.$t('artists'), value: 'MusicArtist' },
{ name: this.$t('genres'), value: 'MusicGenre' }
];
case 'tvshows':
return [
{ name: this.$t('series').toString(), value: 'Series' },
{ name: this.$t('actors').toString(), value: 'Actor' },
{ name: this.$t('genres').toString(), value: 'Genre' },
{ name: this.$t('networks').toString(), value: 'Studio' }
{ name: this.$t('series'), value: 'Series' },
{ name: this.$t('actors'), value: 'Actor' },
{ name: this.$t('genres'), value: 'Genre' },
{ name: this.$t('networks'), value: 'Studio' }
];
default:
return [];
Expand Down
2 changes: 1 addition & 1 deletion components/Item/ItemMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default Vue.extend({
const menuItems = [] as MenuItem[];
if (this.$auth.$state.user.Policy.IsAdministrator) {
menuItems.push({
title: this.$t('editMetadata') as string,
title: this.$t('editMetadata'),
action: () => {
this.dialog = true;
}
Expand Down
2 changes: 1 addition & 1 deletion components/Item/MediaInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default Vue.extend({
// TODO: Use a Date object
return this.$t('endsAt', {
time: endTimeShort
}).toString();
});
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/Item/Metadata/MetadataEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export default Vue.extend({
}
this.$store.dispatch('snackbar/display', {
message: errorMessage.toString(),
message: errorMessage,
color: 'error'
});
}
Expand Down
4 changes: 2 additions & 2 deletions components/Layout/HomeHeader/HomeHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default Vue.extend({
}
if (this.items.length === 0) {
this.extraText = this.$t('homeHeader.welcome.noItems').toString();
this.extraText = this.$t('homeHeader.welcome.noItems');
} else {
this.extraText = this.$t('homeHeader.welcome.checkNewItems').toString();
this.extraText = this.$t('homeHeader.welcome.checkNewItems');
}
window.setTimeout(this.hideWelcomeMessage, 1500);
},
Expand Down
2 changes: 1 addition & 1 deletion components/Players/VideoPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default Vue.extend({
});
} else {
this.$nuxt.error({
message: this.$t('browserNotSupported') as string
message: this.$t('browserNotSupported')
});
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion components/Users/UserCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default Vue.extend({
locale: this.getDfnsLocale()
});
} else {
return this.$t('never').toString();
return this.$t('never');
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default Vue.extend({
return [
{
icon: 'mdi-home',
title: this.$t('home').toString(),
title: this.$t('home'),
to: '/'
}
];
Expand All @@ -156,12 +156,12 @@ export default Vue.extend({
return [
{
icon: 'mdi-pencil-outline',
title: this.$t('metadata').toString(),
title: this.$t('metadata'),
to: '/metadata'
},
{
icon: 'mdi-cog',
title: this.$t('settings').toString(),
title: this.$t('settings'),
to: '/settings'
}
];
Expand Down
23 changes: 23 additions & 0 deletions nuxt-i18n.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import VueI18n, { Path, Values } from 'vue-i18n/types';

/**
* Overloads VueI18n interface to avoid needing to cast return value to string.
* See https://github.com/kazupon/vue-i18n/issues/410
*/
declare module 'vue-i18n/types' {
export default class VueI18n {
t(key: Path, values?: Values): string;
}
}

declare module 'vue/types/vue' {
interface Vue {
$t: typeof VueI18n.prototype.t;
}

interface VueConstructor {
i18n: typeof VueI18n.prototype;
}
}

export default VueI18n;
2 changes: 1 addition & 1 deletion pages/genre/_itemId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default Vue.extend({
// Can't get given library ID
this.$nuxt.error({
statusCode: 404,
message: this.$t('libraryNotFound') as string
message: this.$t('libraryNotFound')
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion pages/item/_itemId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export default Vue.extend({
...mapActions('backdrop', ['setBackdrop', 'clearBackdrop']),
getLanguageName(code?: string): string {
if (!code) {
return this.$t('undefined').toString();
return this.$t('undefined');
}
return langs.where('2B', code).name;
},
Expand Down
2 changes: 1 addition & 1 deletion pages/library/_viewId.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default Vue.extend({
// Can't get given library ID
this.$nuxt.error({
statusCode: 404,
message: this.$t('libraryNotFound') as string
message: this.$t('libraryNotFound')
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/veeValidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const veeValidate: Plugin = ({ app }) => {
configure({
defaultMessage: (_field, values) => {
// values._field_ = app.i18n.t(`fields.${field}`);
return app.i18n.t(`validation.${values._rule_}`, values).toString();
return app.i18n.t(`validation.${values._rule_}`, values);
}
});
};
Expand Down

0 comments on commit 7c559ab

Please sign in to comment.