Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cant translate text with value using GETX in flutter

the problem is that the text has value which declares the day before the text
so idk how to translate this text that includes value.

  untilEventDay =
                      '${pDate.difference(DateTime.now()).inDays},days/ until event day'
                          .tr;

in translation page :

,days/ until next event day': 'ڕؤژ ماوه‌/ تاوه‌كو ئیڤێنتی داهاتوو',

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you should separate the value’s string from your translation

var eventDayCountDownTitle = '${pDate.difference(DateTime.now()).inDays}' + ',' + days/ until event day'.tr;

and if you need your day number to be in a specific language, you can use a map or a helper method. map solution would be something like this:

Map<String,String> englishToPersianNumber = {'1' : '۱'}

and then use it in your string :

englishToPersianNumber[pDate.difference(DateTime.now()).inDays.toString()]

Important: to have a cleaner code, you can create a helper method to generate your desired string, and call it in your text widget. the code would be more understandable that way. Also, you can add handle any conditions that may later be added to the string generator. like if it’s the last day, write something else instead of 0 days remaining.

    String eventDayCountDownTitle(int remainingDays) {
if(remainingDays == 0) return "Less than One day to the event".tr;
    return '${remainingDays.toString}' + ',' + 'days/ until event day'.tr;
    }

ps. your question’s title is wrong, you should change it to what you’re explaining in the caption

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading