I want to implement the following logic of translating Action message:
If source (second parameter passed to $t — mainPage
in the example bellow) is specified it then should try to get a translation from currentLocale.key.source
path. If source key (mainPage
) was not found or it is null I want to show the key itself ('Action'
) to a user.
Messages structure:
{
'by': {
'Action': {
'menu': 'Дзеянне',
'mainPage': 'Аперацыя'
}
}
}
mainPage.vue
{{ $t('Action', 'mainPage') }}
One could say that this is the same to $t('Action.mainPage')
but in case of undefined translation it will show 'Action.mainPage'
which is a no go for me.
I was trying to achieve the same with named-formatting. There is a potential but doesn’t seem like a good option as it looks more as hack rather than a solution.
My guess is that $t should be overridden to implement this, but I couldn’t figure out how.