-
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 (located here: /locales/validation), we can easily add any new language as extra files without affecting the behaviour of Angular-Validation
. 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
The generic translation JSON files are located in /locales/validation.
// inject the validationService inside your Controller
myApp.controller('Ctrl', function ($scope) {
// 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();
});
};
});
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 again see the configuration of the TranslateProvider in Include it in your Project
If you define a new Language set, please make a pull request and I would be really happy to add them in current project... With support from some community members, the library now support over 12 languages (locale), if your locale is not in the list, then please make a pull request and I would be really happy to merge it... Thank you.
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc