angular-meteor icon indicating copy to clipboard operation
angular-meteor copied to clipboard

Angular5: Can't import i18n locale files with A5 new methodology

Open Kwizach opened this issue 8 years ago • 5 comments

With Angular 5 there is a new methodology to import locale files to use with pipe (date, number...). Doc: https://angular.io/guide/i18n#i18n-pipes So now you need to import the locale you want to use and add it to your app.module.ts:

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';

registerLocaleData(localeFr);

When I do that I get a Uncaught SyntaxError: Unexpected token export in my browser console Following the link (module.js?hash=blabla...) from the console I can see the export has been added to the module:

"locales":{"fr.js":function(){

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                     //
// node_modules/@angular/common/locales/fr.js                                                                          //
//                                                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                                       //
/**                                                                                                                    // 1
 * @license                                                                                                            // 2
 * Copyright Google Inc. All Rights Reserved.                                                                          // 3
 *                                                                                                                     // 4
 * Use of this source code is governed by an MIT-style license that can be                                             // 5
 * found in the LICENSE file at https://angular.io/license                                                             // 6
 */                                                                                                                    // 7
// THIS CODE IS GENERATED - DO NOT MODIFY                                                                              // 8
// See angular/tools/gulp-tasks/cldr/extract.js                                                                        // 9
export default [                                                                                                       // 10
    'fr',                                                                                                              // 11
    [                                                                                                                  // 12
        ['AM', 'PM'],      

I believe this is due to the way angular2-compilers converts files contents into a string.

PS1: I hope this is just me and not a real issue ;) PS2: Sorry for my english

Kwizach avatar Dec 05 '17 18:12 Kwizach

can you try the new angular-compilers package instead of angular2-compilers?

Urigo avatar Dec 09 '17 13:12 Urigo

Thank you for your reply (and all your work)

I didn't knew about angular-compilers and was still using angular2-compilers from the old days. So I have migrate my code to use angular-compilers instead of angular2-compilers... everything works great until I try to import that file

image

It is working with my own import (a copy of the angular file) but not when I do it as mentioned in the angular documentation:

//import localeFr from '@angular/common/locales/fr';    ---> KO
import { localeFr } from './locale.fr';                 ---> OK

Kwizach avatar Dec 12 '17 13:12 Kwizach

Your solution seems to be a work around :) I have the same issue (for another locale though).

So here is my logging:

    System.err: 
    System.err: Error calling module function 
    System.err: 
    System.err: Error calling module function 
    System.err: 
    System.err: Cannot compile 
    /data/data/XXXX/files/app/tns_modules/@angular/common/locales/nl.js
    System.err: 
    System.err: SyntaxError: Unexpected token export
    System.err: File: 
    "file:///data/data/XXXX/files/app/tns_modules/@angular/common/locales/nl.js, line: 10, column: 0

Does anyone have another suggestion or solution?

WouterVanVegchel avatar Jan 03 '18 10:01 WouterVanVegchel

I ran into the same problem, I think it is not related with Meteor, it is an Angular 5 issue as explained here:
https://github.com/angular/angular/issues/20605

pbureau avatar Mar 04 '18 09:03 pbureau

Thank you for your collaboration. I think it will be fixed in Angular’s v6 release.

ardatan avatar Mar 19 '18 19:03 ardatan