🚀 Join the waitlist now! waitlist.floot.dev
LogoFlootdocs

Internationalization

Set up and manage multi-language support in your Floot app.

The Floot starter kit comes with English and French support out of the box, and you can easily add additional languages as needed.

Support a new language

To add support for a new language in your Floot app, you’ll need to update both the front-end (Flutter) and back-end (Supabase).

The following steps use Spanish as an example.

Front-end (Flutter)

Locale

Add new locale

Look for app_locale.dart file and add the new locale (e.g. Spanish)

lib/core/presentation/utils/helpers/app_locale.dart
final class SpanishLocale extends AppLocale {
  const SpanishLocale() : super('es'); // make sure to provide the right country code
}

Add your language to the AppLanguage enum

Look for app_language.dart file and add your language of choice to AppLanguage enum.

  • code: the country code

  • name: the name you want to show in the UI (e.g. like the dropdown to switch the app language, etc.)

  • The code editor should also yell at you to handle toLocale(), so proceed

    lib/core/domain/models/app_language.dart
    enum AppLanguage {
      /// Spanish language.
      spanish('es', 'Español'), // new language
    
      /// English language.
      english('en', 'English'),
    
      /// French language.
      french('fr', 'Français'),
    
      /// System language.
      system('system', 'System');
    
      const AppLanguage(this.code, this.name);
    
      // ...existing code
    
      Locale? toLocale() {
        return switch (this) {
          AppLanguage.english => const EnglishLocale(),
          AppLanguage.french => const FrenchLocale(),
          AppLanguage.spanish => const SpanishLocale(), // new locale
          AppLanguage.system => null,
        };
      }
    }

Update the appLocale getter

In build_context_x.dart, update the appLocale getter. This getter determines the current app locale based on the user's language settings and returns an AppLocale instance (such as EnglishLocale, FrenchLocale, etc.). Using specific subclasses ensures only supported locales are used and helps prevent errors from unsupported or mistyped locale codes.

lib/core/presentation/utils/extensions/build_context_x.dart
extension BuildContextX on BuildContext {
  AppLocale get appLocale {
  final locale = Localizations.localeOf(this);

  return switch (AppLanguage.fromString(locale.languageCode)) {
    AppLanguage.english => const EnglishLocale(),
    AppLanguage.french => const FrenchLocale(),
    AppLanguage.spanish => const SpanishLocale(), // new locale
    AppLanguage.system => const EnglishLocale(),
  };
  }

  // ...existing code
}

Translations

After adding a new locale, you need to provide the corresponding translations for that language.

Duplicate the ARB file

Locate the app_fr.arb (lib/core/presentation/l10n/app_fr.arb) file and duplicate it as app_<your_country_code>.arb (for example, app_es.arb for Spanish).

Update the locale and translations

Update the @@locale field to match the new language code (e.g., es), and replace the values with the appropriate translations.

lib/core/presentation/l10n/app_es.arb
{
  "@@locale": "es",
  "aboutToQuitPage": "EstĂĄs a punto de salir de la pĂĄgina.",
  "account": "Cuenta"
  // ...other translations
}

Generate the new translations

Run this command in the terminal to generate the new translations.

Terminal
flutter gen-l10n

How to use localized text?

To show localized text in your app, use this built-in context extension:

  context.l10n!.hello // 'Hola' (Locale == "es"), 'Salut' (Locale == "fr")

Back-end (Supabase)

Once you’ve added support for a new language on the front-end, it’s recommended to update your back-end as well. This ensures that users receive emails in their selected language.

Add the new language to your Supabase types

Look for the l10n.ts file and add the language you supported in your front-end.

supabase/functions/send-email/_templates/l10n.ts
export type Language = "en" | "fr" | "es"; // "es" added

Translate email subjects

In l10n.ts, update the subjects object to include translations for your new language.

supabase/functions/send-email/_templates/l10n.ts
export const subjects: Record<Language, Record<EmailActionType, string>> = {
  en: {
    signup: "Confirm Your Email",
    recovery: "Reset Your Password",
    magiclink: "Your Magic Link",
  },
  fr: {
    signup: "Confirmez votre adresse email",
    recovery: "Réinitialisez votre mot de passe",
    magiclink: "Votre Code Magique",
  },
  // new spanish translations
  es: {
    signup: "Confirma tu correo electrĂłnico",
    recovery: "Restablece tu contraseña",
    magiclink: "Tu enlace mĂĄgico",
  },
} as const;

Translate email content

In each email template file, add translations for your new language by following the same principles as for email subjects.

  • In confirm-email.tsx:

    supabase/functions/send-email/_templates/sign-up/confirm-email.tsx
    const translations: Record<Language, EmailContent> = {
      // ...existing code
      es: {
        // spanish translations...
      },
    } as const;
  • In supabase/functions/send-email/_templates/magic-link/magic-link.tsx and supabase/functions/send-email/_templates/password-reset/password-reset-email.tsx, add translations for your new language following the same pattern.