-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
[Question] Translate from javascript context #475
Comments
Hi!
Sorry, I could not understand about
Could you give us some specific information about stacktrace or capture, please? |
My apologies. I am attempting to use it like this: file: axios.js import _axios from 'axios'
import _each from 'lodash/each'
import { i18n } from './i18n'
_each(data.errors[x], y => {
const text = y.replace('#attribute', i18n.t(x))
}) In case the attribute that is returned from the API has a localised name, I'd like to translate that before displaying the error to the user. Chrome stacktrace
|
Thank you for your feedback! You can use i18n resources: {
"errors": [
"first error: {number}",
"second error: {number}"
]
} import { createI18n } from 'vue-i18n'
import enUS from './locales/en-US.json'
const { global } = createI18n({
legacy: false, // Composition API
locale: 'en-US',
messages: {
'en-US': enUS
}
})
global.tm('errors').forEach((err, index) => {
console.log(global.rt(err, { number: index }))
})
// outputs
// first error: 1
// second error: 2 see the about details:
Thanks! |
Hi,
I've tried to search around the documentation and the issues here, but to no avail.
Is it still possible to access the translation methods in plain js files?
Beforehand I'd import the i18n instance into my axios setup file and translate any error-messages that came back.
However
i18n.t('cars')
now seem to throw an error.I can see that
i18n.global.t
is a function, but attempting to use that, throws anSyntaxError: Invalid value
exceptionThe text was updated successfully, but these errors were encountered: