Skip to content

feat: allow default locale to be set via DEFAULT_LOCALE env var#839

Open
rewritten wants to merge 1 commit intocoopdevs:developfrom
rewritten:feature/838-configurable-default-locale
Open

feat: allow default locale to be set via DEFAULT_LOCALE env var#839
rewritten wants to merge 1 commit intocoopdevs:developfrom
rewritten:feature/838-configurable-default-locale

Conversation

@rewritten
Copy link
Copy Markdown
Contributor

Summary

  • Replaces the hardcoded :es default locale with ENV.fetch('DEFAULT_LOCALE', 'es').to_sym
  • Defaults to es when the env var is not set, so no behaviour change for existing deployments
  • Consistent with the existing ALLOWED_HOSTS pattern in the same file

Resolves #838

🤖 Generated with Claude Code

Resolves coopdevs#838

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 7, 2026 17:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring the Rails app’s default I18n locale via an environment variable, keeping the existing :es default when unset.

Changes:

  • Replace hardcoded config.i18n.default_locale = :es with ENV.fetch('DEFAULT_LOCALE', 'es').to_sym.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to 16
config.i18n.default_locale = ENV.fetch('DEFAULT_LOCALE', 'es').to_sym
config.i18n.available_locales = [:es, :ca, :eu, :gl, :en, :'pt-BR', :fr, :ja]
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

DEFAULT_LOCALE is converted directly to a symbol and used as default_locale without validation. If the env var is set to an unsupported/blank value (not in config.i18n.available_locales on the next line), this can cause boot-time I18n::InvalidLocale errors (or silently misconfigure locale selection). Consider normalizing and validating the env value against available_locales, and falling back to :es (optionally logging a warning) when it's not allowed.

Suggested change
config.i18n.default_locale = ENV.fetch('DEFAULT_LOCALE', 'es').to_sym
config.i18n.available_locales = [:es, :ca, :eu, :gl, :en, :'pt-BR', :fr, :ja]
config.i18n.available_locales = [:es, :ca, :eu, :gl, :en, :'pt-BR', :fr, :ja]
default_locale_env = ENV['DEFAULT_LOCALE'].to_s.strip
default_locale = default_locale_env.empty? ? nil : default_locale_env.to_sym
config.i18n.default_locale = config.i18n.available_locales.include?(default_locale) ? default_locale : :es

Copilot uses AI. Check for mistakes.
@markets
Copy link
Copy Markdown
Collaborator

markets commented Apr 7, 2026

@rewritten It misses docs, as we did in #833 and update from develop (conflitcs).

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.

Provide env var to configure default locale

3 participants