Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Show the public demo in its one language, whatever the visitor asks for

Guido Boyke308c2d3a90c9
diff --git a/CLAUDE.md b/CLAUDE.md
index 8afbd3a..f2883a3 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -962,6 +962,9 @@ Kern antwortet.
vor `authenticate_user!` (Devise übersetzt seine Anmelde-Hinweise in der Sprache, die in
diesem Moment gilt). Reihenfolge: gültiges `?locale=`, Profilsprache eines Angemeldeten,
gemerkte Sprache dieser Sitzung (`session[:public_locale]`), `Accept-Language`, Deutsch.
+ Im Demo-Modus (`LALABASE_DEMO=1`) gilt davor immer `Lalabase::Demo::LOCALE`: Die Welt ist
+ in dieser Sprache geschrieben, und das geteilte Konto darf keine Wahl festhalten
+ (Guard: `spec/requests/demo_mode_spec.rb`).
Ein gültiges `?locale=` wird gemerkt. Die Registrierung übernimmt die Sprache des
Formulars ins Profil. Guard: `spec/requests/locale_per_request_spec.rb`.
⚠️ **Über dieser Leiter stand eine Sprosse: die Sprache im PFAD.** `/docs/:locale/…`
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7ac70b7..311bd49 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -261,7 +261,9 @@ class ApplicationController < ActionController::Base
I18n.with_locale(request_locale, &)
end
- # In this order:
+ # On the public demo, its one language (Lalabase::Demo::LOCALE), before anything
+ # else: the world is written in it, and nobody's choice can stick to the login
+ # every visitor shares. Otherwise, in this order:
# 1. A supported locale in the query string. Remember it for the Devise pages
# that follow without a locale parameter.
# 2. The signed-in user's profile language.
@@ -287,6 +289,8 @@ class ApplicationController < ActionController::Base
# own error handling turns a malformed JSON body into a 400. Through params, the parse
# error was raised here instead, one callback earlier, and the webhook answered 500.
def request_locale
+ return Lalabase::Demo::LOCALE if Lalabase::Demo.enabled?
+
query_locale = supported_locale(request.query_parameters['locale'])
if query_locale
remember_chosen_locale(query_locale)
diff --git a/lib/lalabase/demo.rb b/lib/lalabase/demo.rb
index a2748b5..e46e042 100644
--- a/lib/lalabase/demo.rb
+++ b/lib/lalabase/demo.rb
@@ -30,6 +30,10 @@ module Lalabase
# The hour (UTC) of the nightly reset (DemoResetJob). The banner reads it from
# here; spec/config/recurring_schedule_spec.rb holds config/recurring.yml to it.
RESET_HOUR_UTC = 3
+ # The one language of the demo: the world is written in it (Lalabase::Demo::Reset),
+ # and every page speaks it, whatever the browser, the address or a profile asks for
+ # (ApplicationController#request_locale).
+ LOCALE = :en
# The second latch of the reset (Lalabase::Demo::Reset): a row in system_settings
# that only `bin/rails lalabase:demo:setup` writes, and only on an instance
# without organisations. The flag alone never empties a database.
diff --git a/lib/lalabase/demo/reset.rb b/lib/lalabase/demo/reset.rb
index d9018d3..83e524c 100644
--- a/lib/lalabase/demo/reset.rb
+++ b/lib/lalabase/demo/reset.rb
@@ -40,7 +40,6 @@ module Lalabase
# AI on, through the instance's system credential: no own key, no package.
ORGANISATION = { ai_enabled: true, assistant_enabled: true, ai_provider: 'openai' }.freeze
- LOCALE = :en
def self.call(**) = new(**).call
@@ -73,7 +72,7 @@ module Lalabase
wipe
files.restore_kept
reseed
- World.new(locale: LOCALE, now: @now, organisation: ORGANISATION, embeddings: true,
+ World.new(locale: Demo::LOCALE, now: @now, organisation: ORGANISATION, embeddings: true,
password: PASSWORD).build
end
# After the commit: a world that failed to build keeps its files. The
diff --git a/spec/requests/demo_mode_spec.rb b/spec/requests/demo_mode_spec.rb
index e5a9590..44557bb 100644
--- a/spec/requests/demo_mode_spec.rb
+++ b/spec/requests/demo_mode_spec.rb
@@ -90,6 +90,43 @@ RSpec.describe 'Demo mode', :ci_guard, type: :request do
end
end
+ # The world is written in one language (Lalabase::Demo::LOCALE), and the pages
+ # around it speak the same, whatever the visitor's browser or address asks for.
+ describe 'the language' do
+ def page_language = Nokogiri::HTML(response.body).at_css('html')['lang']
+
+ it 'is the language of the world, whatever the browser asks for' do
+ get new_user_session_path, headers: { 'Accept-Language' => 'de-DE,de;q=0.9' }
+ expect(page_language).to eq(Lalabase::Demo::LOCALE.to_s)
+ end
+
+ it 'is the language of the world on a page that asks for another, and after it' do
+ get new_user_session_path(locale: 'de')
+ expect(page_language).to eq(Lalabase::Demo::LOCALE.to_s)
+
+ get new_user_session_path
+ expect(page_language).to eq(Lalabase::Demo::LOCALE.to_s)
+ end
+
+ it 'is the language of the world for a person whose profile says another' do
+ user = member(email: '[email protected]', password: 'a-long-password-1', language_preference: 'de')
+ sign_in_with(user.email, 'a-long-password-1')
+ follow_redirect!
+
+ expect(response).to have_http_status(:ok)
+ expect(page_language).to eq(Lalabase::Demo::LOCALE.to_s)
+ end
+
+ context 'without the flag' do
+ let(:demo_on) { false }
+
+ it 'follows the browser' do
+ get new_user_session_path, headers: { 'Accept-Language' => 'de-DE,de;q=0.9' }
+ expect(page_language).to eq('de')
+ end
+ end
+ end
+
# One account for everybody: Devise's lockout and the per-address throttle
# would let any visitor shut out all the others.
describe 'the shared login' do