Skip to content
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

Hook custom logic for non existent keys in lang #109

Closed
Erwin32 opened this issue May 29, 2019 · 2 comments
Closed

Hook custom logic for non existent keys in lang #109

Erwin32 opened this issue May 29, 2019 · 2 comments

Comments

@Erwin32
Copy link

Erwin32 commented May 29, 2019

I was looking for some way to register some callback/interceptor on failed key lookup so that I could send a request to server API we have that would notify the server of the missing translation.

I didn't find any way to do this using the library functions. I could introduce custom vue filter and some wrapper method around $t method as last resort tho I wouldn't prefer that.

@tikiatua
Copy link
Member

Hi @Erwin32

This functionality is actually available. You need to pass a respective handler function as onTranslationNotFound property when initializing the store. You can find an example in the readme.

// with promise as return value. this will write the new value into the store,
// after the promise is resolved
Vue.use(vuexI18n.plugin, store, {
	moduleName: 'i18n',
	onTranslationNotFound (locale, key) {

		return new Promise((resolve, reject) => {
			axios.get('/api/translations/async', {locale: locale, key:key})
			.then((result) => {
				resolve(result.data);

			}).catch() {
				reject();
			}

		})

	}}
);

@Erwin32
Copy link
Author

Erwin32 commented May 30, 2019

oh great must have missed that, thx

@Erwin32 Erwin32 closed this as completed May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants