Repository navigation
feat(i18n): answer storefront customers in their language - #164
Merged
Merged
Conversation
The customer app already sends Accept-Language on every request, but the server ignored it, so API errors, push notifications, inbox items and SMS codes stayed English for a customer using the app in Mongolian or Ukrainian. SetStorefrontLocale (first in the storefront.api group) picks the closest shipped language from Accept-Language, answers the request in it, restores the previous locale afterwards, and stores it on the signed-in customer's contact meta when it changed. Order notifications read that stored language (CustomerLocale::for) and set it as the notification locale, so queued pushes are written in it too. An order edit summary is English for the console and driver, so non-English customers get the general "order was updated" line. Customer API messages in the v1 controllers, SetStorefrontSession, the validation rules and ReviewEligibility move to storefront::api, checkout, customers and notifications translation files under server/resources/lang, with en, mn and uk. English text is unchanged. Error codes and gateway/passthrough messages stay as they are. The Pest bootstrap gains a translator, __() and app()->getLocale()/setLocale().
From a native speaker's review: customer_not_found, no_customer_with_phone and customer_user_not_found now add "Шинэ хэрэглэгчээр бүртгүүлнэ үү."
customer_not_found (update, find, delete) and customer_user_not_found (account closure) are not sign-in errors, so telling the customer to register there read wrongly. Only no_customer_with_phone (loginWithPhone) keeps the hint.
4 of 16 tasks
Member
Author
|
API reference: fleetbase/postman#72 documents |
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
The storefront customer app already sends
Accept-Language(e.g.mn) on every request (storefront-app/src/hooks/use-storefront.ts), but the server ignored it. Customers using the app in Mongolian or Ukrainian still got English API errors, push notifications, inbox items and SMS verification codes. With this PR, the server answers in the customer's language.Related Issue
None.
Type of Change
Implementation Notes
Request language.
SetStorefrontLocaleis first in thestorefront.apigroup. It picks the closest shipped language fromAccept-Language(mn-MN→mn; unsupported →en; no header → unchanged) and runs the request in it. It restores the previous locale afterwards, which matters for Octane workers. A language is supported whenserver/resources/lang/<code>exists.Remembered language. When a signed-in customer (Customer-Token) sends a language different from the one stored, it is written to their contact meta (
meta.locale). The write goes straight to the table, with no model events. A request where the language is unchanged costs one select.Notifications. Queued notifications have no request, so
StorefrontOrderNotificationandStorefrontOrderChatMessageset the notificationlocalefrom the order customer's stored language. Laravel then sends every channel in that locale. Order notification text is built throughtrans(), and times use Carbon in that locale.OrderEditor, so it was left out.Strings. Customer-facing messages are now translation keys in
storefront::api,checkout,customersandnotifications, each inen,mnanduk. They cover:SetStorefrontSessionReviewEligibilityCartEnglish text is byte-identical.
Left unchanged: error codes, gateway and other
$e->getMessage()passthroughs, merchant-authored text (store and product names, campaigns, order activity labels), console and internal routes, and core-api / FleetOps messages. That includesAppReview::OFF_MESSAGE, phone validation, and Laravel's own validation messages, whosemn/ukfiles belong infleetbase/fleetbaseapi/resources/lang.Test bootstrap.
scripts/pest-bootstrap.phpgains a translator,__()/trans(), andgetLocale()/setLocale()on the test container.Validation
Heads-up, not from this PR:
composer.lockpinsfleetbase/core-api1.6.69 whilecomposer.jsonrequires^1.6.74. That is why PHP CI on the release PR (#162) fails, and why the App Review tests error locally.Documentation Impact
fleetbase/fleetbase.ioAPI Reference Impact
fleetbase/postmanAPI reference notes: the Storefront API now honours an optional
Accept-Languagerequest header (en,mn,uk), which sets the language oferror/message text. Payloads, status codes and error codes are unchanged. The Storefront collection could document the header.Documentation Notes
Add a "Localization" note to the Storefront API docs in
fleetbase/fleetbase.io. It should cover:Accept-Languageheader and the supported languagesserver/resources/lang/en)Risk
Accept-Language. Requests without the header behave as before.Accept-Language, so storefront-web customers now get their browser language when it ismnoruk.server/resources/lang/{mn,uk}, especially the Mongolian suffixes after store names (:store-ийн).