Skip to content

Curious why object/array returns from $t are removed? #75

@thedamon

Description

@thedamon

I use this frequently when defining content that is systematic.

For example when i have components that take objects, for instance, I have a FormControl component that takes an object of validationMessages keyed to validation rules. I can rely on vue-i18n to store this object exactly as I want it with no need for tricky back and forth:

// i18n
form: {
  firstNameInput:{
   label: 'first name',
   validationMessages: {
     required: 'please enter a first name',
     length: 'please ask your parents for a shorter name',
   }
 }
}

// component
<FormControl validation-messages="$t('form.firstNameInput.validationMessages)"/>

// or even
<FormControl v-bind="$t('form.firstNameInput)"/>

Or when I know something will be a list:

// i18n
cancellation: {
  reasons: [`It was too big`, `It was too small`, `It looked a bit too much like a sailboat`, `it had a strange smell`]
}

// component
<ul>
  <li v-for="reason in $t('cancellation.reasons')>{{ reason }}</li>
</ul>

This flexibility has been amazing for us, allowing us to rely on vue-i18n to store structured content that we can use programmatically (especially when defining form controls). I don't understand any benefit to ensuring objects don't come back. Is there a new function that can be used instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions