I using vue-lang. It works, but not completely
ISSUE
in the JSON file there is an example of:
JavaScript
x
2
1
"messages": "You have {0} {1} messages"
2
and then this code as a filter
JavaScript
1
2
1
<p>{{$lang.messages | replace countmsg 'new'}}</p>
2
But when I do it by example so there is an error here
JavaScript
1
2
1
[Vue warn]: Failed to resolve filter: replace countmsg 'new'
2
MY FILES
main.js
JavaScript
1
9
1
import Vue from 'vue'
2
import Lang from 'vue-lang'
3
4
const locales = {
5
'cs': require('./lang/cs.json')
6
}
7
8
Vue.use(Lang, {lang: 'cs', locales: locales})
9
lang/cs.json
JavaScript
1
4
1
{
2
"messages": "You have {0} {1} messages"
3
}
4
views/login.vue
JavaScript
1
14
14
1
<template>
2
<p>{{$lang.messages | replace countmsg 'new'}}</p>
3
</template>
4
5
<script>
6
export default {
7
name: 'Login',
8
data: function() {
9
return {
10
countmsg: 5
11
}
12
}
13
</script>
14
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:
JavaScript
1
2
1
{{ $lang.messages | replace(countmsg, 'new') }}
2
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