Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

Regarding translation of labels, it'd be nice to input HTML in the label #1534

Closed alber70g closed 3 years ago

alber70g commented 7 years ago

If it would be possible to render labels as html, we could just use any library to provide translations using interpolation. That way we could just do {{_ "TheLabel" }} and it'd be translated by the module responsible for it.

new SimpleSchema({
    length: {
      htmlLabel: '{{_"Length (months)' }}''
      type: Number,
      allowedValues: [3, 6, 12],
      autoform: {
        type: 'select-radio'
      }
    },
});
abate commented 7 years ago

you can easly do this as :

label: () -> TAPi18n.__("Length (months)")
autoform:
  options: () ->
     l = ["a","b","c"]
     _.map(l, (e) -> {value: e, label: TAPi18n.__ e})

or something along these lines ...

mozfet commented 6 years ago

I can confirm that the solution provided by @abate works, with a small change: -> should be =>

I use my own internal Locale component (powered by i18next under the hood) with reactive database translations, if I change the language, the whole UI, including forms, reactively change translations instantly.

name: {
  type: String,
  label: () => Locale.translate('group-form-name-label'),
  autoform: {
    placeholder: () => Locale.translate('group-form-name-placeholder')
  }
}