angular-autoFields-bootstrap icon indicating copy to clipboard operation
angular-autoFields-bootstrap copied to clipboard

autoFields and i18n

Open voznik opened this issue 10 years ago • 8 comments

how can i use autoFields with translations? i'm using now pascalprecht.translate. for now i solve it in json:

property: 'password',        
    placeholder : $translate.instant('PASS'),
    label : '',
    type : 'password',
    addons : [{icon : 'fa fa-lock'}],
    attr: { 
      required: true, 
      ngMinlength:5 },
    msgs: {
      match: $translate.instant('PASSWORDSNOTMATCH')
      },

and translation does not change on language change. but my goal is to override defaultMsgs with $autofieldsProvider.settings.validation

voznik avatar Mar 27 '15 16:03 voznik

Hey @voznik, this is something I'm going to need to look into. I haven't used autofields with i18n, so I'm not sure right now. Anyone else have any experience with this?

JustMaier avatar Mar 27 '15 16:03 JustMaier

one more from me:

$scope.schema = [ {
    property : 'org',
    placeholder : '\{\{\'NAME\' | translate\}\}',
    label : '',
    type : 'text',
    addons : [ {
      icon : 'fa fa-suitcase'
    } ],
    attr : {
      required : true,
      ngMinlength : 2,
      ngMaxlength : 100,
      autofocus : 'autofocus',
      capitalize : 'capitalize'
    },
//    msgs : {
//      required : '\{\{\'ADDRESS\' | translate\}\}',
//      minlength: '\{\{\'VALUESHORT\' | translate\}\}',
//      maxlength: '\{\{\'VALUELONG\' | translate\}\}',
//      pattern : '\{\{\'BADSIMBOLS\' | translate\}\}',
//    }
  }, 

so, when i mask braces - placeholder translation works. but for validation messages it crashes in console. and i have errors when i was trying to add $translate.instant into $autofieldsProvider.settings.validation section p.s.: your component is really, really good. such clean and powerfull.

voznik avatar Mar 28 '15 11:03 voznik

for now i unerstand that i can not use $translate service in autofields.validation .config block because of this is not allowed in angular, must use services in .run block how can i intercept fieldElements.msgs in .run block

voznik avatar Mar 28 '15 19:03 voznik

please, point me to the right direction with config defaultMsgs

voznik avatar Apr 16 '15 13:04 voznik

The defaultMsgs can be set in a config block:

angular.module('app')
.config(function($autofieldsProvider){
    $autofieldsProvider.settings.validation.defaultMsgs = {
       //Replacements...
    };
}

See all default messages here

JustMaier avatar Apr 16 '15 18:04 JustMaier

yes, but i can not use translate provider (and other providers) in .config block. in which block can i translate defaultMsgs?

voznik avatar Apr 20 '15 05:04 voznik

Currently you can do it at the controller level via options passed to autofields.

###Javascript

scope.options = {
    validation: {
        defaultMsgs: {
            //Replaced messages here
        }
    }
}

###HTML

<auto-fields fields="fields" data="data" options="options"></auto-fields>

I understand that this isn't ideal and I'll look into a way to expose the global settings at the run block level.

JustMaier avatar Apr 29 '15 18:04 JustMaier

Maybe, angular-translate could be included by default. One approach is how its done in JanStevens/angular-growl-2

sclausen avatar Mar 07 '16 17:03 sclausen