Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter getx trparams (@ variables substitution) does not work for Hebrew locale. Reported in StackOverflow.com #3073

Open
patishavir opened this issue Apr 8, 2024 · 3 comments
Assignees

Comments

@patishavir
Copy link

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:

  1. Run above example. main.dart. Default counter app modified.
  2. Click on button. Locale is changed on every click.
  3. 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

@jonataslaw
Copy link
Owner

Did you try "ענית נכון על @correctAnswers מתוך @questionsPerGame שאלות !" ?

@patishavir
Copy link
Author

English US locale works fine
Hebrew Israel locale does not work

@jonataslaw
Copy link
Owner

Thank you!
I will fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants