Setting and switching the request locale in storefront code
Key Takeaway
Each storefront request runs in one locale, which comes from the URL. request.setLocale() changes it only when the locale is valid, active, and allowed for the current site. If any of those fails, the call returns false and the request keeps its locale.
In B2C Commerce, every storefront request runs in one locale, such as en_US or fr. That request locale decides which translated strings, templates, static files, product data and currency the shopper sees. Storefront code reads the current locale and can switch the request to another locale. It also builds the links that let shoppers switch, by pointing each link at a URL for a different allowed locale.
What a locale is
en is a language-specific locale. en_US means English in the United States. en_IE means English in Ireland. Locale IDs combine an ISO 639 language code with an ISO 3166 country code.