Commit Graph

10396 Commits

Author SHA1 Message Date
Javi Martín
0c1228a7ce Fix crash with no translation for default locale
When we were visiting a page showing the content of a record which uses
globalize and our locale was the default one and there was no
translation for the default locale, the application was crashing in some
places because there are no fallbacks for the default locale.

For example, when visiting a legislation process, the line with
`CGI.escape(title)` was crashing because `title` was `nil` for the
default locale.

We've decided to solve this issue by using any available translations as
globalize fallbacks instead of showing a 404 error or a translation
missing error because these solutions would (we thinkg) either require
modifying many places in the application or making the translatable
logic even more complex.

Initially we tried to add this solution to an initializer, but it must
be called after initializing the application so I18n.fallbacks[locale]
gets the value defined in config.i18n.fallbacks.

Also note the line:

fallbacks[locale] = I18n.fallbacks[locale] + I18n.available_locales

Doesn't mention `I18n.default_locale` because the method
`I18n.fallbacks[locale]` automatically adds the default locale.
2018-11-05 18:20:50 +01:00
Javi Martín
98cfe8c503 Remove question option uniqueness validation
Having translations makes this validation too complex and not worth the
effort, since now we can't just scope in a single column but we need to
scope in the translations locale and the question ID.
2018-11-05 18:20:50 +01:00
Javi Martín
cf4c30b143 Prefix classes used in JavaScript with "js-"
The same way it's done in the rest of the application.
2018-11-05 18:20:50 +01:00
Javi Martín
d10f07b0b4 Make it easier to know destroy_field is an input
By using the input and finding it by its name, it's easier to see the
difference between this input and the delete-language link.
2018-11-05 18:20:50 +01:00
Javi Martín
9aa07e3b74 Follow naming conventions for HTML classes and IDs
We use underscores for IDs and hyphens for classes.
2018-11-05 18:20:50 +01:00
Javi Martín
f475f4ff3f Remove reference to site customization page locale
We don't use that attribute since we added translations for this model.
2018-11-05 18:20:50 +01:00
Javi Martín
ed990c24d0 Fix "Add option" link position
The new options were being added inside the `.column` div, when they
needed to be added before it.
2018-11-05 18:20:50 +01:00
Javi Martín
44f71b24db Fix rubocop line too long warning 2018-11-05 18:20:50 +01:00
Javi Martín
9fc235727e Extract method in translatable builder
This way we fix the rubocop warning for line too long and make the code
a bit easier to read.
2018-11-05 18:20:50 +01:00
Javi Martín
b024363fae Fix removing an option for legislation questions
We were allowing the `_destroy` field for translations, but not for the
options themselves.
2018-11-05 18:20:50 +01:00
Javi Martín
3165b9b9f4 Fix legislation options not being updated
We broke this behaviour by introducing translations and not allowing the
`id` parameter anymore.
2018-11-05 18:20:50 +01:00
Javi Martín
015cdcc557 Simplify creating a process in questions specs 2018-11-05 18:20:50 +01:00
Javi Martín
1c75df92d7 Fix updating translatables without current locale
The current locale wasn't being marked for destruction and so saving
the record tried to create a new translation for the current locale.
2018-11-05 18:20:50 +01:00
Javi Martín
01ed66e9bb Fix alignment in last translatable fields
When we grouped the fields together, the last one turned into a
`last-child`, which foundation automatically aligns to the right.

The markdown editor also needed to be tweaked a little bit.
2018-11-05 18:20:50 +01:00
Javi Martín
7b9b65043f Fix ambiguous field in test 2018-11-05 18:20:50 +01:00
Javi Martín
28ed6aa136 Make private methods private 2018-11-05 18:20:50 +01:00
Javi Martín
2658bb55f6 Wrap translation fields in a div
This way we can show/hide that div when displaying translations, and we
can remove the duplication applying the same logic to the label, the
input, the error and the CKEditor.

