Bug 529 - d_printf() cannot handle msg strings included variables
Summary: d_printf() cannot handle msg strings included variables
Status: CLOSED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: SWAT (show other bugs)
Version: 3.0.0
Hardware: All All
: P3 minor
Target Milestone: none
Assignee: Jeremy Allison
QA Contact:
URL:
Keywords:
Depends on:
Blocks: 413
  Show dependency treegraph
 
Reported: 2003-09-28 09:58 UTC by TAKAHASHI Motonobu
Modified: 2005-08-24 10:18 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description TAKAHASHI Motonobu 2003-09-28 09:58:11 UTC
Created as a seperated bug from BUG#413 

------- Additional Comment #5 From TAKAHASHI Motonobu 2003-09-22 19:11 ------- 
There are still some issues:

For example
 6a) d_printf(_("test %s messege\n"))  is working well but
 6b) d_printf("%s\n", _("test %s messege")) is not working.
 I modified the 6b) format to 6a) format.

 This is currently d_printf() limitation?

------- Additional Comment #7 From Tim Potter 2003-09-25 19:13 ------- 
Item IV) is a little tricky.  Due to the fact that the exact string in the
dprintf() function is used as an index to the language tdb, tricks like
d_printf("%s\n", _("test %s messege")) won't work as you point out.

For the i18n to work correctly you can't use a variable number of parameters to
d_printf() unless you are really careful.

For example the msgid string for the first d_printf() would be "<translation of
'test %s message'>\n" whereas what you want is a msgid like "test %s message". 
I.e the string within the _().

This breaks your second patch to update the calling _().  Commands like

d_printf("<input type=radio name=\"ViewMode\" value=0 %s>Basic\n", (mode == 0) ?
"checked" : "");

should become:

d_printf(_("<input type=radio name=\"ViewMode\" value=0 %s>Basic\n"), (mode ==
0) ? "checked" : "");

instead of:

d_printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", (mode == 0) ?
"checked" : "", _("Basic"));

Sorry.  )-:

------- Additional Comment #8 From Tim Potter 2003-09-25 23:52 ------- 
OK here is the status of this bug as I see it.  

  - Monyo's two patches need to be regenerated and applied.

------- Additional Comment #9 From TAKAHASHI Motonobu 2003-09-26 12:14 -------
About issue IV), assuming commands like

d_printf("<input type=radio name=\"ViewMode\" value=0 %s>Basic\n", (mode == 0) ?
"checked" : "");

the solutions are:

(1) Always writing like

d_printf(_("<input type=radio name=\"ViewMode\" value=0 %s>Basic\n"), (mode ==
0) ? "checked" : "");

This is an easy way but I do not like it because 
  1a) HTML strings are included in msg strings,
  1b) Simply ugly to look :-(
  1c) msg srings become longer and increased because for example "basic" 
and "<li>basic\n" are counted as different msgs.

(2) Writing like 

d_printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", (mode == 0) ?
"checked" : "", _("Basic"));

when possible and when valiable is included in msg string, writing like (3).

This can seperate the "essential" messege and HTML tags basically but 
there are 2 syntax for writing d_printf() depended on a variable is included or 
not.

(3) Always writing like

d_printf("<input type=radio name=\"ViewMode\" value=0 ", _("Basic"), ">%s\n", 
(mode == 0) ?
"checked" : "");

This is the most acceptable resolution I think.

How about (3)?

------- Additional Comment #11 From TAKAHASHI Motonobu 2003-09-28 01:53 ------- 
For IV), I mistook again. (3) in #comment_9 causes syntax error.

At last I want to modify:

If the msg strings do not contain variables, then writing like 
    d_printf("%s\n", _("test messege"));
If contain, then
  writing like
    d_printf(_("test %s messege"));
    d_printf("\n");

Of course this is NOT the best solution. But is acceptable.
Because
  the HTML tags are not included in msg files. 
  indeed there are few msg strings included variables.

If you are OK, I will re-generate the patch and msg files.

------- Additional Comment #12 From Tim Potter 2003-09-28 03:38 ------- 
Monyo, I will be happy to look at any patches you send.

------- Additional Comment From TAKAHASHI Motonobu ------- 
I will ask the Japanese guys how to fix this issue.
Please give me time.
Comment 1 TAKAHASHI Motonobu 2003-10-02 11:55:08 UTC
At last I modify:

If the msg strings do not contain variables, then writing like 
    d_printf("%s\n", _("test messege"));
If contain, then
  writing like
    d_printf(_("test %s messege"));
    d_printf("\n");

The patch is attached at BUG#413.
Comment 2 John H Terpstra (mail address dead( 2003-10-18 10:59:57 UTC
Jeremy,

Would you please check this one and the patches Monyo has provided.
Thanks.

- John T.
Comment 3 TAKAHASHI Motonobu 2003-10-19 06:46:49 UTC
This patch is already applied by tpot on the 3rd, Oct.

-----
Moving towards better i18n support in SWAT.  This commit contains a
bunch of updates to bug 413 from Monyo:

1) pick up proper strings to call msg strings for example to add
  strings in wizard menu in web/swat.c, web/statuspage.c and
  param/loadparm.c.

2) define N_() macro in include/intl.h to pick up some strings
  in param/loadparm.c

3) quote all name and value tag with '"'
  For example in swat.c:720 the "Edit Parameter Values" string is
  displayd only as "Edit" because value tag is not quoted like:
  value=Edit Parameter Values
  These tags should be quoted though it sometimes works well
  without quotation.

4) modify the msg strings not to contain HTML tags or other
  non-message strings. For example
  dprintf(_("test\n")); is modified to dprintf("%s\n", _("test"));

Revisions:
swat.c          1.79.2.23 => 1.79.2.24
        http://www.samba.org/cgi-bin/cvsweb/samba/source/web/swat.c.diff?r1=1.7\
9.2.23&r2=1.79.2.24
statuspage.c            1.29.2.7 => 1.29.2.8
        http://www.samba.org/cgi-bin/cvsweb/samba/source/web/statuspage.c.diff?\
r1=1.29.2.7&r2=1.29.2.8

Revisions:
loadparm.c              1.397.2.103 => 1.397.2.104
        http://www.samba.org/cgi-bin/cvsweb/samba/source/param/loadparm.c.diff?\
r1=1.397.2.103&r2=1.397.2.104

Revisions:
intl.h          1.2 => 1.2.2.1
        http://www.samba.org/cgi-bin/cvsweb/samba/source/include/intl.h.diff?r1\
=1.2&r2=1.2.2.1
Comment 4 Tim Potter 2003-11-05 10:34:06 UTC
Monyo says this is fixed.
Comment 5 Gerald (Jerry) Carter (dead mail address) 2005-08-24 10:18:10 UTC
sorry for the same, cleaning up the database to prevent unecessary reopens of bugs.