-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for setting labels, hints and legends via Rails' i18n #68
Comments
The with_localisations method allows us to temporarily set the locale backend and always cleans up after itself. Refs #68
This will pull the correct localisation string from the backend and display it unless it has been overridden by manually supplying text Refs #68
This can now be optionally set and will be used for the retrieval of localisations from the I18n backend Refs #68
Compacting the array and joining the remains can return a hash if it matches the structure of the backend. For example, "helpers.person.." will return the other translations for the object. Instead, return nil unless all parts are present Refs #68
This is a great addition! Are there plans to make the i18n scopes configurable? For example, I'd like to use the ActiveRecord |
Thank you! I'm in agreement regarding being able to configure it, and generally being able to configure how the builder works is definitely on my radar (mainly for things like setting default label/legend sizes and tags, etc). The automatic building of the path is very straightforward and should be easily-overridable, but I think individually configuring the structure labels, hints and legends might get a bit complicated. |
CollectionItem will hold functionality that's specific to items belonging to a collection. Initially, this covers the retrieval of the value depending on what's passed into the :text_method, :value_method or :hint_method params. These arguments now accept and properly deal with procs Refs #68
Instead of using `#send` inline to retrieve the value from `@item`, make use of `#retrieve` which works with procs. Refs #68
The :value_method, :text_method and :hint_method params passed to radio collections and the :hint_method params passed to checkbox collections now accept procs which can be used to customise the value retrieved from the item. This could be used for simple transformations like upcasing the text or more-complex operations like localising the value, as per the provided specs Refs #68
CollectionItem will hold functionality that's specific to items belonging to a collection. Initially, this covers the retrieval of the value depending on what's passed into the :text_method, :value_method or :hint_method params. These arguments now accept and properly deal with procs Refs #68
Instead of using `#send` inline to retrieve the value from `@item`, make use of `#retrieve` which works with procs. Refs #68
The :value_method, :text_method and :hint_method params passed to radio collections and the :hint_method params passed to checkbox collections now accept procs which can be used to customise the value retrieved from the item. This could be used for simple transformations like upcasing the text or more-complex operations like localising the value, as per the provided specs Refs #68
This is now in the 1.1.0 branch |
Add support for customising the localisation schema (provided in #68) as part of the application config. The configuration allows for the value localisation_schema_fallback to be set, which provides a default 'base' schema; and localisation_schema_label, localisation_schema_hint, and localisation_schema_legend to be set which configures labels, hints and legends respectively. One slightly-breaking change (from the initial version of localisation functionality) is that now we're referring to fieldset legends by legend rather than fieldset. This is more inkeeping with the language used everywhere else in the project and definitely feels cleaner.
The with_localisations method allows us to temporarily set the locale backend and always cleans up after itself. Refs #68
This will pull the correct localisation string from the backend and display it unless it has been overridden by manually supplying text Refs #68
This can now be optionally set and will be used for the retrieval of localisations from the I18n backend Refs #68
Compacting the array and joining the remains can return a hash if it matches the structure of the backend. For example, "helpers.person.." will return the other translations for the object. Instead, return nil unless all parts are present Refs #68
CollectionItem will hold functionality that's specific to items belonging to a collection. Initially, this covers the retrieval of the value depending on what's passed into the :text_method, :value_method or :hint_method params. These arguments now accept and properly deal with procs Refs #68
Instead of using `#send` inline to retrieve the value from `@item`, make use of `#retrieve` which works with procs. Refs #68
The :value_method, :text_method and :hint_method params passed to radio collections and the :hint_method params passed to checkbox collections now accept procs which can be used to customise the value retrieved from the item. This could be used for simple transformations like upcasing the text or more-complex operations like localising the value, as per the provided specs Refs #68
Add support for customising the localisation schema (provided in #68) as part of the application config. The configuration allows for the value localisation_schema_fallback to be set, which provides a default 'base' schema; and localisation_schema_label, localisation_schema_hint, and localisation_schema_legend to be set which configures labels, hints and legends respectively. One slightly-breaking change (from the initial version of localisation functionality) is that now we're referring to fieldset legends by legend rather than fieldset. This is more inkeeping with the language used everywhere else in the project and definitely feels cleaner.
Currently all of the helpers require that the text that's passed in to form labels, hints and legends is supplied inline. Many projects prefer to store the text in the locales files and use Rails' i18n to populate the relevant strings.
There's a working implementation in the GOV.UK elements form builder that can be used for inspiration.
Additional things to check
text_method:
and:hint_method
which probably already do everything that's required 🤔Should there be a shorthand way to specify to the helper which localisation key to use? Rather than doing something likelabel: { text: I18n.t('my.favourite.type.of.pasta') }
perhapslabel: { t: 'my.favourite.type.of.pasta' }
? 🤷🏽♂️The text was updated successfully, but these errors were encountered: