无法使用getx在颤动中使用value翻译文本

发布于 2025-02-12 23:58:36 字数 313 浏览 0 评论 0原文

问题在于文本的价值在文本前一天声明 因此,idk如何翻译包含值的文本。

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

在翻译页面中:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美煞众生 2025-02-19 23:58:36

您应该将值的字符串与翻译分开

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

,如果您需要使用特定语言的日常数字,则可以使用地图或辅助方法。地图解决方案将是这样的东西:

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

然后在字符串中使用它:

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

重要:要拥有一个清洁的代码,您可以创建一个辅助方法来生成所需的字符串,然后将其称为文本widtet 。这样的代码将更可以理解。 此外,您可以添加处理任何条件,这些条件以后可能会添加到字符串生成器中。就像是最后一天一样,写其他东西,而不是剩余0天。

    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。您的问题的标题是错误的,您应该将其更改为您在标题中的解释

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文