现在的位置: 首页 > 综合 > 正文

吐槽-android4高级编程(第三版)(中文版)之getQuantityString

2013年12月06日 ⁄ 综合 ⁄ 共 1372字 ⁄ 字号 评论关闭

前段时间从卓越亚马逊买了本android4高级编程(第三版),神级的快递第二天就到了。不过当哥看到原书那一刻就吐了一次血。纸张发黄不解释,好像要散了一样。明显地边的盗版货。真不知道这样的书,卓越是怎么发出来的。

不过好在书的内容不错,内容也够充实,有700多页。要仔细看完得看一阵呢。

不过哥确实是打算细看的。

书的内容确实没的说,充实得不像话,虽然名字叫高级编程,但是作者还是花了一章的时间来介绍开发环境的搭建,让我不禁返回封皮重新看了一眼,确认书命中确实有“高级编程”四个字。不是说没必要介绍环境搭建,但是烦请作者为我们要攒钱买房的屌丝们想一想,省一些纸我们买书的时候可以省些钱不是。

然后是正式的内容了。哥照着书做的第一个例子,就是复数资源的使用。按照做着的法子,加入资源

	<plurals name="unicornCount">
	    <item quantity="one">One unicorn</item>
	    <item quantity="other">%d unicorns</item>
	</plurals>

又在java中加入

String s = getResources().getQuantityString(R.plurals.unicornCount, 1, 1);
		Log.d(this.getClass().getName(), s);
		s = getResources().getQuantityString(R.plurals.unicornCount, 3, 3);
		Log.d(this.getClass().getName(), s);

可为什么在楼主的小米1s手机上运行Logcat上并没有显示One unicorn和3 unicorns而是两行3 unicorns啊。

百度之,谷歌之都没有这个问题的讨论,好像大家都没有这个问题。那就奇怪了。经过楼主对android sdk的阅读才发现,原来:Although historically called "quantity strings" (and still
called that in API), quantity strings should 
only be
used for plurals. It would be a mistake to use quantity strings to implement something like Gmail's "Inbox" versus "Inbox (12)" when there are unread messages, for example. It might seem convenient to use quantity strings instead of an 
if statement,
but it's important to note that some languages (such as Chinese) don't make these grammatical distinctions at all, so you'll always get the 
other string.

原来因为中文没有复数语法,所以当语言是中文时,将总是获得quantity为other的字符串。果不其然,楼主把手机的语言设置为英文就好使了。

呵呵。我只想说翻译组在翻译这本书为中文的时候,是不是也应该提醒一下中文读者这件事情呢。

既然都开了吐槽的头,楼主决定尽量发觉这本书的槽点,发泄对社会的不满。

抱歉!评论已关闭.