Skip to content
Advertisement

Why the vue-lang do not work with filter?

I using vue-lang. It works, but not completely

ISSUE

in the JSON file there is an example of:

"messages": "You have {0} {1} messages"

and then this code as a filter

<p>{{$lang.messages | replace countmsg 'new'}}</p>

But when I do it by example so there is an error here

[Vue warn]: Failed to resolve filter: replace countmsg 'new'

MY FILES

main.js

import Vue from 'vue'
import Lang from 'vue-lang'

const locales = {
  'cs': require('./lang/cs.json')
}

Vue.use(Lang, {lang: 'cs', locales: locales})

lang/cs.json

{
  "messages": "You have {0} {1} messages"
}

views/login.vue

<template>
  <p>{{$lang.messages | replace countmsg 'new'}}</p>
</template>

<script>
  export default {
  name: 'Login',
  data: function() {
    return {
      countmsg: 5
    }
 }
</script>

Still does not work. What am I doing wrong?

Advertisement

Answer

I’m not familiar with this particular library but the usual way to use a filter like this would be:

{{ $lang.messages | replace(countmsg, 'new') }}

The documentation for that filter appears to be 3 years old so it may be out of date. The syntax for calling filters was changed some time ago: https://v2.vuejs.org/v2/guide/migration.html#Filter-Argument-Syntax-changed

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement