组织的strings.xml [英] Organizing Strings.xml

查看:179
本文介绍了组织的strings.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个Android应用程序,因为我刚开始我想尝试获得最有组织code /资源。在我的strings.xml文件,到目前为止,我有这样的:

I'm making an android app and since I've just started I want to try get the most organised code/resources. In my strings.xml file so far I have this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="stop">Stop</string>
<string name="start">Start</string>
<string name="preferences">Preferences</string>
<string name="back">Back</string>
</resources>

除外APP_NAME在选项菜单中使用的字符串。但自从我将加入更多的字符串,我在想,这可能是更好的做这样的事情:

All of the strings except app_name are used in an options menu. But since I will be adding much more strings I was thinking that it might be better to do something like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>

这是不是最好的方式还是应该使用另一个系统?

Is it the best way or should I use another system?

推荐答案

这取决于那里的字符串将被使用。如果停止永远不会被任何地方,但在菜单中使用,称之为menu_stop是个好主意。如果它会使用所有的地方,那么它应该只是叫停。

It depends on where the strings will be used. If "stop" will never be used anywhere but in a menu, calling it "menu_stop" is a good idea. If it'll be used all over the place then it should just be called "stop".

另外,XML注释是组织资源非常有用的。

Also, XML comments are very useful for organizing resources.

<resources>
    <string name="app_name">GameController</string>

    <!-- Menu Strings -->
    <string name="menu_stop">Stop</string>
    <string name="menu_start">Start</string>
    <string name="menu_preferences">Preferences</string>
    <string name="menu_back">Back</string>
</resources>

最后,如果你发现你有吨,吨字符串资源,你可能想那么远,他们分成不同的XML文件中去。menu_strings.xml,dialog_strings.xml等

Finally, if you find you have tons and tons of string resources you may want to go so far as to separate them into different xml files: menu_strings.xml, dialog_strings.xml, etc.

<resources>
    <!-- Menu Strings -->
    <string name="menu_stop">Stop</string>
    <string name="menu_start">Start</string>
    <string name="menu_preferences">Preferences</string>
    <string name="menu_back">Back</string>
</resources>

dialog_strings.xml

<resources>
    <string name="dialog_cancel_yes">Yes, cancel.</string>
    <string name="dialog_cancel_no">No, do not cancel.</string>
</resources>

这篇关于组织的strings.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