How to avoid Globalize3 from returning fallback translations for an attribute into a specific context?

前端 未结 3 1496
情话喂你
情话喂你 2021-01-19 01:43

I\'m working in the internationalization/localization of web site using Globalize3 and easy_globalize_accesors and right now I\'m adapting the forms to manage fields with po

3条回答
  •  误落风尘
    2021-01-19 02:12

    You can implement this method in your model:

      def read_translated_attribute(name)
        globalize.stash.contains?(Globalize.locale, name) ? globalize.stash.read(Globalize.locale, name) : translation_for(Globalize.locale).send(name)
      end
    

    Then you'll just need to set the input values in your form explicitely, like this:

    <%= text_field 'role', "name_#{locale}", :value => @role.read_translated_attribute(:name), :class => ... %>
    

提交回复
热议问题