getx
getx copied to clipboard
Flutter getx trparams (@ variables substitution) does not work for Hebrew locale. Reported in StackOverflow.com
ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.
Describe the bug When I select Hebrew-IL locale the @ variables are not substituted and are displayed on screen unchanged.
**Reproduction code Run the example. Keep clicking the button. Locale changes on every click.
example:
import 'package:get/get.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
translations: Languages(),
// locale: const Locale('en', 'US'),
locale: const Locale('he', 'IL'),
title: 'GetX I18N Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'GetX I18N Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Locale heilLocale = const Locale ("he", "IL");
Locale enusLocale = const Locale ("en", "US");
void _incrementCounter() {
setState(() {
_counter++;
if (_counter %2 ==0 ) {
Get.updateLocale(heilLocale);
} else {
Get.updateLocale(enusLocale);
}
});
}
@override
Widget build(BuildContext context) {
int correctAnswers = 11;
int questionsPerGame = 22;
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text('greeting'.tr),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text('greeting'.tr),
Text('local is ${Get.locale}'),
Text("summary_line".trParams({
"correctAnswers": "$correctAnswers",
"questionsPerGame": "$questionsPerGame"
})),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class Languages extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'en_US': {
'greeting': 'Hello, welcome to the counter app !',
"summary_line":
"You have answered correctly @correctAnswers out of @questionsPerGame",
},
'he_IL': {
'greeting': 'שלום, ברוך הבא לאפליקציית המונה !',
"summary_line":
"ענית נכון על correctAnswers@ מתוך questionsPerGame@ שאלות !",
}
};
}
To Reproduce Steps to reproduce the behavior:
- Run above example. main.dart. Default counter app modified.
- Click on button. Locale is changed on every click.
- If locale is English US the variables work fine. If locale is Hebrew Israel the @variables are not processed.
Expected behavior Expected behavior is that variables are processed in Hebrew IL locale the same way the work in English US locale.
Screenshots If applicable, add screenshots to help explain your problem.
Flutter Version: Latest. 3.19.5
Getx Version: Latest 4.6.6
Describe on which device you found the bug: ex: Moto z2 - Android.
Minimal reproduce code Provide a minimum reproduction code for the problem
Did you try "ענית נכון על @correctAnswers מתוך @questionsPerGame שאלות !" ?
Thank you! I will fix that