2017-05-16 2 views
2

Ich habe versucht, Lokalisierung mit i18n durch Webpack und Angular.ngtools/webpack ExtractI18nPlugin Verwendung

Ich kam über das Plugin in den cli Tool von Angular https://github.com/angular/angular-cli/blob/master/packages/%40ngtools/webpack/src/extract_i18n_plugin.ts

aber ich habe es nicht zur Arbeit gekommen, jemand weiß, wie es einzurichten?

Ich bekomme nur die üblichen "Fehler: Kann '../aot/src/app/app.module.ngfactory' nicht auflösen", aber rein aot läuft, funktioniert gut.

var helpers = require('./helpers'); 
var ngtools = require('@ngtools/webpack'); 
var AotPlugin = ngtools.AotPlugin; 
var ExtractI18nPlugin = ngtools.ExtractI18nPlugin 

module.exports = { 
    entry: { 
     'polyfills': './src/polyfills.ts', 
     'vendor': './src/vendor-aot.ts', 
     'app': './src/main-aot.ts' 
    }, 
    module: { 
     rules: [ 
      { 
       test: /\.ts$/, 
       use: ['@ngtools/webpack'] 
      } 
     ] 
    }, 

    plugins: [ 
     new ExtractI18nPlugin({ 
      outFile: "src/i18n", 
      tsConfigPath: helpers.root('tsconfig-aot.json') 
     }), 
     new AotPlugin({ 
      tsConfigPath: helpers.root('tsconfig-aot.json'), 
      entryModule: helpers.root('src/app/app.module#AppModule') 
     }) 

    ] 
}; 
+0

Werfen Sie einen Blick auf dieses Thema Thema: https://github.com/ angular/angular.io/issues/3163 Dies ist etwas, das noch nicht wirklich unterstützt wird, wenn es sich um ein ** ausgeworfenes ** Angular-Projekt handelt, OOTB. Ich bin dabei, das selbst zu implementieren, aber vielleicht hilft dir der Thread auf deinem Weg! –

Antwort

0

ich sehe hat eine Notiz an anderer Stelle, dass Sie die ExtractI18nPlugin nach dem AotPlugin setzen müssen, etwa so:

"plugins": [ 
// ... 
new AotPlugin({ 
    "mainPath": "main.ts", 
    "i18nFile": "src/i18n/messages.fr.xlf", 
    "i18nFormat": "xlf", 
    "locale": "fr", 
    "replaceExport": false, 
    "missingTranslation": "error", 
    "hostReplacementPaths": { 
    "environments\\environment.ts": "environments\\environment.ts" 
}, 
"exclude": [], 
"tsConfigPath": "src\\tsconfig.app.json" 
}), 
new ExtractI18nPlugin({ 
    "tsConfigPath": "src\\tsconfig.app.json", 
    "exclude": [], 
    "i18nFormat": "xlf", 
    "locale": "fr", 
    "outFile": "i18n/test.xlf", 
}) 
// ... 
] 
+0

Der wichtige Teil besteht darin, das ExtractI18nPlugin am Ende Ihrer Plugins-Liste hinzuzufügen –