I want to build a web-application with angular2 and bundle this with webpack. What is the best way for providing multiple languages:
i18n-plugin: https://github.com/
A slightly modified version of @M.Nour Berro's answer.
I made this change as synchronous xhr's are deprecated and possibly support might be removed later.
function getTranslations(filePath: string): Promise {
var text = '';
return new Promise ((resolve, reject) => {
const fileRequest = new XMLHttpRequest();
fileRequest.open('GET', filePath, true);
fileRequest.onerror = function (err) {
console.log(err);
reject(err);
};
fileRequest.onreadystatechange = function () {
if (fileRequest.readyState === 4) {
if (fileRequest.status === 200 || fileRequest.status === 0) {
text = fileRequest.responseText;
resolve(text);
}
}
};
fileRequest.send();
});
}