Home > Blockchain >  cant translate text with value using GETX in flutter
cant translate text with value using GETX in flutter

Time:07-03

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': 'ڕؤژ ماوه‌/ تاوه‌كو ئیڤێنتی داهاتوو',

CodePudding user response:

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

  • Related