Skip to content

Conversation

@akshayutture-augment
Copy link

The FallbackLocaleList object tells I18n::Backend::Fallbacks what order the
languages should be attempted in. Because of the translate_accelerator patch,
the SiteSetting.default_locale is *not* guaranteed to be fully loaded after the
server starts, so a call to ensure_loaded! is added after the locale is set for
the current user.

The declarations of config.i18n.fallbacks = true in the environment files were
actually garbage, because the I18n.default_locale was
SiteSetting.default_locale, so there was nothing to fall back to. *derp*
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 4/5

  • This PR is safe to merge with low risk
  • The implementation is well-structured and follows Discourse patterns. The custom FallbackLocaleList class properly handles dynamic site settings, and the initialization order is correct (loads after freedom patches and site settings due to alphabetical ordering). The lazy-loading approach in the [] method avoids initialization timing issues. Minor confidence reduction due to lack of visible test coverage in the changeset.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
config/initializers/i18n.rb 4/5 Added custom FallbackLocaleList class to handle locale fallback order (user locale → site default → English) and integrated pluralization support
lib/freedom_patches/translate_accelerator.rb 5/5 Added ensure_loaded! method to support explicit locale preloading for fallback chain
app/controllers/application_controller.rb 5/5 Added call to I18n.fallbacks.ensure_loaded! in set_locale to preload fallback locales

Sequence Diagram

sequenceDiagram
    participant Controller as ApplicationController
    participant I18n as I18n Module
    participant Fallbacks as FallbackLocaleList
    participant Accelerator as TranslateAccelerator
    participant Backend as I18n::Backend
    
    Controller->>Controller: set_locale()
    Controller->>I18n: Set locale (user or site default)
    Controller->>Fallbacks: ensure_loaded!()
    Fallbacks->>Fallbacks: self[I18n.locale]
    Note over Fallbacks: Returns [user_locale, site_default, :en]
    loop For each locale in fallback chain
        Fallbacks->>I18n: ensure_loaded!(locale)
        I18n->>Accelerator: load_locale(locale)
        Note over Accelerator: Check if already loaded
        alt Not yet loaded
            Accelerator->>Backend: load_translations(locale files)
            Accelerator->>Accelerator: Add to @loaded_locales
        end
    end
    
    Note over Controller,Backend: Later during request...
    Controller->>I18n: translate(key)
    I18n->>Accelerator: Check cache
    alt Cache miss
        I18n->>Backend: Lookup with fallbacks
        Note over Backend: Tries user locale → site default → :en
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

3 participants