Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

How do I change the language of the component? #38

Open
ThCC opened this issue Sep 10, 2013 · 3 comments
Open

How do I change the language of the component? #38

ThCC opened this issue Sep 10, 2013 · 3 comments

Comments

@ThCC
Copy link

ThCC commented Sep 10, 2013

In my application language change is dynamic, but very frequent. From what I saw in documentation jQueryUI, there are files for each language, but you need to make a javascript command that specifies the language component. The AngularUI did a treatment for this / one specific API?

JQuery Doc: http://api.jqueryui.com/datepicker/ look for Localization

@ThCC
Copy link
Author

ThCC commented Sep 17, 2013

Good morning, not wanting to be annoying, and forgive me if I'm being, but I really need to know how to modify the language of the ui-date. Can you help me?

@ghost
Copy link

ghost commented Apr 30, 2014

Not trivial. I'm assuming you use this angular translate to handle your translations. The way I did it:
In index.html, include the languages you want to be able to display:

<script src="js/vendor/i18n/jquery.ui.datepicker-en.js"></script>
<script src="js/vendor/i18n/jquery.ui.datepicker-lb.js"></script>
<script src="js/vendor/i18n/jquery.ui.datepicker-pt-BR.js"></script>
<script src="js/vendor/i18n/jquery.ui.datepicker-tr.js"></script>
<script src="js/vendor/i18n/jquery.ui.datepicker-fr.js"></script>

Then in your controller, extend $scope.dateOptions with the language you're using:

// JQuery UI date options
$scope.dateOptions = {
    minDate: 0,
    dateFormat: ninja_config.l10n.ui_date
};
angular.extend($scope.dateOptions, jQuery.datepicker.regional[$translate.uses()]);

Also add a listener to be able to change the language dynamically:

// Translates the datepicker whenever the language changes.
$scope.$on('$translateChangeSuccess', function () {
    var language = $translate.uses();
    $log.debug('Changing datepicker language to ' + language);
    angular.extend($scope.dateOptions, jQuery.datepicker.regional[language]);
});

@zengchuan
Copy link

How to inject jQuery in jQuery.datepicker.regional ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants