Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Fallback logic related suggestions/request #480

Closed
lkho opened this issue Dec 13, 2018 · 3 comments
Closed

[feature request] Fallback logic related suggestions/request #480

lkho opened this issue Dec 13, 2018 · 3 comments

Comments

@lkho
Copy link

lkho commented Dec 13, 2018

Hi folks!
First of all, thanks for all the hard work.

As I scan through the issues, I found that there are lots of suggestions regarding the fallback logic, and I would like to add one more.

There are existing ones:

And I have a new one:

  • fallback key

I think that if the key can accept array/fallback then maybe some issues mentioned above can also be solved, such that:

export default {
  methods: {
    t (keys, ...params) {
      // use `$te` and `$t
      let lastKey = '';
      for (let key of [].concat(keys)) {
        lastKey = key;
        if (this.$te(key)) {
          return this.$t(key, ...params);
        }
      }
      return lastKey;
    }
  }
}

then I can use it like this:

this.t([
  'status.' + data.statusKey, // original value
  'status.unknown', // if the key is not found, output the default translation
  '< Unknown Status >', // if the default key is still not found, output hard coded value
]);

of course, the priority of whether the language or key should be searched first is arguable, and is left for discussion. Moreover, the ...params passed in is also arguable, but I think most of the time all the fallback keys would have the same format/semantics which can use the same params.

@IssueHuntBot
Copy link

@rororofff has funded $5.00 to this issue.


@kazupon kazupon added Status: Proposal Request for comments and removed feature request labels Feb 25, 2020
@kazupon kazupon added Status: Ready and removed Status: Proposal Request for comments labels Mar 24, 2020
@kazupon
Copy link
Owner

kazupon commented Mar 5, 2021

we supported in Vue I18n v9.
please try it!

@Lemmings19
Copy link

@kazupon I am new to Vue and am learning it.

Could you please link to or provide a basic explanation for how to do use a fallback/default message?

I found this, but don't really understand how/if I can use this.

I would love to be able to use t('hello', 'Hello world!') in my project, or something equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants