很多时候,当生成要显示给用户的消息时,该消息将包含一些我想告知客户的东西.
Many times, when generating messages to show to the user, the message will contain a number of something that I want to inform the customer about.
我举个例子:客户从 1 起选择了多个项目,并单击了删除.现在我想给客户一个确认信息,我想提一下他选择的项目数量,以通过选择一堆项目并在他只想删除其中一个时单击删除来最大程度地减少他出错的机会他们.
I'll give an example: The customer has selected a number of items from 1 and up, and has clicked delete. Now I want to give a confirmation message to the customer, and I want to mention the number of items he has selected to minimize the chance of him making a mistake by selecting a bunch of items and clicking delete when he only wants to delete one of them.
一种方法是制作这样的通用消息:
One way is to make the generic message like this:
int noofitemsselected = SomeFunction();
string message = "You have selected " + noofitemsselected + " item(s). Are you sure you want to delete it/them?";
这里的问题"是 noofitemselected
为 1 的情况,我们必须写 item 和 it 而不是 项目和他们.
The "problem" here is the case where noofitemselected
is 1, and we have to write item and it instead of items and them.
我的正常解决方案是这样的
My normal solution will be something like this
int noofitemsselected = SomeFunction();
string message = "You have selected " + noofitemsselected + " " + (noofitemsselected==1?"item" : "items") + ". Are you sure you want to delete " + (noofitemsselected==1?"it" : "them") + "?";
如果代码中有很多对数字复数的引用,那么这会变得很长而且非常快,而且实际的消息很难阅读.
This gets quite long and quite nasty really fast if there are many references to the numbers plurality inside the code, and the actual message gets hard to read.
所以我的问题很简单.有没有更好的方法来生成这样的消息?
So my questions is simply. Are there any better ways of generating messages like this?
编辑
我看到很多人对我提到消息应该显示在消息框内的情况非常感兴趣,并且只是简单地给出了如何完全避免使用消息框的答案,并且都很好.
I see a lot of persons has got very hung up in the case that I mentioned that the message should be displayed inside a message box, and has simply given an answer of how to avoid using the message box at all, and that is all good.
但请记住,除消息框外,复数化问题也适用于程序中其他地方的文本.例如,显示在网格中选择的行数的网格旁边的标签将在复数方面存在相同的问题.
But remember that the problem of pluralization also apply to texts other places in the program in addition to message boxes. For example, a label alongside a grid displaying the number of lines selected in the grid will have the same problem regarding pluralization.
所以这基本上适用于大多数从程序以某种方式输出的文本,然后解决方案并不像仅仅将程序更改为不再输出文本那么简单:)
So this basically apply to most text that is outputted in some way from programs, and then the solution is not as simple as to just change the program to not output text anymore :)
如果有任何机会,无论多么小,这个应用程序都需要翻译成其他语言,那么两者都是错误的.正确的做法是:
If there is ever any chance, no matter how small, that this app will need to be translated to other languages then both are wrong. The correct way of doing this is:
string message = ( noofitemsselected==1 ?
"You have selected " + noofitemsselected + " item. Are you sure you want to delete it?":
"You have selected " + noofitemsselected + " items. Are you sure you want to delete them?"
);
这是因为不同的语言处理复数的方式不同.有些像马来语甚至没有语法复数,所以字符串通常是相同的.将这两个字符串分开可以更容易地在以后支持其他语言.
This is because different languages handle plurality differently. Some like Malay don't even have syntactic plurals so the strings would generally be identical. Separating the two strings makes it easier to support other languages later on.
否则,如果此应用程序旨在供公众使用并且应该对用户友好,那么第二种方法更可取.抱歉,我真的不知道更短的方法.
Otherwise if this app is meant to be consumed by the general public and is supposed to be user friendly then the second method is preferable. Sorry but I don't really know a shorter way of doing this.
如果此应用仅供贵公司内部使用,请执行快捷方式 "item(s)"
操作.在编写企业代码时,您实际上不必给任何人留下深刻印象.但我建议不要对公开消费的应用程序这样做,因为这给人的印象是程序员很懒惰,从而降低了他们对应用程序质量的看法.相信我,像这样的小事.
If this app is meant to be consumed only internally by your company then do the shortcut "item(s)"
thing. You don't really have to impress anybody when writing enterprisy code. But I'd advise against doing this for publicly consumed app because this gives the impression that the programmer is lazy and thus lower their opinion of the quality of the app. Trust me, small things like this matter.
这篇关于用户消息中的多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!