Docs/LanguageConfiguration.md
This guide explains how language support works in the Bagisto Flutter app and how to add a new language correctly.
The app uses Flutter's gen_l10n localization system with ARB files stored in lib/l10n/. Language selection is also connected to Bagisto backend locales, so adding a new language requires both:
If only the app translations are added, the UI text can be localized, but Bagisto content like categories, CMS pages, and other translated storefront data may still come from the default backend language.
| File | Purpose |
|---|---|
pubspec.yaml | Enables generated Flutter localization support with flutter: generate: true |
l10n.yaml | Configures the ARB directory and generated localization output |
lib/l10n/app_en.arb | Base English translation template |
lib/l10n/app_*.arb | Language translation files |
lib/l10n/app_localizations.dart | Generated localization delegate and supported locale list |
lib/main.dart | Applies selected locale to MaterialApp |
lib/core/locale/locale_cubit.dart | Saves and updates selected locale |
lib/core/channel/channel_bootstrap_service.dart | Loads available locales from Bagisto and stores the default locale |
lib/core/graphql/graphql_client.dart | Adds the X-LOCALE header to GraphQL requests |
lib/features/account/presentation/pages/preferences_bottom_sheet.dart | Language selector in the account preferences UI |
lib/features/account/presentation/pages/settings_bottom_sheet.dart | Alternate language selector UI |
The current generated app supports:
ardeenesfritnlrutrukYou can verify this in lib/l10n/app_localizations.dart.
ChannelBootstrapService fetches the Bagisto channel configuration.LocaleCubit reads the saved locale code from shared preferences.MaterialApp applies the locale using:
localelocalizationsDelegatessupportedLocalesGraphQLClientProvider sends the selected locale in the X-LOCALE header, which allows Bagisto to return localized content.Use a simple locale code that matches both Flutter and Bagisto, for example:
ptjahiCurrent app logic expects simple language codes like
enorfr. Region-based locale codes such aspt_BRare not fully supported by the current locale storage/comparison flow.
Copy the English template and create a new ARB file in lib/l10n/.
Example for Portuguese:
New file: lib/l10n/app_pt.arb
{
"@@locale": "pt",
"appTitle": "Bagisto Store",
"homeFailedToLoad": "Falha ao carregar a pagina inicial",
"commonRetry": "Tentar novamente"
}
app_en.arb must be present in the new file. Missing keys may cause build failures or silent fallbacks to English.@messageName@@locale matches the file codeFor messages with placeholders, keep the placeholder names unchanged:
"homeAddedToCartMessage": "{productName} added to cart",
"@homeAddedToCartMessage": {
"placeholders": {
"productName": {}
}
}
Run:
flutter gen-l10n
This updates the generated files inside lib/l10n/, including:
app_localizations.dartapp_localizations_<locale>.dartBecause pubspec.yaml already has flutter: generate: true, Flutter can also regenerate these files during normal builds, but running flutter gen-l10n is the clearest manual step after adding a new ARB file.
After generation, confirm all of the following:
app_localizations_pt.dartlib/l10n/app_localizations.dart includes Locale('pt') in supportedLocalesNo manual update is normally required in lib/main.dart because it already reads AppLocalizations.supportedLocales.
This step is required if you want the language to appear in the app's language selector and receive translated storefront data from the backend.
Make sure Bagisto is configured so that:
The app reads locale data from these GraphQL paths:
lib/core/graphql/queries.dart → channel.locales and channel.defaultLocalelib/core/graphql/account_queries.dart → localesIf Bagisto does not return the new locale, the app will not show it in the dropdown even if the ARB file exists.
Recommended verification steps:
You can also inspect debug logs or network headers and verify that GraphQL requests include:
X-LOCALE: <your-locale-code>
To change translations for an existing language:
app_<locale>.arb fileflutter gen-l10nIf you want the iOS project metadata to explicitly list the language:
CFBundleLocalizations inside Info.plist, so iOS properly recognizes the supported language.This is separate from Flutter ARB generation but is useful for native iOS configuration consistency.
Flutter automatically handles text direction based on the locale. If you add a new RTL language (such as he for Hebrew or fa for Persian), Flutter will apply RTL layout for standard widgets. However:
EdgeInsets.only(left: ...) or Alignment.centerLeft that should use directional equivalents (EdgeInsetsDirectional, AlignmentDirectional).ar) is already supported, so most layouts should already work, but new screens added after the initial RTL pass may not have been tested.When adding a new language, be aware of these existing behaviors:
lib/features/search/presentation/pages/search_page.dart uses localeId: 'en_US' for speech recognition, so voice input does not currently follow the selected app language.lib/features/home/data/models/home_models.dart prefers English theme customization translations when available, then falls back to the first available translation.These do not block adding a new UI language, but they are worth reviewing if you want a fully localized experience.
app_<locale>.arb file created with all keys from app_en.arb@@locale matches the new codeflutter gen-l10n completed without errorsapp_localizations_<locale>.dart)supportedLocales includes the new localeX-LOCALE headerCFBundleLocalizations