ng2-ui / datetime-picker

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

Would be possible to change the name of months by changing the locale of MomentJS? #29

Closed celsoagra closed 8 years ago

celsoagra commented 8 years ago

Hi,

I have a question about i18n. I saw that you're using momentJS with locale, so I'd like to know if it is possible to change language to use 'PT-BR'?

Is it possible?

allenhwkim commented 8 years ago

Let me see,

Based on the existing code, https://github.com/ng2-ui/ng2-datetime-picker/blob/master/src/datetime.ts#L54

Yes, it's possible. If not, let me know. I will treat it as a bug.

allenhwkim commented 8 years ago

@celsoagra if you made it successful, please attach your screenshot here, so that other people can see it. A picture is better than thousand words.

celsoagra commented 8 years ago

@allenhwkim Thanks for you answer! Sorry to not give you a feedback. I was quite on a rush here.

I tried to change the datetime.ts file, but now I get a new error. I think I did something wrong here.

I create a new folder with same content that ng2-datetime-picker/src files:

+-- ng2-datetime-picker
|     +-- datetime.ts
|     +-- datetime-picker.component.ts
|     +-- datetime-picker.directive.ts
|     +-- index.ts

Then I changed the "datetime.ts", as you suggested above (initialize method #17).

Then I set this in my app,module.ts:

import { NgModule } from '@angular/core';
import { Ng2DatetimePickerModule } from './shared/ng2-datetime-picker';
// ....
@NgModule({
  imports: [
    // ....
    Ng2DatetimePickerModule
  ],
 // ....
})

export class AppModule {
}

But now I get a new error:

Error: Error: XHR error (404 Not Found) loading http://XXXX/build/shared/ng2-datetime-picker.js(…)

I have a "build" folder to store only the "compiled" files.

Could you help me please?

celsoagra commented 8 years ago

@allenhwkim is there a way to change datetime.ts and use this in node-modules?

allenhwkim commented 8 years ago

import { Ng2DatetimePickerModule } from 'ng2-datetime-picker'; will work to use node_modules. Please take a look at the plunker example which uses node_modules.

allenhwkim commented 8 years ago

About the name of months, you simply set Moment js setting. You don't need any change on datetime-picker. Please take a look at the following example. By simply adding these lines, you can change 'months' and 'days' to your locale.

  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment-with-locales.min.js"></script>
  <script> moment.locale('fr'); </script>
celsoagra commented 8 years ago

Solved!!

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment-with-locales.min.js"></script>
<script> moment.locale('pt-br'); </script>

I just add this to my index.html and the moment works fine

Thanks again for your help!

allenhwkim commented 8 years ago

My pleasure to help. Glad to hear it worked