1
我阅读了intl库的API文档,但我真的不知道Intl类可以帮助我们什么。Dart的国际图书馆是什么?
起初,我一直认为库就像Java中的ResourceBundle类。
但现在,我不能肯定地说...
什么时候应该使用intl库? 还是有关于图书馆的任何好的样本?
我阅读了intl库的API文档,但我真的不知道Intl类可以帮助我们什么。Dart的国际图书馆是什么?
起初,我一直认为库就像Java中的ResourceBundle类。
但现在,我不能肯定地说...
什么时候应该使用intl库? 还是有关于图书馆的任何好的样本?
查看源代码中的intl example。
从例如评论:
这定义邮件在英语语言环境,直接在程序 并具有定义说或多或少同样的事情,德国和泰国的消息 单独的库,并打印消息与 其中的日期和时间格式适当的语言环境。
德国文件定义了runAt
消息,其中有两个参数:time
和day
runAt(time, day) =>
Intl.message('Ausgedruckt am $time am $day.', name: 'runAt', args: [time, day]);
的basic_example.dart定义了默认,英文版
runAt(time, date) =>
Intl.message('Ran at $time on $day', name: 'runAt', args: [time, day]);
然后,您可以使用正确的当地:
var de = new Intl('de_DE');
Intl.withLocale(de.locale,() => runAt('10:00', 'Dienstag')).then(print);
// default (en_GB?) locale
Intl.withLocale(new Intl().locale,() => runAt('10:00', 'Tuesday')).then(print);
(print
是输出消息的默认print()
函数)。
感谢您的回答。 但是,我还不明白图书馆。 我尝试[intl示例](https://code.google.com/p/dart/source/browse/#svn%2Fbranches%2Fbleeding_edge%2Fdart%2Fpkg%2Fintl%2Fexample%2Fbasic),然后我得到一个错误下面。 'NoSuchMethodError:method not found:'then'' – TomochikaHara
它应该工作,并且在测试中您可以找到运行它的intl_message_basic_example_test.dart。除了允许消息替换之外,它还可以格式化日期和数字(日期现在工作,数字还没有真正起作用)。 –
它不起作用:( 请参阅[intl示例](https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/pkg/intl/example/basic/basic_example.dart ) basic_example.dart:第55行'runAt'函数返回一个字符串 函数引用被传递给'printForLocale'函数 在'printForLocale'中,函数'operation'被调用并返回String类没有'then'方法,所以我得到一个NoSuchMethodError。 我在检查模式下发现了另一个错误,所以我不敢相信这个例子。 – TomochikaHara