Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.misc > #2031
| From | "James Harris" <james.harris.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.misc |
| Subject | Issuing a message in the language of the user |
| Date | 2014-04-27 20:29 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <ljjlr6$4ok$1@dont-email.me> (permalink) |
I was going to add this to the existing thread about formatting numbers as it is related but it is really a topic in itself so am posting separately. I will focus on expressing this in C terms and will use C in the examples. The idea is that a program wants to issue a message to a user (using a function which for the sake of giving it a name in this post I will call IssueMsg) but doesn't want to have to know what language the user speaks or what other locale settings are in effect. The message should appear in English to an English speaker, French to a French speaker etc. The IssueMsg routine is to look up the message in a library of the appropriate language for the user and then fill-in the parameter values supplied by the program. This is akin to gettext() but, of course, much better. ;-) Regarding the need for the order of values in a message to vary, a two-parameter message in English might have parm 1 first then parm 2 but the same message in French might be more naturally expressed by having parm 2 come before parm 1. Rather than forcing the same order on all languages the message needs to pick the parameter for each location. This means that the message text cannot just use them in order but needs to have numbered or named parameters. Numbered is more efficient and was chosen for the suggestion below. Therefore, to process the message there needs to be a table of parameters. A Posix extension to C's printf family apparently allows numbered parameters but I cannot see how that could be implemented easily using va_arg which is the only standard mechanism I am aware of in C for processing variable length argument lists. So, rather than the normal printf form printf(message, parms); the idea is for a program to send the message to a user by the following form of call IssueMsg(N, parms, message); N would state how many parms there were. The parms would normally be pairs of "formatting code", value but individual parms could be more complex if required as long as they were parseable. The message would be something that could be looked up in a library for the current human language. The message text, regardless of human language, would refer to numbered parameters from the table. In other words IssueMsg would build the table first. Then it would scan the message substituting the arguments at the appropriate points. In this way it would be easy, when processing the message, to refer back to numbered parameter entries in the table. Having the number of table entries first would allow the table to be allocated in one go by the IssueMsg routine. It could be malloced or could even be put on the stack as long as each entry is of fixed size. Where all this relates to the original thread is in the choice of "formatting code" elements. I won't bore you with what little I have done on that so far but it might be possible for both to use the same formatting code language. James
Back to comp.lang.misc | Previous | Next — Next in thread | Find similar | Unroll thread
Issuing a message in the language of the user "James Harris" <james.harris.1@gmail.com> - 2014-04-27 20:29 +0100
Re: Issuing a message in the language of the user "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-04-28 09:24 +0200
Re: Issuing a message in the language of the user "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-04-28 03:45 -0400
Re: Issuing a message in the language of the user "James Harris" <james.harris.1@gmail.com> - 2014-04-28 18:15 +0100
Re: Issuing a message in the language of the user "BartC" <bc@freeuk.com> - 2014-04-28 19:09 +0100
Re: Issuing a message in the language of the user "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-04-28 20:33 -0400
Re: Issuing a message in the language of the user "BartC" <bc@freeuk.com> - 2014-04-28 09:52 +0100
Re: Issuing a message in the language of the user "James Harris" <james.harris.1@gmail.com> - 2014-04-28 19:17 +0100
Re: Issuing a message in the language of the user "BartC" <bc@freeuk.com> - 2014-04-29 22:17 +0100
Re: Issuing a message in the language of the user "James Harris" <james.harris.1@gmail.com> - 2014-04-29 23:21 +0100
Re: Issuing a message in the language of the user George Neuner <gneuner2@comcast.net> - 2014-04-28 12:27 -0400
csiph-web