xref: /freebsd/contrib/nvi/catalog/README (revision 110d525ec6188f3c9dc4f54c4bc1cced2f7184cd)
1b8ba871bSPeter WemmGenerally, all non-system error and informational messages in nvi are
2b8ba871bSPeter Wemmcatalog messages, i.e. they can be tailored to a specific langauge.
3*f0957ccaSPeter WemmCommand strings, usage strings, system errors and other 'known text'
4*f0957ccaSPeter Wemmare not.
5b8ba871bSPeter Wemm
6b8ba871bSPeter WemmMessage catalogs in nvi are fairly simple.  Every catalog message
7b8ba871bSPeter Wemmconsists of two parts -- an initial number followed by a pipe (`|')
8b8ba871bSPeter Wemmcharacter, followed by the English text for the message.  For example:
9b8ba871bSPeter Wemm
10b8ba871bSPeter Wemm	msgq(sp, M_ERR, "001|This is an error message");
11b8ba871bSPeter Wemm
12b8ba871bSPeter Wemmwould be a typical message.
13b8ba871bSPeter Wemm
14b8ba871bSPeter WemmWhen the msgq() routine is called, if the user has specified a message
15b8ba871bSPeter Wemmcatalog and the format string (the third argument) has a leading number,
16b8ba871bSPeter Wemmthen it is converted to a record number, and that record is retrieved
17b8ba871bSPeter Wemmfrom the message catalog and used as a replacement format string.  If
18b8ba871bSPeter Wemmthe record can't be retrieved for any reason, the English text is displayed
19b8ba871bSPeter Wemminstead.
20b8ba871bSPeter Wemm
21b8ba871bSPeter WemmEach message format string MUST map into the English format string, i.e.
22b8ba871bSPeter Wemmit can't display more or different arguments than the English one.
23b8ba871bSPeter Wemm
24b8ba871bSPeter WemmFor example:
25b8ba871bSPeter Wemm
26b8ba871bSPeter Wemm	msgq(sp, M_ERR, "002|Error: %d %x", arg1, arg2);
27b8ba871bSPeter Wemm
28*f0957ccaSPeter Wemmis a format string that displays two arguments.
29b8ba871bSPeter Wemm
30b8ba871bSPeter WemmArguments to the msgq function are required to contain ONLY printable
31b8ba871bSPeter Wemmcharacters.  No further translation is done by the msgq routine before
32b8ba871bSPeter Wemmdisplaying the message on the screen.  For example, in the msgq call:
33b8ba871bSPeter Wemm
34b8ba871bSPeter Wemm	msgq(sp, M_ERR, "003|File: %s", file_name);
35b8ba871bSPeter Wemm
36b8ba871bSPeter Wemm"file_name" must contain only printable characters.  The routine
37*f0957ccaSPeter Wemmmsg_print() returns a printable version of a string; the third argument
38*f0957ccaSPeter Wemmindicates whether the string needs to be freed.  For example:
39b8ba871bSPeter Wemm
40b8ba871bSPeter Wemm	char *p;
41*f0957ccaSPeter Wemm	int nf;
42b8ba871bSPeter Wemm
43*f0957ccaSPeter Wemm	p = msg_print(sp, file_name, &nf);
44*f0957ccaSPeter Wemm	msgq(sp, M_ERR, "003|File: %s", p);
45*f0957ccaSPeter Wemm	if (nf)
46b8ba871bSPeter Wemm		FREE_SPACE(sp, p, 0);
47b8ba871bSPeter Wemm
48b8ba871bSPeter Wemmmakes sure that "file_name" is printable before calling the msgq
49b8ba871bSPeter Wemmroutine.
50b8ba871bSPeter Wemm
51b8ba871bSPeter Wemm=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
52b8ba871bSPeter Wemm
53b8ba871bSPeter WemmThe message catalogs themselves are maintained in two files.  The first
54b8ba871bSPeter Wemmis the "base file" which contains two fields, a record number and the
55b8ba871bSPeter Wemmmessage itself.  All base files are named using the convention
56*f0957ccaSPeter Wemm"<language>.base", e.g. the English one is "english.base".  For
57b8ba871bSPeter Wemmexample:
58b8ba871bSPeter Wemm
59*f0957ccaSPeter Wemm	002 "Line length overflow"
60*f0957ccaSPeter Wemm	003 "unable to delete line %lu"
61*f0957ccaSPeter Wemm	004 "unable to append to line %lu"
62*f0957ccaSPeter Wemm	005 "unable to insert at line %lu"
63*f0957ccaSPeter Wemm	006 "unable to store line %lu"
64*f0957ccaSPeter Wemm	007 "unable to get last line"
65b8ba871bSPeter Wemm
66*f0957ccaSPeter Wemmare the first few lines of the current english.base file.
67b8ba871bSPeter Wemm
68*f0957ccaSPeter WemmBefore this file being converted to the second file, the POSIX formatted
69*f0957ccaSPeter Wemmmessage catalog file, by gencat(1), two lines:
70b8ba871bSPeter Wemm
71*f0957ccaSPeter Wemm	$set 1
72*f0957ccaSPeter Wemm	$quote "
73b8ba871bSPeter Wemm
74*f0957ccaSPeter Wemmwill be inserted before the base text to setup the set_id and the quote
75*f0957ccaSPeter Wemmcharacter.  So the double-quote needs to be escaped by a backslash to be
76*f0957ccaSPeter Wemmincluded in a message; same as the backslash itself.
77b8ba871bSPeter Wemm
78*f0957ccaSPeter WemmThese files are named for their language, e.g. "english".  However, a
79*f0957ccaSPeter Wemmlocale(1) name is also recommended.
80b8ba871bSPeter Wemm
81b8ba871bSPeter WemmTo create a new catalog for nvi:
82b8ba871bSPeter Wemm
83*f0957ccaSPeter WemmCopy the file english.base to a file that you can modify , e.g.  "cp
84*f0957ccaSPeter Wemmenglish.base german.base".  For each of the messages in the file,
85*f0957ccaSPeter Wemmreplace the message with the string that you want to use.  If you have
86*f0957ccaSPeter Wemmdoubts about the meaning of a message, just email me.
87b8ba871bSPeter Wemm
88*f0957ccaSPeter WemmA latest english.base can be created from source by running the command
89*f0957ccaSPeter Wemm"make english" in the catalog/ directory.
90b8ba871bSPeter Wemm
91b8ba871bSPeter WemmOnce you've translated all of the strings, then add your catalog to the
92b8ba871bSPeter Wemm"CAT=" line of the Makefile, and run the command "make catalog".  This
93b8ba871bSPeter Wemmwill create the second (and corresponding) file for each file named
94b8ba871bSPeter Wemm<language>.base.
95b8ba871bSPeter Wemm
96b8ba871bSPeter WemmDon't worry about missing line numbers, i.e. base files that look like:
97b8ba871bSPeter Wemm
98b8ba871bSPeter Wemm	005	Message number 5.
99b8ba871bSPeter Wemm	007	Message number 7.
100b8ba871bSPeter Wemm
101b8ba871bSPeter WemmThis simply means that a message was deleted during the course of nvi's
102b8ba871bSPeter Wemmdevelopment.  It will be taken care of automatically when you create
103b8ba871bSPeter Wemmthe second form of the file.
104b8ba871bSPeter Wemm
105b8ba871bSPeter Wemm=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
106b8ba871bSPeter WemmIf you add new messages to the nvi sources, you can check your work by
107b8ba871bSPeter Wemmdoing "make english; make check".  The "make check" target lists unused
108b8ba871bSPeter Wemmmessage numbers, duplicate message numbers, and duplicate messages.
109b8ba871bSPeter WemmUnused message numbers are only useful if you are condensing messages.
110b8ba871bSPeter WemmDuplicate message numbers are a serious problem and have to be fixed.
111b8ba871bSPeter WemmDuplicate messages are only interesting if a message appears often enough
112b8ba871bSPeter Wemmthat it's worth creating a routine so that the string is only need in
113b8ba871bSPeter Wemma single place.
114b8ba871bSPeter Wemm
115b8ba871bSPeter Wemm=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
116b8ba871bSPeter WemmTo select a catalog when running nvi, set the "msgcat" option.  If the
117b8ba871bSPeter Wemmvalue of this option ends with a '/', it is treated as the name of a
118*f0957ccaSPeter Wemmdirectory that contains a message catalog "$LC_MESSAGES", which is set
119*f0957ccaSPeter Wemmthrough the LC_MESSAGES environment variable but returned by setlocale(3).
120*f0957ccaSPeter WemmCheck the output of locale(1) to validate such a value.  If the option
121*f0957ccaSPeter Wemmdoesn't end in a '/', the option is treated as the full path name of the
122*f0957ccaSPeter Wemmmessage catalog to use.
123b8ba871bSPeter Wemm
124b8ba871bSPeter WemmIf any messages are missing from the catalog, the backup text (English)
125b8ba871bSPeter Wemmis used instead.
126