本文介绍了Flutter国际化-动态字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用intl包将我的应用翻译成西班牙语.

I'm translating my app to spanish using the intl package.

locales.dart

locales.dart

class AppLocale {
...
   String get folder => Intl.message("Folder", name: 'folder');
...
}

messages_es.dart

messages_es.dart

class MessageLookup extends MessageLookupByLibrary {
      get localeName => 'es';

      final messages = _notInlinedMessages(_notInlinedMessages);
      static _notInlinedMessages(_) => <String, Function> {
            "folder": MessageLookupByLibrary.simpleMessage("Carpeta"),
      };
}

我用以下代码称呼它:

AppLocale.of(context).folder

工作正常.

但是,我需要创建动态"字符串.例如:

However, I need to create "dynamic" strings. For example:

{$ name}"

然后,我将调用此字符串,并将此名称"作为参数或类似的名称传递.西班牙语将其翻译为"Hola,{$ name}".

Then I would call this string, passing this "name" as parameter, or something like this. It would be translate as "Hola, {$name}" in spanish.

可以使用此intl软件包吗?

It is possible using this intl package?

推荐答案

intl程序包的自述文件说明了该示例 https://github.com/dart-lang/intl

The README of the intl package explains that examplehttps://github.com/dart-lang/intl

greetingMessage(name) => Intl.message(
      "Hello $name!",
      name: "greetingMessage",
      args: [name],
      desc: "Greet the user as they first open the application",
      examples: const {'name': "Emily"});
  print(greetingMessage('Dan'));

在本节下面,有更复杂的示例被解释,它们也处理复数形式和性别.

Below this section there are more complex examples explained that also deal with plurals and genders.

这篇关于Flutter国际化-动态字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 11:57