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
Register $t globally #69
Comments
Thank you for your feedback! |
Thanks for quick response! Having $t in every module, simply means we can translate every piece of text we handle within javascript:
|
If I'm understanding correctly, you're asking for this: global.$t = Vue.t; No, please don't do this! Global variables are very much an anti-pattern. The function is available in components, and it's available under Also, this entire exercise only saves three characters? |
ok..... I understand.... but is it not the same as you are already doing in each <template>
<div>
<h1>{{ $("title") }}</h1>
<fancy title='$t{"title"}'></fancy>
</div>
</template> <script>
import Vue from 'vue'
const myTitle = Vue.t("title") // here I would suggest myTitle= $t("title")
</script> I mean, if there is any reason for a |
@callumacrae yes... 3 characters..used 1000 times... ;) |
I think so, too The following is a supplement: |
ok, thanks :) |
How is this done in the latest version?
How would I get this value in a child component's script?
I saw something like Any chance to get the value there? EDIT: |
I am running into this issue while trying to set a default string variable.
results in Yet wanting to have a translated default of a string prop seems somewhat normal to me... |
replace:
with:
Or just use |
Hmm. I haven't got any of your suggestions to work. For now I am just setting the default in the template as a fallback I don't see mentioned anywhere in the guide or API docs that I'm trying in general not to import Vue into SFCs, and when I just use |
I am not sure if this is helpful, but I use something like this successfully: export default {
data: function () {
return {
// just some example of an array with translated labels
pricesHeader: this.$i18n.t('prices.header'),
fields: [
{ key: 'label', label: this.$i18n.t('prices.label') },
{ key: 'service', label: this.$i18n.t('prices.info') },
{ key: 'tokens', label: this.$i18n.t('prices.tokens') }
]
}
}
} |
Oh sorry, I was thinking of |
I am unable to use this.$t or Vue.t in a prop default.
is there a way to do this ? |
@gkatsanos |
It seems unrelated, but it's not. it's actually the exact same issue. |
Did you try add return keyword in factory function?
|
Yes, i think the answer may help:
|
This doesn't work in Vue.js 3, as default props factories no longer have an access to
|
Please register $t globally per default. Now we need each time:
The text was updated successfully, but these errors were encountered: