Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 8a4855b

Browse files
committed
Made switching language more stable
Made switching language more stable with ValidationSummary
1 parent 7bf35f9 commit 8a4855b

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

app.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ myApp.config(['$compileProvider', '$locationProvider', '$routeProvider', functio
2929

3030
// -- Main Controller for Angular-Validation Directive
3131
// ---------------------------------------------------
32-
myApp.controller('Ctrl', ['$location', '$route', '$scope', '$timeout', '$translate', function ($location, $route, $scope, $timeout, $translate) {
33-
// change the translation language & reload the page for a better handling of the validation translation
34-
// the timeout+reload ensures validation translations had time to re-render
32+
myApp.controller('Ctrl', ['$location', '$route', '$scope', '$translate', function ($location, $route, $scope, $timeout, $translate) {
33+
// change the translation language & reload the page to make sure all errors were rendered properly
3534
$scope.switchLanguage = function (key) {
36-
$translate.use(key);
37-
$timeout(function() {
35+
$translate.use(key).then(function() {
3836
$route.reload();
39-
}, 50);
40-
37+
});
4138
};
4239
$scope.goto = function ( path ) {
4340
$location.path( path );

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ NOTE: To be fully localized, I should add the country code at the end of my JSON
240240
// define a key, could be on the fly with a button or a menu link
241241
var key = 'fr';
242242

243-
// change the translation language & reload the page for a better handling of the validation translation
244-
// the timeout+reload ensures validation translations had time to re-render
245-
$translate.use(key);
246-
$timeout(function() {
247-
$route.reload();
248-
}, 50);
243+
// change the translation language & reload the page to make sure all errors were rendered properly
244+
$scope.switchLanguage = function (key) {
245+
$translate.use(key).then(function() {
246+
$route.reload();
247+
});
248+
};
249249
```
250250

251251
*P.S. If you define a new Language set, please make a pull request and I would be happy to add them in current project... It would be nice to have Spanish, German or even Chinese :) Thank you.*

0 commit comments

Comments
 (0)