Repository navigation
Add Japanese locale, chosen from shopkeepers.locale or Accept-Language - #150
Merged
Merged
Conversation
Responses, validation errors, HTML pages and emails are now in English or
Japanese. SetLocale picks the locale per request from Accept-Language
(quality values, regional tags such as ja-JP), falling back to English. It
wraps process_action rather than using around_action, because rescue_from
handlers and rate_limit responses run outside the callback chain. Mails
queued during a request keep its locale.
Japanese lives in config/locales/ja.yml (app messages and attribute names),
rails.ja.yml (Active Model/Record validation messages) and devise.ja.yml,
written by hand instead of adding rails-i18n or devise-i18n. The error
pages, ErrorsController messages, the sample item tag and the mail
greetings moved from hard-coded English to locale keys; English output is
unchanged.
test/i18n/locale_files_test.rb fails on any English key without a Japanese
translation (app keys plus the Rails, Devise and devise_token_auth scopes)
or a Japanese-only %{variable}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WyUzNEPWyhjjWrBcSaXSW4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WyUzNEPWyhjjWrBcSaXSW4
Broken output: - Several errors were joined as "A, B, and C": add support.array (、). - An unknown current_platform printed only "は一覧にありません", since the attribute prints just its message; it now gets the spam-protection text (also in English, which printed only "is not included in the list"). - Accepting an invitation as an existing member said the user "already exists"; it now says they are already a member (also in English). - An invalid reset link read "Reset password tokenは不正な値です". - The reset password form still had "(8 characters minimum)" and an English placeholder. Wording: "は正しくありません" for invalid, "はすでに使われています" for taken, "を選択してください" for a missing role, 「」 instead of '...' in devise_token_auth messages, サインイン instead of the gem's ログイン, a clearer email format error, 個人用の組織, a full-width colon after the invitation's instructions heading, and a thank-you greeting in the confirmation mail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WyUzNEPWyhjjWrBcSaXSW4
Sign-up stores the locale the app sends (regional tags reduced to the language; unsupported or missing falls back to Accept-Language), and PATCH /shopkeeper_auth can change it (en or ja, else 422). Signed-in requests answer in that language; requests before authentication keep using Accept-Language. Confirmation, reset and invitation mails use the recipient's locale, an invitation to a new email the inviter's. Also fix PATCH /shopkeeper_auth returning 422 unless email was sent: devise_token_auth validated the params before name, time_zone and locale were permitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WyUzNEPWyhjjWrBcSaXSW4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shopkeepers.locale(the column already existed, defaulten) now decides the language of every signed-in request, overAccept-Language. Sign-up stores thelocalethe app sends (ja-JP→ja; unsupported or missing falls back toAccept-Language, so sign-up never fails over it).PATCH /shopkeeper_authchanges it (enorja, else 422). Confirmation and reset mails use the shopkeeper's locale; an invitation uses the invitee's if they have an account, otherwise the inviter's.SetLocaleconcern (inApplicationControllerandNonApiApplicationController) picks English or Japanese fromAccept-Language: quality values, header order for ties, regional tags (ja-JP),q=0refusals; anything else gets English. It wrapsprocess_actioninstead ofaround_action, becauserescue_fromhandlers (404/400/422 JSON) andrate_limit429s run outside the callback chain and came back in English otherwise.rails-i18n/devise-i18n:config/locales/ja.yml: every app message plus model and attribute names, so validation errors read e.g.店舗名を入力してください.rails.ja.yml: Active Model / Active Record validation messages.devise.ja.yml: Devise's messages (e.g. the 401 for a missing token). devise_token_auth already shipsja.yml; app overrides mirroren.yml.ErrorsControllerJSON messages, the sample item tag a new shop gets, and the mail greetings. English output is unchanged.I18n.locale).PATCH /shopkeeper_authreturned 422 unlessemailwas sent, because devise_token_auth validated the params beforename,time_zone(and nowlocale) were permitted.configure_permitted_parametersis now aprepend_before_action.Translation review
A second agent reviewed the Japanese against the English and the composed messages. Fixed in a follow-up commit, each with a test that failed first (
test/i18n/japanese_messages_test.rb, two more inlocale_test.rb):A, B, and C;support.arraynow joins them with、.current_platformprinted onlyは一覧にありません; it now gets the spam-protection message.ユーザーはすでにこの組織のメンバーです.Reset password tokenは不正な値です.(8 characters minimum)and an English placeholder.は正しくありません(invalid),はすでに使われています(taken),を選択してくださいfor roles, 「」 quotes and サインイン in devise_token_auth messages, a clearer email format error, 個人用の組織.English changes: an unknown
current_platformnow returns "Your input data is wrong." (same as blank), and a duplicate member returns "User is already a member of this organization" instead of "User has already been taken". Two existing model tests were updated for this.Not changed: the invitation mail names app UI labels (「組織」タブ, 「参加」ボタン). Whether they match the clients' Japanese labels needs checking against the iOS/Android apps.
Client impact
To use the stored locale, the apps should send
localeat sign-up and offer it on the profile screen (PATCH /shopkeeper_authwithlocale). Until they do, new shopkeepers get theirAccept-Languagelanguage stored at sign-up, and existing ones stayen.iOS sends
Accept-Languagefrom the device's preferred languages automatically, so Japanese devices get Japanese with no client change. Android's OkHttp sends noAccept-Languageby default; those clients keep getting English until they add the header. Clients that compareerror_messagestrings would break for Japanese devices; the template clients only display them.Tests
locale_test.rb,shopkeeper_test.rb,registrations_controller_test.rb): it wins overAccept-Languageboth ways; a failed sign-in still uses the header; sign-up withja,ja-JP, none, and unsupportedfr; profile update tojaand rejection offr(message in the stored language); confirmation, reset, and both invitation mails; model validation; atime_zone-only profile update. Each was seen failing by removing the matching line of the implementation.locale: ja-JPstoredja; a signed-in 404 withAccept-Language: enanswered見つかりませんでした。;PATCH locale=frgave言語は一覧から選択してください; afterPATCH locale=en, a 404 withAccept-Language: jaansweredNot found.test/integration/locale_test.rb(18 tests): header parsing cases, no locale leak between requests, Japanese validation message, Devise 401,rescue_from404, unknown-route 404 JSON and HTML page, 429, invitation mail, sample item tag.test/i18n/locale_files_test.rb: fails on an English key with no Japanese translation (app keys plus the Rails, Devise and devise_token_auth scopes) or a Japanese-only%{variable}.q=0, not stripping the region, and not switching the locale all turned the suite red.bin/rails test: 583 runs, 0 failures (was 568 before the stored-locale commit)bin/cipassed: 568 runs, 0 failures; RuboCop, erb_lint, Brakeman, bundler-audit clean.Accept-Language: ja: sign-in error, blank shop name, missing token and the reset password page were Japanese; without the header, English. A password reset mail queued in Japanese storedlocale: jaand was delivered with the subjectパスワード再設定のご案内.🤖 Generated with Claude Code
https://claude.ai/code/session_01WyUzNEPWyhjjWrBcSaXSW4