SFDigitalServices / formio-sfds

The form.io theme for sf.gov
https://formio-sfds.herokuapp.com/
MIT License
15 stars 2 forks source link

Figure out how to localize Choices.js strings #165

Closed shawnbot closed 3 years ago

shawnbot commented 3 years ago

This would need to happen at the patch level, and would need to be deferred until after translations load. Where we currently patch the select component's customOptions object, we could do this:

const prefix = `${component.key}.choices` // e.g. "yourJob.choices"
component.customOptions = Object.assign({
  noResultsText: form.t(`${prefix}.noResultsText`, 'No results found'),
  noChoicesText: form.t(`${prefix}.noChoicesText`, 'No choices to choose from'),
  itemSelectText: form.t(`${prefix}.itemSelectText`, 'Press to select'),
  addItemText (value) {
    return form.t(`${prefix}.addItemText`, 'Press Enter to add <b>"{{value}}"</b>', { value })
  },
  maxItemText (count) {
    // using {{count}} here enables pluralization in i18next:
    // <https://www.i18next.com/translation-function/plurals>
    return form.t(`${prefix}.maxItemText`, 'Only {{count}} values can be added', { count })
  }
}, component.customOptions)