Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ You can always take control of the views by creating your own views and/or parti
</html>
```


### Locales

The dashboard is written in English and renders in English whenever your app allows the `:en` locale. If `config.i18n.available_locales` leaves out `:en`, the dashboard renders in your app's locale instead, and you will need to provide the `datetime.distance_in_words.short` translations from [`config/locales/en.yml`](config/locales/en.yml) in that locale.

## Sponsors

<p align="center">
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/solid_errors/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SolidErrors
class ErrorsController < ApplicationController
around_action :force_english_locale!
around_action :use_english_when_available

before_action :set_error, only: %i[show update destroy]

Expand Down Expand Up @@ -53,7 +53,10 @@ def set_error
@error = Error.find(params[:id])
end

def force_english_locale!(&action)
# The dashboard's strings ship in English only; apps that don't allow :en keep their own locale
def use_english_when_available(&action)
return action.call unless I18n.locale_available?(:en)

I18n.with_locale(:en, &action)
end

Expand Down
16 changes: 16 additions & 0 deletions test/controllers/solid_errors/errors_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ class SolidErrors::ErrorsControllerTest < ActionDispatch::IntegrationTest
assert_select "main a[href='/']", text: "← Back to main app"
end

test "the dashboard renders in apps that do not make English available" do
available_locales, default_locale, locale = I18n.available_locales, I18n.default_locale, I18n.locale
I18n.available_locales = [:fr]
I18n.default_locale = I18n.locale = :fr

get solid_errors.errors_path
assert_response :success

get solid_errors.error_path(@error)
assert_response :success
ensure
I18n.available_locales = available_locales
I18n.default_locale = default_locale
I18n.locale = locale
end

private

def report_errors(count)
Expand Down
Loading