Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.misc > #2049

Re: Issuing a message in the language of the user

From "Rod Pemberton" <dont_use_email@xnothavet.cqm>
Newsgroups comp.lang.misc
Subject Re: Issuing a message in the language of the user
Date 2014-04-28 20:33 -0400
Organization Aioe.org NNTP Server
Message-ID <op.xe1yip0q6zenlw@localhost> (permalink)
References <ljjlr6$4ok$1@dont-email.me> <op.xe0nt7y86zenlw@localhost> <ljm2c8$5tn$1@dont-email.me>

Show all headers | View raw


On Mon, 28 Apr 2014 13:15:55 -0400, James Harris  
<james.harris.1@gmail.com> wrote:
> "Rod Pemberton" <dont_use_email@xnothavet.cqm> wrote in message
> news:op.xe0nt7y86zenlw@localhost...
>> On Sun, 27 Apr 2014 15:29:42 -0400, James Harris
>> <james.harris.1@gmail.com> wrote:

>>> [snip]
>>>
>>> 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.
>>>
>>> [snip]
>>
>> Is there a reason each message needs to have values?
>>
>> I.e., my inclination would be to have static strings for each
>> language selectable by index and pointer.  The pointer would
>> be set for the chosen language to select the appropriate array
>> of strings.  I would avoid emitting values, or I'd emit them on
>> a line without other text and without language specific formatting.
>
> Some messages might not have values. They could be issued as normal but  
> with
> no parameters. But some messages would need parameters. For example.
>
>   your account balance is 10.62 CR
>   you last logged in from IP address 10.1.1.4 on 5/5/2014
>   syntax error on line 20 near column 8 expected one of ",", ";", "(".
>

I suspect you're going to end up with many large arrays of pointers to
functions.  One array set for each language with each array containing
function pointers for each type of formatting routine you need.  Set
the pointer to the appropriate array for the language, index, call
function pointer.  This generates messy code, but keeps all the
functions, or strings as mentioned earlier, under control, in one place.

The other option is to call one function for each formatting task,
so the code is clean, no indexing, no pointers, no calling function
pointers, etc.  But, then each format function needs to be "smart",
perhaps using a switch to select code for each language.


Rod Pemberton

Back to comp.lang.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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