Skip to content

Improve decidim's i18n#1555

Merged
beagleknight merged 5 commits intomasterfrom
fix/simpler_dev_locales
Jul 28, 2017
Merged

Improve decidim's i18n#1555
beagleknight merged 5 commits intomasterfrom
fix/simpler_dev_locales

Conversation

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez commented Jun 30, 2017

🎩 What? Why?

This PR fixes several things regarding decidim languages:

  • Adds docs! 🎉

  • Allows configuring locales. At the moment, by the time decidim's configuration is run, the config.available_locales = Decidim.available_locales assignment in application.rb has already been run. So custom locales are not picked up. I fixed it by changing the order these are run.

  • Changes generated application locales to be :en, :ca & :es, instead of all available locales. At the moment, playing around with the generated application is a PITA because until we fix Only require the default locale translations #1127, all languages are required. And the generated application uses all 8 languages by default! Even if Only require the default locale translations #1127 was no longer a problem, I'm not sure we want to generate applications with all languages enabled, since it would be a pretty unrealistic application. I think enabling English + decidim original languages is a good compromise.. I finally used those locales not globally but for the sample organizations as suggested by @mrcasals.

  • Makes it easier to remove locales from an app by providing a rake task, decidim:sanitize_locales, that cleans up DB from no longer available locales. Without running this task, decidim can crash after removing locales, because the locales available for each organization might no longer be available.

📌 Related Issues

📋 Subtasks

None.

📷 Screenshots (optional)

None.

👻 GIF

catcold

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 30, 2017

Codecov Report

Merging #1555 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1555   +/-   ##
=======================================
  Coverage   96.78%   96.78%           
=======================================
  Files         511      511           
  Lines        8640     8640           
=======================================
  Hits         8362     8362           
  Misses        278      278

config.authorization_handlers = [ExampleAuthorizationHandler]

# Uncomment this lines to set your preferred locales
# config.available_locales = %i{en ca es}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Ruby 2.0 this is equivalent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. But we are enforcing the style I switched to via rubocop.

@mrcasals
Copy link
Copy Markdown
Contributor

mrcasals commented Jul 3, 2017

@deivid-rodriguez the second point can be related to #1532, if you want to link it :)

# Uncomment this lines to set your preferred locales
# config.available_locales = [:en, :ca, :es]
# Change this line to set your preferred locales
config.available_locales = [:en, :ca, :es]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the problems are the seeds, then? Since the organization created there uses Decidim.available_locales as its own available_locales. Maybe we can change it there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean using the hardcoded list for the organizations locales, but leaving the full list enabled here? As long as I don't have to fill in 8 locales for each field on every form, sounds good to me! :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'd change the values in the seeds until we start working on not making all the languages compulsory

task sanitize_locales: :environment do
Decidim::Organization.find_each do |organization|
sanitized_locales =
organization.available_locales & Decidim.available_locales.map(&:to_s)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. Shouldn't we update processes, etc in order to fix the locales there too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, I didn't know there were other locales in DB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we configure a reasonable set of locales per organization, I don't think we need this at the moment. I'll remove it, ok?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see what you meant by updating processes. All translations for every text field are saved in DB, of course...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I meant. We would need to update every process/meeting/whatever and remove that language :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm not sure leaving the translations around could cause any problems. And they would still be there if you reenable the language... :) I can see how the opposite is problematic in the current situation though (adding a new language and every object lacking compulsory translations).

