Loosely related since you mention language files. If anyone can share a bit of experience with swipl and internationalization (e.g., interoperability with gettext), that would be very helpful.
It would not be a big deal to add an interface to gettext. Might be a good idea. The overall idea of message support is derived from Quintus and available as print_message/2 and friends. This idea is that a message is represented by a Prolog term that conveys the semantics, for example,
incomparable(apples, pears) Next, you define a rules that currently looks like
prolog:message(incomparable(X, Y)) --> [ 'Thou shalt not compare ~p with ~p!'-[X, Y] ].
Now Quintus implemented these DCG rules in a file per language. An application can at startup load the applicable file and we are done.
System messages are or SWI-Prolog all defined in
boot/messages.pl and many libraries define their own set of rules for specific messages that are (thus) loaded with the library.
I think we should refine this to be able to deal with multiple languages in the same executable. That allows for plugins/libraries to support multiple languages include multiple languages into an executable without difficult procedures at startup and have e.g. web servers talk to users in their own language while providing services to people with different languages.
One option might be to simply add a language code to the prolog:message rule, so we get
prolog:message(en, incomparable(X, Y)) --> [ 'Thou shalt not compare ~p with ~p!'-[X, Y] ].
Following the language identification rules we can now select the most applicable rule and have e.g., rules for en_GB and en_US while if there is no matching en_GB we fallback to just
Note that as these are multifile rules we can provide additional language files and load them on demand.
Does that make sense? It seems pretty trivial to add …
I’ve pushed some preliminary work to make print_message/2 language sensitive.
Attached is a demo file that illustrates how to use it and that makes the system talk a little Dutch You can use it by updating Prolog to the git version, download the file and run (at least on Linux, might also work on MacOS)
LANG=nl_NL.utf8 swipl nl.pl
nl.pl (3.3 KB)
Besides need for more documentation, the main issue seems that, at least if you want to create a Prolog system that talks another language, you want to reuse a lot of stuff from the system message translation. Not sure how to solve that. Possibly by putting part (most) of the actual translation into a normal user library?
If you want multilingual console applications this is now surely a lot easier. One of the other things I’m still struggling with is interpolating color sequences. It can be done, but it is rather tedious. Possibly we can use a simplified Markdown notation?
If you run it without the LANG setting you get the following:
$ swipl /tmp/nl.pl Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.1-DIRTY) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. CMake built from "/home/u2/tmp/swipl-devel/build.release" For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). 1 ?- hi | . FOUT: Unknown procedure: hi/0 (DWIM could not correct goal)
I figured it is because of :
user:message_property(error, tag('FOUT')). user:message_property(warning, tag('Waarschuwing')).
Is there a way to specify those tags apply only to nl language?