Commit Graph

14 Commits

Author SHA1 Message Date
Jim Warner
c465dca573 top: adapt 'locate/find next' search capability for nls 2011-12-22 23:48:06 +11:00
Jim Warner
db88a8d242 top: streamlined creation of nls string tables
The gettext documentation leads one to believe that
a printf type call is necessary for gettext string
extraction.  That turns out to be misleading and
all one really needs is the runtime gettext string
address resolution.

Thus, we can avoid our original snprintf/strdup
overhead and establish an address for the original
or translated string just by issuing the _() macro.

We create these nls string tables so that:
  1) top avoids the overhead of repeated
     runtime function calls
  2) we can control the order of top's
     strings in the .pot file
  3) translator comments don't obscure
     and clutter the main program
2011-12-22 23:48:05 +11:00
Jim Warner
7c4014f881 top: corrected typos and clarified 'Translation' notes 2011-12-22 23:48:05 +11:00
Jim Warner
3e6d1c4ee0 top: added <stdlib.h> for VALIDATE_NLS which requires exit() 2011-12-22 23:48:05 +11:00
Jim Warner
04e3ec75dd top: idiot! sometimes nls was misspelled nsl (but not anymore) 2011-12-22 23:48:05 +11:00
Jim Warner
bc441a67ea top: added additional xgettext strings plus translator hints 2011-12-22 23:48:05 +11:00
Jim Warner
de3ed5bff8 top: adapted/generalized comments for Makevars --add-comments= 2011-12-22 23:48:05 +11:00
Jim Warner
67034a9a4a top: finalized nls translation implementation 2011-12-22 23:48:05 +11:00
Jim Warner
acd73a1365 top: provided for nls table integrity validation 2011-12-22 23:48:05 +11:00
Jim Warner
da35f4a364 top: tweaked some xgettext emitted comments 2011-12-22 23:48:04 +11:00
Jim Warner
617d46633e top: redesign Uniq_nlstab/show_special (nls quirks)
Until this patch, top had used some strings with
special escape sequences to produce colors, normal
text, bold text, etc.  They took the following form,
explained by an excerpt from program comments:
  ...
  Our special formatting consists of:
     "some text <_delimiter_> some more text <_delimiter_>...\n"
  Where <_delimiter_> is a single byte in the range of:
     \001 through \010  (in decimalizee, 1 - 8)
  and is used to select an 'attribute' from a capabilities table
  which is then applied to the *preceding* substring.
  ...

Unfortunately, these nonprinting values revealed
insurmountable inconsistencies in both the front-end
and back-end translation tools.

The xgettext (extraction) program would take those
special escapes, convert them and then output raw
binary values.  Thus the .pot file would contain
lots of unprintable stuff making it unreadable.

If the following was added to po/Makevars, most of
those special escapes would be preserved in their
escape notation:
  XGETTEXT_OPTIONS = ... --escape
But two escapes were converted from octal notation
and there was no way to prevent it:
  \007  -->  \a
  \010  -->  \b

After a pass through the msginit program, most of
the escapes were reconverted to raw binary values
making translation impossible.  There was no
"--escape" option for the back-end programs like
there was for xgettext.

But the real killer was the escape \004, also used
in some of top's special strings.  This value would
be silently accepted by xgettext, only to produce
the following fatal error in back-end programs like
msginit, msgfmt and msgen:
  .pot:2647: context separator <EOT> within string

To quote from one of the references below:
  "Would you create a suite of tools that silently
   allow what is destined to become a fatal error
   to pass unnoticed?"

So the bottom line was: top's special strings, in
use for the past nine years, had to be redesigned.

References:
http://www.freelists.org/post/procps/procpsng-nls-support,11
http://www.freelists.org/post/procps/procpsng-nls-support,14
2011-12-22 23:48:04 +11:00
Jim Warner
5826ce4c6e top: relocated nls.h from top_nls.h to top_nls.c 2011-12-22 23:48:04 +11:00
Jim Warner
3f7468082a top: finalized top nls support (or so he thought)
summary of changes:
. adopted relative paths to 'include' and 'proc'
  dirs so that stand alone compiles are made
  easier and no one need guess their locations

. corrected several names for enums and macro
  usage reflecting fmt vs. txt

. expanded all octal escape sequences to a full
  3 digits since one already required 3 digits

. finalized translator hints (for now)

programming note:
  as an aside, by not including an argument for
  the gettext --add-comments, any preceeding c
  style comment will be propagated to the .pot
  file, if the gettext macro isn't empty.

  /* Need Not Say 'TRANSLATORS' ...
  snprintf(buf, sizeof(buf), "%s", _(   // unseen
  /* Translator Hint: ...
  snprintf(buf, sizeof(buf), "%s", _("" // seen
2011-12-22 23:48:04 +11:00
Jim Warner
32a9adbc13 top: provide extensive, generalized nls support
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2011-12-22 23:48:04 +11:00