I am trying to translate formlyjs
required validation message in angularjs
that's the code what I have tried but it doesn't translate or bring the translated string in "REQUIRED" I am using angular-translate.
Output i am getting UsernameREQUIRED
instead of Username is required
I have looked at this question and answer over stackoverflow. it works with out to.label
but i need to have this to.label
concatenation.
Any help or suggestion please.
$translateProvider.translations("en", {
REQUIRED: "is required",
})
formlyValidationMessages.messages.required = 'to.label + "REQUIRED" | translate';
angular.module('templates/formly/validation-messages.html', []).run([
'$templateCache',
function ($templateCache) {
$templateCache.put('templates/formly/validation-messages.html',
'<formly-transclude></formly-transclude>' +
'<div class="validation-messages" ng-messages="(fc[0] || fc).$error" ng-if="(options.formControl[0] || options.formControl).$touched || (options.formControl[0] || options.formControl).$error.required || form.$submitted" ng-messages-multiple>' +
' <div class="label label-danger animate vanishIn enter-vanishIn exit-vanishOut" ng-message="{{::name}}" ng-repeat="(name, message) in ::options.validation.messages">' +
' {{message((fc[0] || fc).$viewValue, (fc[0] || fc).$modelValue, this)}}' +
' </div>' +
'</div>' +
'');
}
]);
REQUIRED
eg:'to.label + " REQUIRED" | translate'
{{to.Label "REQUIRED" | translate }}
result:{{to.Label "REQUIRED" | translate }}
, While this will work :to.Label {{ "REQUIRED" | translate }}
, result:to.Label is required
. You may test it here : angular-translate.github.io/docs/#/api/…