Table of Contents
Overview
Flutter doesn’t (yet) ship Somali (so) in the official flutter_localizations bundle. Until it lands upstream, you can vendor a single file (so.dart) that provides Somali strings for Material widgets and forwards Cupertino/Widgets to global fallbacks. This guide shows the exact setup used in the Masjid Abu Hureyra app.
Prerequisites
- Flutter with
flutter_localizationsenabled. - (Optional)
intlif you format dates/times in Somali.
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: any # optional, recommended for date/time formatting1) Add the Somali file
Create lib/l10n/so.dart and paste the final version below.
✅ Important: The
delegatemust be a static const insideSoMaterialLocalizations. ❌ Do not use anextensionto add a staticdelegate(Dart doesn’t allow static members in extensions).
// lib/l10n/so.dart
//
// One-stop Somali localization wiring for your app.
// - Material: Somali strings via SoMaterialLocalizations (your overrides)
// - Cupertino: temporarily forwards to GlobalCupertinoLocalizations (English/fallback)
// - Widgets: forwards to GlobalWidgetsLocalizations (text direction etc.)
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
/// ------------------------------
/// MATERIAL (Somali overrides)
/// ------------------------------
class SoMaterialLocalizations extends MaterialLocalizations {
// If your Flutter channel adds new abstract getters to
MaterialLocalizations, the compiler will tell you which ones are missing — implement them inSoMaterialLocalizationswith Somali (or temporary English).
2) Wire the delegates in MaterialApp
Make sure Somali delegates are listed before the global ones so they override.
import 'package:masjidabiihurayra/l10n/so.dart';
MaterialApp.router(
// ...
localizationsDelegates: const [
AppLocalizations.delegate, // your ARB-generated app strings
SoMaterialLocalizations.delegate, // 3) (Optional) Initialize dates in Somali
If you format dates/times:
import 'package:intl/date_symbol_data_local.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeDateFormatting('so');
runApp(const ProviderScope(child: MyApp()));
}4) Validate
-
Change device language to Somali (or set
locale: const Locale('so')) and verify:- Alert dialogs (OK/Cancel), menus, date/time pickers, tooltips.
- Week start day (Monday if you set
firstDayOfWeekIndex = 1). - Date formats match your
dd/mm/yyyy.
-
Your app strings (not provided by Material) should live in
lib/l10n/app_*.arb(e.g.,app_so.arb) and be accessed viaAppLocalizations.
5) Troubleshooting
-
“The values in a const list literal must be constants.” Remove
constfromlocalizationsDelegates, or ensure your custom delegates arestatic constand their delegate classes haveconstconstructors (as above). -
“The getter ‘delegate’ isn’t defined for the type ‘SoMaterialLocalizations’.” Ensure
delegateis declared inside the class:static const LocalizationsDelegate<MaterialLocalizations> delegate = _SoMaterialLocalizationsDelegate();(Do not put it in an extension.) -
“A MaterialLocalizations delegate that supports the ‘so’ locale was not found.” Make sure
SoMaterialLocalizations.delegateis inlocalizationsDelegatesbefore the global ones, andsupportedLocalesincludesLocale('so'). -
Weird weekday order Keep
narrowWeekdaysSunday-first; choose week start withfirstDayOfWeekIndex.
6) Notes on Quality & Future Upstreaming
- Several strings in the sample are placeholders or need refinement. You can iterate on translations anytime; they’re just getters.
- When an official Somali implementation lands in Flutter, you can remove the vendored file and rely on the stock
Global*delegates.
7) Minimal Example Snippet
final flutterSupportedLocales = const [
Locale('en'),
Locale('ar'),
Locale('fr'),
Locale('so'),
];
Locale? effectiveLocale(Locale? selected) {
if (selected == null) return null;
return flutterSupportedLocales.any((l) => l.languageCode == selected.languageCode)
? selected
: const Locale('en');
}8) License & Attribution
If you adapted strings from a public repo, check and keep the original LICENSE and add attribution in your repository. This blog post reflects a vendored approach for compatibility until official support ships.
Finish
With lib/l10n/so.dart in place and delegates registered, your Flutter app will show Somali UI for Material widgets today. If you hit a specific compile error after a Flutter upgrade, drop the error message in an issue and update SoMaterialLocalizations with any new required getters.
