-
Notifications
You must be signed in to change notification settings - Fork 58
Locales (languages)
Locales are simple sets of language defined in external JSON files, we can easily add any new language as extra files without affecting the behaviour of the angular directive. You could even change displayed language on the fly (note that the error message will be reflected only after field value is re-evaluated). Make sure to include the angular-translate
library and configure it, see section Include it in your Project
NOTE: To be fully localized, I should add the country code at the end of my JSON filename and then change the suffix on the angular-translate
loader
method, but this would add an overhead and I prefer to keep it simple as validation messages often looks the same anyway (for example English from UK or US would most probably give similar error messages). If you really do want to be fully localized, then see the example in Include it in your Project
// define a key, could be on the fly with a button or a menu link
var key = 'fr';
// change the translation language & reload the page to make sure all errors were rendered properly
$scope.switchLanguage = function (key) {
$translate.use(key).then(function() {
$route.reload();
});
};
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.
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc