Android strings.xml 最佳实践?

发布于 2024-12-03 10:42:42 字数 1431 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

北方的韩爷 2024-12-10 10:42:42

我对此还是新手,所以我一直在寻找一个示例项目。 Astrid 在 Github 上是开源的,浏览项目 res 目录对于像我这样的新手来说是大开眼界。

好东西。看一下:

https://github.com/todoroo/astrid/tree/master/astrid/资源/值

I'm still new at this, so I was looking for an example project. Astrid is open source on Github, and looking through the projects res directory was eye opening for a newbie like me.

Good stuff. Take a look:

https://github.com/todoroo/astrid/tree/master/astrid/res/values

一念一轮回 2024-12-10 10:42:42

好问题。我也在为此苦苦挣扎。我的命名方案是:

1)UI元素:
如果一个字符串仅对应于一个 ui,我会根据控制元素和用途以及在控制元素的哪个部分使用它来命名它。示例:

button_helpText;
control : button, purpose: help, context: Text;

2) 一般要素:
如果在 UI 上使用字符串,但我想在另一个上下文中使用它,我只需保留前缀并添加后缀来更精确地描述目的/上下文。

helpMessageHeading;
purpose: help; context: a Message (abstract, could be a dialog), context_of_dialog: Heading; (the heading of a help dialog)
helpMessageText;
purpose: help, context: a Message (abstract, could be a dialog), context_of_dialog: Text; (the text inside a help dialog)
helpExplanation;
purpose: help; context_of_help: Explanation (just a explanation of the help topic)

3)订购:
我主要根据它们的上下文来排序这些字符串,因为它是您通常搜索的内容。

<!-- buttons -->
...
<!-- dialogs -->
...
<!-- general -->
...
<!-- explanations -->
...

等等。因此,我的列表通常在 UI 控件中分开,如果字符串未绑定到它,则它的一般精确上下文。为什么我要使用精确的上下文?当您搜索一个字符串来描述您所做的事情时,关于该字符串最独特的想法是它的精确上下文,因此这就是应该首先弹出的内容。但是,当您使用自动完成功能时,您通常会搜索一般描述。我认为这个结构是一个很好的解决方案。

我对其他答案很感兴趣。

Nice question. Im struggling with this too. My naming scheme is:

1) UI elements:
If a string only corresponds to a ui i name it accordingly to the control element and the purpose, as well as in which part of the control element it is used. example:

button_helpText;
control : button, purpose: help, context: Text;

2) General elements:
If a string is used on the UI but i want to use it in another context i just leave the prefix and add a postfix to describe the purpose / context mor precise.

helpMessageHeading;
purpose: help; context: a Message (abstract, could be a dialog), context_of_dialog: Heading; (the heading of a help dialog)
helpMessageText;
purpose: help, context: a Message (abstract, could be a dialog), context_of_dialog: Text; (the text inside a help dialog)
helpExplanation;
purpose: help; context_of_help: Explanation (just a explanation of the help topic)

3) Ordering:
I order those string mainly based on their context as it is what you normally search for.

<!-- buttons -->
...
<!-- dialogs -->
...
<!-- general -->
...
<!-- explanations -->
...

and so on. So my list is normally seperated in UI controls and, if a string is not bound to it, its general precise context. Why do i use the precise context ? when you search for a string to describe what you do the most unique idea about this string is its precise context, so thats what should pop up first. But when you use auto-completion you normally search for the general description. i think this structure is a fine solution.

I im very interested in other answers.

十六岁半 2024-12-10 10:42:42

检查约定的最佳位置很可能是在 Android SDK 示例中。以下是找到它们的方法 -http://developer.android.com/tools/samples/索引.html

The best place to check out conventions would most likely be within the Android SDK samples. Here's how you can find them -http://developer.android.com/tools/samples/index.html

知你几分 2024-12-10 10:42:42

如何保持翻译同步?您可以推荐哪些协作在线工具吗?

对我来说,最好的工具是 http://www.translatekarate.com

它是免费且协作的。

How to keep translations in sync? Are there collaborative online tools you can recommend?

For me, the best tool is http://www.translatekarate.com

It is free and collaborative.

峩卟喜欢 2024-12-10 10:42:42

如何保持翻译同步?有没有在线协作工具
可以推荐一下吗?

目前我正在使用这个协作工具 http://www.getlocalization.com/ 它让生活如果不使用专业功能,则更容易并且免费。

然后还有 https://crowdin.com/ ,它在我的观点是因为 ist 建议通过 google 和 bing 进行翻译,但最便宜的版本要花费 9 美元。

如何对strings.xml文件中的字符串进行排序?按字母顺序排列?分组
按活动? ...?

到目前为止,我还没有订购它们,因为我基本上不手动编辑 xml。
有一个插件可以让在 Eclipse 中处理多个翻译变得非常容易:Sequoyah 本地化编辑器

How to keep translations in sync? Are there collaborative online tools
you can recommend?

At the moment I'm using this collaborative tool http://www.getlocalization.com/ which makes life a lot more easier and is free if using no pro features.

Then there is also https://crowdin.com/ which is a bit better in my opinion becuse ist proposes translations by google and bing but costs 9$ in the cheapest variant.

How to order the string in the strings.xml file? Alphabetical? Grouped
by Activity? ...?

Up to now, I didn't order them because I mostly don't edit my xml by hand.
There is a plugin which makes handling multiple translations in eclipse very easy: Sequoyah localization Editor

情仇皆在手 2024-12-10 10:42:42

如何保持翻译同步?您可以推荐哪些协作在线工具吗?

我使用项目管理工具 https://poeditor.com 来翻译 XML 文件并保持它们同步。

How to keep translations in sync? Are there collaborative online tools you can recommend?

I use the project management tool https://poeditor.com to translate XML files and keep them in sync.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文