ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

It's dosen't work to set local language #185

Closed fishen closed 7 years ago

fishen commented 7 years ago

I have already added script moment-with-locales to my app(ng4) , and set language to 'zh-cn' in the AppComponent, but it still dosen't work. package.json: "@ngui/datetime-picker": "^0.16.1" .angular-cli.json:

"scripts": [
        "../node_modules/moment/min/moment-with-locales.min.js",
        "../node_modules/jquery/dist/jquery.min.js",
]

app.component.ts:

constructor(
    private translate: TranslateService,
    private dispatcher: EventDispatcher,
  ) {
    moment.locale('zh-cn');
    console.log(moment().format('L'));
    translate.setDefaultLang(window.navigator.language);
  }

template : <input [(ngModel)]="model" ngui-datetime-picker date-only="true" /> navigator's console output :

2017年4月17日 //moment-with-locales works!!
Angular is running in the development mode. Call enableProdMode() to enable the production mode.

page result(still English...): default

The example in the https://plnkr.co/edit/J6hXyB?p=preview works properly.

fishen commented 7 years ago

add local setting above AppComponent can fix this issue.

declare var moment: any;
moment.locale('zh-cn');

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.None
})
export class AppComponent implements OnInit {