Commit Graph

35 Commits

Author SHA1 Message Date
Javi Martín
26b48e527a Move information texts form partial to a component
This way it'll be easierto write tests for it when we change it.
2024-06-05 16:10:56 +02:00
Javi Martín
5f09718e77 Move globalize locales partial to a component 2024-06-05 16:10:55 +02:00
Javi Martín
4855fee3d5 Remove unused code in globalize helper
This code isn't used since commit 041abe904.
2024-06-05 16:10:55 +02:00
Javi Martín
f87d4b589d Add and apply Naming/BlockForwarding rubocop rule
This syntax has been added in Ruby 3.1.

Not using a variable name might not be very descriptive, but it's just
as descriptive as using "block" as a variable name. Using just `&` we
get the same amount of information than using `&block`: that we're
passing a block.

We're still using `&action` in `around_action` methods because here we
aren't using a generic name for the variable, so (at least for now) we
aren't running this cop on controllers using `around_action`.
2023-09-12 15:17:28 +02:00
Javi Martín
32b1fc53e1 Add and appy MultilineOperationIndentation rule
This way it's easier to see when lines are part of multiline
statements and when they belong to `if` statements.
2023-08-18 14:56:16 +02:00
Javi Martín
a102f3f0a7 Add and apply Style/ExplicitBlockArgument rule
We were already applying it in most places.
2021-08-09 19:11:29 +02:00
Javi Martín
749428d93f Replace content_tag with new tag builder syntax
One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
2020-04-27 19:26:37 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
6b1864fbcd Sanitize translations instead of using _html
Using the `_html` suffix in an i18n key is the same as using `html_safe`
on it, which means that translation could potentially be used for XSS
attacks.
2019-10-09 19:46:47 +02:00
Javi Martín
9c3686a6d8 Remove unused block parameters
We're using `yield` in the method body.
2019-10-05 15:03:25 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Senén Rodero Rodríguez
58164ee2ec Show validation error at translation interface
Only when present
2019-07-02 17:15:27 +02:00
Senén Rodero Rodríguez
041abe9044 Add persisted but marked for destruction translations to logic
Now we take into consideration locales persisted but marked for
destruction to complete some logic and to be able to show best
translations on different situations.
2019-07-02 17:15:22 +02:00
Senén Rodero Rodríguez
b2d8851bcc Add the option to disable languages managment to cover special cases
We understand languages management as the ability to add new languages
or remove existing ones. When no option is passed it will allow language
manipulation by default.

There are 3 special places where we want block languages management:
- admin legislation processes homepage
- admin legislation processes milestones summary
- proposals retired form

Co-Authored-By: Sebastia <sebastia.roig@gmail.com>
2019-07-01 15:03:48 +02:00
taitus
07577a050c Cover special translation interface behavior at admin information texts
When not yet exists I18nContentTranslation languages,
SiteCustomization::InformationText section render I18n.locale by
default. This was causing that `languages in use` description and
default selected language were incorrectly initialized.
2019-07-01 14:49:44 +02:00
Senén Rodero Rodríguez
5ada975448 Adapt globalize helper methods to new translation interface markup 2019-07-01 14:49:43 +02:00
Senén Rodero Rodríguez
9fd77d4042 Add languages in use description
New interface now shows a description to ensure the user
knows how many languages are currently in use.
2019-07-01 14:49:43 +02:00
Senén Rodero Rodríguez
f87804aa90 Update helpers after globalize gem version update
Globalize has fixed new translations globalized_model initialization
so we have to adapt existing code.
2019-04-17 17:40:55 +02:00
Javi Martín
93a7cb6c0f Simplify code checking whether to enable a locale 2018-10-22 16:36:18 +02:00
Javi Martín
3b5a12b0ab 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-10-22 16:28:53 +02:00
Javi Martín
124b8496de Simplify methods defining translation styles
This refactor is going to be useful when we change these rules within
the next few commits.
2018-10-22 16:28:53 +02:00
Javi Martín
96b3a37222 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-10-22 15:43:28 +02:00
Javi Martín
7deb857357 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-10-22 15:43:28 +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
ca5f8719a8 Fix helper to merge style option correctly 2018-09-11 18:48:05 +02:00
Marko Lovic
2cb3e4b111 Extract translatable field logic to FormBuilder 2018-09-11 18:46:50 +02:00
Marko Lovic
4603a30f95 Change Translatable impl to keep track of enabled locales 2018-09-10 17:18:01 +02:00
Marko Lovic
cb716e07d7 Extract translation helper from translatable form views
So that individual form partials don't depend on the implementation
of how translations are deleted.
2018-09-10 17:17:47 +02:00
decabeza
5bcec351ef Improves admin content translatable ui 2018-05-10 09:01:12 +02:00
iagirre
471c9730cc Refactorings
- Cleanup Translatable module (`translation_params` method too large)
- Move globalize_helpers partial to admin folder
- Use any class for method translation_params
- Helpers in `GlobalizeHelpers` make sure all are in use and see if they can be more legible
- Review js name clases and methods see if they can be more legible
- Refactor milestone views into partials with nice spacing between attributes
2018-05-09 16:58:47 +02:00
iagirre
951d1c1695 Use a helper with yield Globalize.with_locale
A helper has been created to encapsule the logic
of Globalize.with_locale. Now, to call that function,
globalize(locale) do is called.
2018-05-09 16:07:21 +02:00
iagirre
8b9d1ebd33 Make portuguese locale work
There was a problem with the portuguese locale.
The locale was pt-BR, but `globalize_accessors` gem
doesn't allow the creation of methods using locales
with that format.

To avoid transforming pt-BR to pt and lose the distinction
of the different variations of the language, a function has
been added to transform pt-BR into pt_br (without changing
the locale itself). That way, when globalize uses the locales,
all of them will have a valid format (downcased and underscored)
AND they will be always the same (comparing pt-BR with pt_br
doesn't work).
2018-05-09 16:07:21 +02:00
iagirre
285e02ce96 Highlight current locale when changing locale from select
When the locale changes the corresponding tab is
highlighted automatically.
When a language is added to the milestone, the tab
is highlighted automatically.
2018-05-09 16:07:21 +02:00
iagirre
b318c2be46 Add feature to delete a translation
To delete a translation, a link has been added. This
link works for the selected language. It hides all the
things related to a language (the tab and the text_area)
and empties the text area, so that the value is blank
in the param hash. A variable called `delete_translations[]`
is changed.

e.g. If admin wants to remove English language,
delete_translations[:en] will be 1; if not, it will be 0.

When the milestone is updated, there is a before_action
callback that cleans the selected languages for deletion
(looking the delete_translations[] variable).
Because of the deleted translations are blank in param hash,
them won't be saved in DB.
2018-05-09 16:07:12 +02:00
rgarcia
f7486b9238 Add Globalize to Milestones 2018-05-09 16:05:44 +02:00