Angular2 and webpack - i18n plugin vs ng2-translate

后端 未结 5 1799
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 04:01

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/

5条回答
  •  死守一世寂寞
    2020-12-24 04:26

    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();
      });
    }
    

提交回复
热议问题