Commit Graph

22 Commits

Author SHA1 Message Date
Javi Martín
a48db19c05 Show error message for just the displayed locale
Unfortunately the builder didn't offer any options for the error message
and we just had to overwrite the `error_for` methods.
2018-11-05 18:20:50 +01:00
Javi Martín
1ab3b7f42d Don't force translations for the current locale
Globalize creates a translation for the current locale, and the only way
I've found to change this behaviour is to monkey-patch it.

The original code uses `translation.locale` instead of
`Globalize.locale`. Since `translation.locale` loads the translation
with empty attributes. It both makes the record invalid if there are
validations and it makes it almost impossible to create a record with
translations which don't include the current locale.

See also the following convertations:

https://github.com/globalize/globalize/pull/328
https://github.com/globalize/globalize/issues/468
https://github.com/globalize/globalize/pull/578
https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
2018-11-05 18:20:50 +01:00
Javi Martín
f2d64833f0 Simplify methods defining translation styles
This refactor is going to be useful when we change these rules within
the next few commits.
2018-11-05 18:20:50 +01:00
Javi Martín
e9a5f03089 Update poll question answers translatable fields
We needed to bring back support for CKEditor in our translatable form,
which we had temporarily remove.

And now we support CKEditor in our translatable specs, and so we can
remove the duplicated specs for poll question answers.
2018-11-05 18:20:50 +01:00
Javi Martín
968a5b11d3 Update legislation drafts translatable fields
Updating it required reorganizing the form so translatable fields are
together.

We also needed to add a `hint` option to the form label and input
methods so the hint wouldn't show up for every language.

Finally, the markdown editor needed to use the same globalize attributes
as inputs, labels and hints, which adds a bit of duplication.
2018-11-05 18:20:25 +01:00
Javi Martín
a8f8a7bc4f Don't disable new invalid translations
After adding a new translation with invalid data and sending the form,
we were disabling the new translation when displaying the form again to
the user, which was confusing.
2018-11-05 18:19:50 +01:00
Javi Martín
6fc3389587 Keep invalid translation params through requests
We were reloading the values from the database and ignoring the
parameters sent by the browser.
2018-11-05 18:19:50 +01:00
Javi Martín
1874480ff0 Simplify passing the locale to translatable fields
Creating a new form builder might be too much. My idea was so the view
uses more or less the same syntax it would use with Rails' default
builder, and so we can use `text_field` instead of
`translatable_text_field`.
2018-11-05 18:19:50 +01:00
Javi Martín
009cea29bf Validate translations in banners
This change forces us to use nested attributes for translations, instead
of using the more convenient `:"title_#{locale}"` methods.

On the other hand, we can use Rails' native `_destroy` attribute to
remove existing translations, so we don't have to use our custom
`delete_translations`, which was a bit buggy since it didn't consider
failed updates.
2018-11-05 18:19:50 +01:00
Julian Herrero
4344165bce change translatable form helper for cktext_area 2018-09-24 19:40:51 +02:00
Julian Herrero
e6762d6bca handle non-underscored locale names for cktext_area 2018-09-21 20:50:23 +02:00
Marko Lovic
c7fcdd9b0e Use standard locale names for Globalize
It turns out it is not necessary to downcase and underscore
locale names to use the globalize-accessor gem. The gem
will automatically underscore the locale name when defining and
calling the accessor methods.
2018-09-11 18:48:14 +02:00
Marko Lovic
6fe7dc22bc Fix translatable field labels to not include locale
Label for field :title should be "Title", not "Title en"
2018-09-11 18:48:09 +02:00
Marko Lovic
ca5f8719a8 Fix helper to merge style option correctly 2018-09-11 18:48:05 +02:00
Marko Lovic
1fb1437886 Fix merging_translatable_field_options helper 2018-09-11 18:48:01 +02:00
Marko Lovic
5ad3bf03cd Nest TranslatableFormBuilder in helper module
To avoid having multiple top-level classes per file
2018-09-11 18:47:57 +02:00
Marko Lovic
e26500179a Add missing blank line between methods 2018-09-11 18:47:52 +02:00
Marko Lovic
38e6c394e7 Change string manipulation to use interpolation for readability 2018-09-11 18:47:48 +02:00
Marko Lovic
b9f3ea2a33 Change variable name to reflect possibility of being array 2018-09-11 18:47:43 +02:00
Marko Lovic
7b0aa1e104 Extract merge_translatable_field_options helper method 2018-09-11 18:47:34 +02:00
Marko Lovic
61e3b3b406 Incorporate label into translatabel field
Suggested by @javierm so that we can take advantage of certain browser
features that rely on a <label> tag being associated with an <input> tag.
2018-09-11 18:47:28 +02:00
Marko Lovic
2cb3e4b111 Extract translatable field logic to FormBuilder 2018-09-11 18:46:50 +02:00