Show Vue meta i18n variable names instead of values
P粉510127741
2023-08-26 18:52:56
<p>I have a vue2 project and use vue-meta and vue-i18n to localize the project.
In my browser bookmarks, the title of the web page is not shown, instead the variable is shown. The same issue occurs in Google Analytics, it seems to show the variable instead of the value in the variable. </p>
<p>This is the code snippet of my Home component: </p>
<pre class="brush:php;toolbar:false;">name: 'Home',
metaInfo () {
return {
title: this.$t("home.meta.title"),
meta: [{
name: "description",
content: this.$t("home.meta.descriptioncontent")
}, {
name: "keywords",
content: this.$t("home.meta.keywordscontent")
},
{ property: 'og:title', content: this.$t("home.meta.title")},
{ property: 'og:site_name', content: 'www.examplesite.se'},
{ property: 'og:description', content: this.$t("home.meta.descriptioncontent")},
{ property: 'og:type', content: 'Home'},
{ property: 'og:url', content: 'https://examplesite.se/'},
{ property: 'og:image', content: 'https://www.examplesite.se' '/img/' 'example_logo_social.png'}
]
}
},
data() {
return {
fimagefolder: '../../Images/',
bimagefolder: '../../fImages/',
};
},</pre>
<p>So this.$t("home.meta.title") variable stores the Swedish and English translations. Inside the site, it shows the correct title in both languages, but Google Analytics only shows "home.meta.title". </p>
<p>From what I understand, the crawler can't see my variable values because it doesn't have any scripts loaded. Any ideas? </p>
It would be nice to see some of your code so we can understand how you set it up, otherwise we're a bit in the dark and have a hard time helping you. So, this is more of a comment than an answer, but I'll share some code that might help that can't be put in a comment.
I assume you are using vue-i18n, and I guess you are defining vueMeta as an object. However, if you define it as a function, you can access other component data, including
this.$t
. They should work together like this: