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

External file with translations #10

Closed
jdriesen opened this issue Mar 1, 2017 · 2 comments
Closed

External file with translations #10

jdriesen opened this issue Mar 1, 2017 · 2 comments

Comments

@jdriesen
Copy link

jdriesen commented Mar 1, 2017

Hello,

I have a small question.
You're writing

// translations can be kept in separate files for each language
// i.e. resources/i18n/de.json.

Can you please tell me how to 'load' such an external file ?

Thanks in advance for your reply & help,
Johnny

@tikiatua
Copy link
Member

tikiatua commented Mar 2, 2017

Hi @jdriesen ,

You can find an example in the test directory. Basically you just need to load the file via ajax and pass the translations to the plugin.

Please note, that the example is still using vue-resource. This library has been recently depreciated and it is recommended to switch to another ajax library. The authors recommend axios (which we are using now for all new projects).

// code using vue-router
this.$http.get(url).then((response) => {
	return response.json();
}).then((data) => {
	this.$i18n.add(locale, data);
	this.$i18n.set(locale);
}).catch((error) => {
	alert('could not fetch locale translations');
});


// code using axios (do not forget to import axios)
// import axios from 'axios';
axios.get(url).then((response) => {
	this.$i18n.add(locale, response.data);
	this.$i18n.set(locale);
}).catch((error) => {
	alert('could not fetch locale translations');
});

Let me know if you need some further assistance.

@jdriesen
Copy link
Author

jdriesen commented Mar 2, 2017

Super.
Thanks a lot.
Gonna give it a try asap.
Thanks for your time to give me a reply. Appreciated !

Kind regards,
Johnny

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