Android本地化變量中的簡單拼寫錯誤(例如%1d
而不是%1$d
在strings.xml
中)可能會導致crash。檢查Android strings.xml變量的工具?
我們無法進行徹底的測試(很多屏幕,一些很少顯示,幾十種語言,頻繁發佈,沒有收入),所以我們必須找到一個更智能的方法。這些錯誤在Eclipse中沒有顯示,實際上我正在尋找一個非可視化工具,以便它可以被我們的自動發佈工具調用。
我寫了下面的腳本來檢查本地化文件:
#! /bin/sh
# Spot malformed string replacement patterns in Android localization files.
grep -R "%1$ s" values*
grep -R "%1$ d" values*
grep -R '%' values* |
sed -e 's/%/\n%/g' | # Split lines that contain several expressions
grep '%' | # Filter out lines that do not contain expressions
grep -v ' % ' | # Lone % character, not a variable
grep -v '%<' | # Same, at the end of the string
grep -v '% ' | # Same, at the beginning of the string
grep -v '%で' | # Same, no spaces in Japanese
grep -v '%s' | # Single string variable
grep -v '%d' | # Single decimal variable
grep -v '%[0-9][0-9]\?$s' | # Multiple string variable
grep -v '%[0-9][0-9]\?$d' | # Multiple decimal variable
grep -v '%1$.1f' | # ?
grep -v '%.1f'
grep -R '%' values*
的問題:它fails趕在阿拉伯語本地化文件的問題。
問題:不是重新發明輪子,有沒有這種驗證工具? (不是Eclipse)
如果不是:我忘了什麼檢查?
我沒有意識到這個問題,但它聽起來像是應該由ADT中的Lint工具修復的東西。也許你應該問[Tor Norbye](https://plus.google.com/u/0/116539451797396019960/posts)。 – 2012-03-05 10:10:38
@DavidCaunt:謝謝!我向林特提交了一個增強請求:http://code.google.com/p/android/issues/detail?id=26434 – 2012-03-05 11:31:19
@DavidCaunt:看起來像ADT 17將是解決方案,當發佈時:-)能否請您讓你的評論成爲答案,以便我可以接受它? – 2012-03-09 09:37:23