kazupon/vue-i18n

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

lkho posted onGitHub

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:

  • fallback locale/language (#36, #138, #322)
  • fallback value/default value (#12, #444)

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.


@rororofff has funded $5.00 to this issue.


posted by IssueHuntBot almost 6 years ago

we supported in Vue I18n v9. please try it!

posted by kazupon about 4 years ago

Fund this Issue

$5.00
Funded

Pull requests

Recent activities

rororofff funded 5.00 for kazupon/vue-i18n# 480
almost 6 years ago