This way we also solve the problem of the textarea of the CKEditor
taking space when we switch locales, as well as CKEditor itself taking
space even when not displayed.
2018-11-05 18:20:50 +01:00
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
87484015da Update information texts translatable fields
This part used the code we deleted in order to make it easier to
refactor the rest of the translatable models. Now we add the code back.
2018-11-05 18:20:50 +01:00
Javi Martín
1f033383e5 Refactor globalize_locales partials to increase DRYness 2018-11-05 18:20:50 +01:00
Angel Perez
4af5e1d46d Improve I18nContent#flat_hash readability using concise variable names 2018-11-05 18:20:50 +01:00
Angel Perez
ae9cad3c5b Avoid ternary operator usage when appending/creating I18n keys
When using the OR operator, if the left side of the expression evaluates
to false, its right side is taken into consideration. Since in Ruby nil
is false, we can avoid using conditionals for this particular scenario
2018-11-05 18:20:50 +01:00
Angel Perez
3c033d0ac3 Improve readability for I18nContent#begins_with_key spec
In order to be consistent with similar specs, the I18nContent#begins_with_key
spec was improved by explicitly specifying an I18n key for one (1) factory
that relied on its default value
2018-11-05 18:20:50 +01:00
Angel Perez
64dbf55d55 Fix Rubocop warnings [ci skip] 2018-11-05 18:20:50 +01:00
Raúl Fuentes
ff6e8c9bcb Move flat_hash to I18nContent model
also add unit tests for this function and a description
into the model of the behaviour of the function
2018-11-05 18:20:50 +01:00
Angel Perez
9b19a4e956 Extract translation logic to helper method 2018-11-05 18:20:50 +01:00
Angel Perez
362157d56e Add I18nContent model specs 2018-11-05 18:20:50 +01:00
Javi Martín
937cf0bdd3 Validate both the model and its translations
This way we guarantee there will be at least one translation for a model
and we keep compatibility with the rest of the application, which
ideally isn't aware of globalize.
2018-11-05 18:20:50 +01:00
Javi Martín
a38eac02df Refactor globalize models code using a concern
I've chosen the name "Globalizable" because "Translatable" already
existed.
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
981b13ac9b Update widget cards translatable fields 2018-11-05 18:20:50 +01:00
Javi Martín
e400cb8eae Update site customization pages translatable fields 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
292609e7ac Update poll questions translatable fields
We need to replace ".title=" by ".title_#{locale}=" in one place because
for some reason globalize builds a new translation record when using the
latter but it doesn't build one when using the former.
2018-11-05 18:20:25 +01:00
Javi Martín
6478bb70c2 Update polls translatable fields
The `:name` attribute is still allowed in the controller because some
forks use it when creating a poll from a budget.
2018-11-05 18:20:25 +01:00
Javi Martín
601fe666d9 Fix question options translations not being saved
If we enabled the locale and then added an option, the "add option" link
added the partial which was generated before enabling the translation,
and so it generated a field where the translation was disabled.

Enabling the translation after inserting each field solves the issue.
2018-11-05 18:20:25 +01:00
Javi Martín
7cd06bd51d Update legislation questions translatable fields 2018-11-05 18:20:25 +01:00
Javi Martín
9c5a7c58a7 Update legislation process translatable fields 2018-11-05 18:20:25 +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
d5bd481f7f Update milestones translatable fields
Note the title field was hidden since commit 01b9aa8, even though it was
required and translatable. I've removed the required validation rule,
since it doesn't seem to make much sense and made the translatable
tests harder to write.

Also note the method `I18n.localize`, which is used to set the
milestone's title, uses `I18n.locale` even if it's inside a
`Globalize.with_locale` block, and so the same format is generated for
every locale.
2018-11-05 18:19:50 +01:00
Javi Martín
d40cd3995d Update admin notifications translatable fields
The same way we did for banners.

We needed to add new translation keys so the labels are displayed in the
correct language. I've kept the original `title` and `body` attributes
so they can be used in other places.

While backporting, we also added the original translations because they
hadn't been backported yet.
2018-11-05 18:19:50 +01:00
Javi Martín
5e6dfe6ed8 Disable removed translations
After removing a translation while editing another one with invalid data
and sending the form, we were displaying the removed translation to the
user.

We now remove that translation from the form, but we don't remove it
from the database until the form has been sent without errors.
2018-11-05 18:19:50 +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
decabeza
68b83f3a2b Removes unnecessary style to orbit slide 2018-11-05 18:19:50 +01:00
decabeza
c30c94f878 Removes condition to allow images and data equalizer on proposals
The proposal image only can be present if feature :allow_images is enabled, so there is no need to include both conditions. The data-equalizer also is unnecessary because the :thumb image already has an fix height.
2018-11-05 18:19:50 +01:00
decabeza
ebca4bca9b Removes styles to fix logo size on devise views 2018-11-05 18:19:50 +01:00