question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Improved i18n support

See original GitHub issue

Problem to solve

When working with vue-i18n there is an issue with dynamic language changes.

For example when using input rules on v-text-field. Within the rule one can call i18n.t('...') to translate error-messages. The problem is, that on language-change the messages don’t get updated to the new locale unless the validation is triggered again.

There is a similar issue on the usage of hints and labels. Avoiding the $t for performance-reasons leads to very bloated code and is not always possible (see example).

<v-text-field
    :rules="[val => !!val || $t('messages.required')]"
    :hint="$t('messages.hint')"
>
    <template #label>
        <span v-t="'messages.label'"></span>
    </template>
</v-text-field>

Just assume the keys messages.required, messages.label and messages.hint exist.

The label can be displayed with the better performing v-t directive and the ‘label’ slot, for the hint $t has to be used even if you try to avoid it.

Proposed solution

It would be nice to have a property like use-i18n or similar. If set to true, the component would take the strings provided for hint, label and as return of the rules and try to use it for the path on i18n translation.

This behavior could also be extended to the item-text values of v-select components.

To have better control about where this behavior is applied or not the property could accept an object like { label: true, hint: false, rules: true}.

This feature is intended to input components but could be used on other components too.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
SteDeshaincommented, Jul 1, 2020

Is there any known good workaround for the issue originally described in the report (changing language doesn’t change language of validation error messages when using i18n.t(‘…’) within the rules)?

v-text-field and other v-input elements all have a scoped slot named message, so you can use the same way mentioned above to solve the problem, but need some tricks.

The tricks are that you should pass a i18n key rather than $t(...) to the rule function, like this :rules="[ v => !!v || 'an-i18n-key' ]". And then you should call $t('an-i18n-key') in the slot template to show the translated messages.

<v-text-field :rules="[ v => !!v || 'an-i18n-key' ]">
    <template #message="{ message }">
        {{ $t(message) }}
    </template>
</v-text-field>

My English is bad, I hope you can get what I mean ;D

9reactions
jacekkarczmarczykcommented, Aug 26, 2019

bit less boilerplate

<template v-for="header in headers" v-slot:[`header.${header.value}`]="{ header }">
{{ $vuetify.lang.t(`$vuetify.${header.text}`) }}
</template>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Internationalization & Localization - ServiceNow Community
I want to translate 'Service Request' topic to other language, Now I used Enable I18N Debugging, It shows like this picture and there...
Read more >
How to improve your localization program's efficiency with ...
Connectivity a vital feature to deploy if you wish to have localization efficiency, but even more vital is identifying the tool to make...
Read more >
feature request #7707: Handle title / titleCache similar to Media in ...
In #7705 the best way to handle i18n-title and titleCache in the UI for classes with "simple titleCache" (titleCache generated only from title...
Read more >
Roadmap - Vue I18n - Intlify
octicon:git-pull-request-24. #631. chore(deps): update dependency esbuild-register to v3. Type: Dependency. octicon:git-pull-request-24.
Read more >
Improve Your I18n Workflow with the Phrase GitHub Sync
It offers great features to support collaboration on software. To integrate one step further, it would be great to combine the localization ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found