- [Social providers integration](https://github.com/decidim/decidim/blob/master/docs/social_providers.md): Enable sign up from social networks.
- [Analytics](https://github.com/decidim/decidim/blob/master/docs/analytics.md): How to enable analytics
- [Geocoding](https://github.com/decidim/decidim/blob/master/docs/geocoding.md): How to enable geocoding for proposals and meetings
- [Languages](https://github.com/decidim/decidim/blob/master/docs/languages.md): How to enable configure languages
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to configure languages?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

@mrcasals Your comments make sense to me, it should make this much simpler. I'll update the PR & docs as you suggested.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Allows configuring locales. At the moment, by the time decidim's configuration is run, the config.available_locales = Decidim.available_locales assignment in application.rb has already been run. So custom locales are not picked up. I fixed it by changing the order these are run.

Should I keep 32c00fb? Removing locales globally is currently prone to errors (you have to re-seed or use a task like the one I provided here), and provides little value over configuring them per organization. So I'm not even sure about keeping that either, even if it fixes unexpected behavior.

@mrcasals
Copy link
Copy Markdown
Contributor

mrcasals commented Jul 3, 2017

We deliberately don't let system admins modify available locales for an already created organization, because we thought that modifying the locales could give some problems right now (until we do that PR about the locales).

As for that commit, I'd ping @beagleknight so he can chime in :)

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Oh, I didn't know that... #1127 keeps biting! 😱

@mention-bot
Copy link
Copy Markdown

@deivid-rodriguez, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mrcasals and @josepjaume to be potential reviewers.

@deivid-rodriguez deivid-rodriguez force-pushed the fix/simpler_dev_locales branch from d4ce6ec to 98e3e0c Compare July 24, 2017 21:23
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

I rebased this PR and removed the parts I was not sure about. Updated the PR description to reflect what's left in there. It's ready for another review pass!

@beagleknight beagleknight force-pushed the fix/simpler_dev_locales branch from 98e3e0c to 9e9a371 Compare July 25, 2017 08:03
@deivid-rodriguez deivid-rodriguez force-pushed the fix/simpler_dev_locales branch from 9e9a371 to 19f5bb0 Compare July 25, 2017 14:45
Due to the order Rails loads things, locale were not actually
configurable via `Decidim.available_locales` at the moment, because when
the assignment to Rails native locales was done, customizations had not
yet been loaded.

This change fixes it by loading locale customizations _before_ setting
`config.i18n.available_locales`.
Each test should be responsible for not leaking state.
@deivid-rodriguez deivid-rodriguez force-pushed the fix/simpler_dev_locales branch from 19f5bb0 to 3628cdd Compare July 26, 2017 10:55
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Anything else left to do here? This makes manual testing a lot easier IMO.

@decidim decidim deleted a comment from codecov bot Jul 28, 2017
@decidim decidim deleted a comment from codecov bot Jul 28, 2017
Copy link
Copy Markdown
Contributor

@beagleknight beagleknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok! Let's merge 😄

@beagleknight beagleknight merged commit 947bed6 into master Jul 28, 2017
@beagleknight beagleknight deleted the fix/simpler_dev_locales branch July 28, 2017 13:03
@ghost ghost removed the in-review label Jul 28, 2017
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Yuhuuuuu! 🎉

beagleknight pushed a commit that referenced this pull request Aug 2, 2017
* Fix code style of commented configuration

* Fix locale configuration

Due to the order Rails loads things, locale were not actually
configurable via `Decidim.available_locales` at the moment, because when
the assignment to Rails native locales was done, customizations had not
yet been loaded.

This change fixes it by loading locale customizations _before_ setting
`config.i18n.available_locales`.

* Fix typo

* No need to reset locales for every test

Each test should be responsible for not leaking state.

* A a more reasonable set of locale for sample orgs
homepage_image: File.new(File.join(__dir__, "seeds", "homepage_image.jpg")),
default_locale: I18n.default_locale,
available_locales: Decidim.available_locales,
available_locales: [:en, :ca, :es],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @deivid-rodriguez ! I know this is merged but I am having a few problems because of that 😄 . Do you remember why you hardcoded this values?
The problem I found is when a installation doesn't have English for example, I cannot create a review app because the seeds are creating "invalid" organizations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, that makes sense. The idea was not having 7 locales in the generated app by default. I initially changed the defaults in decidim's configuration. But @mrcasals suggested to do it per organization here. None of us realized of this problem... :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! 😄 I think I am going to change our app generator to include those locales as default because if we leave Decidim.available_locales commented it will use all the locales.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that... 🙏 I can rework another PR that doesn't touch the seed process if you want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heheh, we replied at the same time :) Sounds good to me, sorry for the trouble 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry! I think I can handle it and it's not a big deal 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add docs about i18n Only require the default locale translations

5 participants