Closed adriancsbna closed 7 months ago
@adriancsbna You have to wrap your widgets with the I18n()
widget. Did you do that?
Wrap your widget tree with the I18n
widget, below the MaterialApp
, together with
the localizationsDelegates
and the supportedLocales
:
import 'package:i18n_extension/i18n_widget.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
...
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', 'US'),
const Locale('pt', 'BR'),
],
home: I18n(child: ...) // Here !!!!!!!!!!!!!!!!!!!!!!!
);
}
The code home: I18n(child: ...)
shown above will translate your strings to the current system locale. Or you can override it with your own locale, like this:
I18n(
initialLocale: Locale('pt', 'BR'),
child: ...
Wow, right. When using routes and not a home I totally forgot about it.
I write below the code I used, in my case it is to wrap the widgets in the routes:
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
),
initialRoute: "/",
routes: {
'/': (context) => const SplashScreen(),
'/on_boarding': (context) => I18n(child: const OnBoardingScreen()), // Here!!
},
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('es')],
locale: const Locale('es'),
);
}
Thank you very much @marcglasberg
Hello.
I am using i18n_extensions for a new App and I have run into a problem. I'm setting the default language to Spanish, but for some reason, the App tries to translate to en_us and I get the following error: There are no translations in 'en_us' for "continue".
I don't have that language set anywhere, only Spanish. Here is the code of the MaterialApp and the i18n.
I am using Flutter 3.19.1 and i18n_extension: ^11.0.11