47

I use the datePicker documented here.

However, no direct option allows to change the language, English by default.

I find a the documentation of the widget provided without angular directive, and it provides a nice way to achieve it:

http://bootstrap-datepicker.readthedocs.org/en/latest/i18n.html

Is there an easy way, avoiding to tweak the original directive's source code, to change it?

Mik378
  • 21,881
  • 15
  • 82
  • 180

3 Answers3

90

If you are using the DatePicker form angular-ui simply add the localized js file in the header of your page. An example would be :

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
<script src="http://code.angularjs.org/1.0.8/i18n/angular-locale_fr-fr.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>

You can see a working plunker here

Nicolas ABRIC
  • 4,925
  • 28
  • 18
  • 16
    This doesn't translate the action buttons text when using the popup. To translate it, you must also configure the datepickerPopupConfig global objetct : http://plnkr.co/edit/g5uxqcJkhqbQRKmLI2Zj?p=preview – Mat May 11 '14 at 13:05
  • 5
    When using bower, [bower install angular-i18n](https://github.com/angular/bower-angular-i18n) – fracz Oct 04 '14 at 18:33
  • remember to change the localization cdn url to match your angular version – Sérgio S. Filho Sep 21 '16 at 20:12
18

First, you have to load your locales (get them here) script after angular in index.html:

 <script src="angular.js"></script>
 <script src="angular-locale_de-de.js"></script>

After that, the days and months are localised but you need to translate the buttons by yourself adding parameters inside the datepicker input tag:

<input type="text" class="form-control" datepicker-popup="dd.MM.yyyy"
ng-model="dt" is-open="opened" min-date="minDate" max-date="'2042-04-02'"
datepicker-options="dateOptions" date-disabled="disabled(date, mode)" 
ng-required="true" 
current-text="Tonight" clear-text="Reset" close-text="Exit" />
Pekka
  • 959
  • 2
  • 12
  • 22
4

You can find locale js files latest version with this link.

https://cdnjs.com/libraries/angular-i18n

Also, if you want to translate datepicker action buttons(like 'Close') globaly, you can add this code for global config.

//DatePicker -> uibDatepickerConfig
//DatePickerPopup -> uibDatepickerPopupConfig
app.config(['uibDatepickerPopupConfig', function(uibDatepickerPopupConfig) {
uibDatepickerPopupConfig.closeText = 'Close';
uibDatepickerPopupConfig.currentText = 'Today';
uibDatepickerPopupConfig.clearText = 'Clear';
}]);
Edward D. Wilson
  • 351
  • 1
  • 4
  • 11
  • With globaly the problem is, that you cannot display the buttons in different languages during runtime. – Sebastian Sep 04 '18 at 13:11
  • This worked perfectly for my project as we reload the page on language change and this saved me from having to wrap the date-picker in my own directive – Simon K Feb 09 '20 at 21:22