Re: [HACKERS] error messages not only English

Поиск
Список
Период
Сортировка
От Peter T Mount
Тема Re: [HACKERS] error messages not only English
Дата
Msg-id Pine.LNX.3.95.980526213449.3185B-100000@retep.org.uk
обсуждение исходный текст
Ответ на Re: [HACKERS] error messages not only English  (Peter T Mount <psqlhack@retep.org.uk>)
Список pgsql-hackers
Oh dear, even I'm answering myself now ;-)

On Tue, 26 May 1998, Peter T Mount wrote:

> On Tue, 26 May 1998, David Gould wrote:
>
> > Vadim writes:
> > > Andreas Zeugswetter wrote:
> > > >
> > > > Anyway, we are still missing the first step in this direction: enumerate ERROR messages.
> > >
> > > BTW, are error codes in standard ?
> >
> > Some are. There is also a format for standard severity levels etc.
> >
> > On the internationalized message topic, how about storing all the messages
> > in a text file. This file would be opened (but not read) at startup by each
> > backend (and the postmaster). To change languages, just open a different
> > file. ELOG would scan the message file to get the message text corresponding
> > to an errog code. Since reading a pre-opened text file does not depend on
> > much of the system working, it should work even in the catastrophic cases.
>
> Do you want me to post a brief outline on how Java does this? It uses
> plain text files to handle internationalized messages, and can handle
> regional dialects as well?

Here goes:

Java 1.1 introduced Internationalization using Resource Bundles. Now these
could be either custom classes, or defined using Property Files (which are
more like what what were looking at here).

Anyhow, this is a brief description on how this works. I'm not
suggesting this is the way to go, but presenting this here as
something to base this on.

First, a few files:

# The file colours.properties is the default bundle.
# As I'm British, I've made my own locale the default (re: Colour)
colours=Colours
colours.red=Red
colours.green=Green
colours.blue=Blue

# The file colours.en.US.properties overides the default locale.
# As you can see it overides only one resource, as the other
# defaults are fine for this locale
colours=Colors

# The file colours.fr.properties handles the French locale
colours=Couleurs
colours.red=Rouge
colours.green=Vert
colours.blue=Bleu

When searching for a property, it follows the following algorithm:

    basename_language_country_variant
    basename_language_country
    basename_language
    basename

Entries found first take precedence. Only the lowest level needs to have
every possible entry.

There is a downside to this scheme (as far as PostgreSQL is concerned), in
that we could have several files open, although error handling isn't
something that needs to be too fast.

Now for formatted messages:

In Java, this is handled by the MessageFormat class. It takes a static
string, and inserts into the correct places additional strings to form the
final message.

ie:

In English:    "Error at line {0} in file {1}."
In French:    "Erreur: {1}: {0}."

--
Peter T Mount peter@retep.org.uk or petermount@earthling.net
Main Homepage: http://www.retep.org.uk
************ Someday I may rebuild this signature completely ;-) ************
Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk


В списке pgsql-hackers по дате отправления:

Предыдущее
От: ocie@paracel.com
Дата:
Сообщение: Re: [HACKERS] Query cancel and OOB data
Следующее
От: Brett McCormick
Дата:
Сообщение: Re: [HACKERS] Query cancel and OOB data