ruby on rails - How to implement i18n in the Simple Form gem for a collection's "priority:" option -


integrating i18n simple form gem

simple_form accommodates i18n well, , docs pretty thorough on i18n, don't address solution "priority:" option collection field. i've tried applying idea/structure use "hints:" , "prompts:" isn't working. must missing something.

excerpt yml:

simple_form:     hints:       location:         website: must enter leading http://          short_desc:  general information, not review.        prompts:       location:         state: select state        # tried this, doesn't seem work            priority:       location:         country: united states of america     

here's snippet form:

# works prompt per spec. <%= f.input :state, collection: us_states, prompt: :translate %>   # tried this. nope. missing translation error. <%= f.input :country, priority: [ t('.country') ] %>   # tried this. nope.  missing translation error. <%= f.input :country, priority: :translate %>  

i make work creating custom t. string "priority:" setting in default yml, more logical , maintainable if setting's string had consistent implementation simple_form's "hints:" , "prompts:" there must simple_form solution. in advance.

added notes (edit) else has problem, wanted add notes here. translating path-to-str verbatim @ console work. but, simple gem uses context dependent translations based on yml formatted in way gem interprets. specification clear on , works 2 form properties "hints" , "prompts." problem seems simple form doesn't implement context correctly form collection property "priority" in same way "prompts" , "hints." form property "priority" not spec'ed simple form, , not work, makes me think it's been omitted on purpose. i'm going have contact gem builders , see have say.

i18n implementation in simple form "priority" property collection form field

to answer, contacted gem contributors on git repo simple form. summary of question asked:

is form collection field feature "priority" implemented in i18n simple form? if so, grateful information on yaml needs structured simple form use translation.

the answer both yes , no.

yes, country select field, if using country_select gem

country priorities handled country_select gem. simple form delegates country select's "priority" string setting. not explicitly add string simple form's yaml, tried in question example above. problem solved setting priority in country_select component, okay.

but other collections, lists of things you'd have default selected , have part of simple_form translation yaml?

no, other custom collections

i'll quote contributor project

there's nothing related generic priority fields right now, countries/time zones delegated country_select/rails.

it's not end of world

in simple form form loop, hints, labels , prompts pulled in simple_form yaml you've set up, have explicitly assign priority field translation string in form itself. see code example below.

en.yml

en:   # simple_form custom widgets   simple_form:     hints:       location:         website: must valid website          short_desc:  50 words ofr less        prompts:       location:         state: select state        # must explicitly referenced           priority:       location:         country: united states of america     

form.html.erb

important side note: "prompt" you've set in yaml work, must explicitly invoke :translate on prompt: (you need not explicit on t string, wanted example clear possible.)

<%= simple_form_for(@location) |f| %>       <%= f.input :name %>       <%= f.input :street %>       <%= f.input :city %>       <%= f.input :state, collection: us_states, prompt: :translate %>       <%= f.input :country, priority:[t('simple_form.priority.location.country')] %>        <%= f.input :phone %>       <%= f.input :website %>       <%= f.button :submit, class: "btn btn-primary" %>     <% end %> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -