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

Provide an example usage of registerLocaleData()

Open salemdar opened this issue 8 years ago • 7 comments

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see use [gitter](https://gitter.im/mgechev/angular2-seed) or [stackoverflow](https://stackoverflow.com/questions/tagged/angular2)

According to the documentation, registerLocaleData() method is needed to change the pipe formats.

Current i18n mechanism of angular-seed doesn't use registerLocaleData() method at all.

salemdar avatar Jan 04 '18 16:01 salemdar

I tried to add locales similar to the other packages, but didn't succeeded.

let additionalPackages: ExtendPackages[] = [
  {
    name: '@angular/common/locales/de',
    path: 'node_modules/@angular/common/locales/de.js'
  }

Which results in an error

TypeError: Unable to dynamically transpile ES module
A loader plugin needs to be configured via SystemJS.config({ transpiler: 'transpiler-module' }).

As it they are not recognized it seems.

maxmarkus avatar Jan 23 '18 12:01 maxmarkus

In the AppModule import { registerLocaleData } from '@angular/common'; import localeDe from '@angular/common/locales/de';

registerLocaleData(localeDe, 'de');

for JIT i also added @NgModule({ { provide: LOCALE_ID, useValue: 'de' } })

And then you also need to add the npm dependency to your project.config { name: '@angular/common/locales/de', path: '${this.NPM_BASE}@angular/common/locales/de.js' }

With this configuration the aot build works for me, im happy to provide further details if needed.

tobiaseisenschenk avatar Feb 16 '18 09:02 tobiaseisenschenk

Hey @tobiaseisenschenk, thanks for your input. But when I do that and run yarn start I receive the following error:

(index):65 TypeError: Unable to dynamically transpile ES module
   A loader plugin needs to be configured via `SystemJS.config({ transpiler: 'transpiler-module' })`.
    at transpile (http://localhost:5555/node_modules/systemjs/dist/system.src.js?1518778235730:3680:11)
    at http://localhost:5555/node_modules/systemjs/dist/system.src.js?1518778235730:3462:12
    at ZoneDelegate.invoke (http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:388:26)
    at Zone.run (http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:138:43)
    at http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:858:57
    at ZoneDelegate.invokeTask (http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:421:31)
    at Zone.runTask (http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:188:47)
    at drainMicroTaskQueue (http://localhost:5555/node_modules/zone.js/dist/zone.js?1518778235733:595:35)
    at <anonymous> Not expecting this error? Report it at https://github.com/mgechev/angular-seed/issues

salemdar avatar Feb 16 '18 11:02 salemdar

i can't figure it out either, only solution that works for me is to copy locale.js to base app folder, change it to .ts and then import - but it's far from optimal :)

unnamed666 avatar Feb 22 '18 12:02 unnamed666

@mgechev Do you have any idea about this one?

salemdar avatar Mar 23 '18 09:03 salemdar

Solution by @tobiaseisenschenk worked for me for AOT.

For CLI this is the behavior:

The CLI imports the locale data for you when you use the parameter --locale with ng serve and ng build.

Can we add --locale parameter and mimic this behavor?

zkirill avatar May 03 '18 19:05 zkirill

install dependencies npm i systemjs-plugin-babel

add following line in SYSTEM_CONFIG_DEV @ /tools/config/seed.config.js map: { 'plugin-babel': 'path/to/systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build': 'path/to/systemjs-plugin-babel/systemjs-babel-browser.js' }, transpiler: 'plugin-babel'

govindmahecha avatar May 28 '18 12:05 govindmahecha