l18l
New Member
Posts: 44
|
Post by l18l on Mar 12, 2011 18:30:40 GMT 1
Hello to all, little demo for NNTL made in beta/bacon.bash on wary bash4
#./test2 How many ? (1 to 11) 2 There is/are 2 green bottle(s) There are 2 green bottles # ./test2 How many ? (1 to 11) 1 There is/are 1 green bottle(s) There is 1 green bottle #
Sorry, bacon -x ... did not produce a pot file. (marked in red color later) So it is English only for now. here is the source
REM test2 NNTL REM demo for gramatically correct plurals in some languages REM created 2011-03-12 by L18L
OPTION INTERNATIONAL TRUE SETENVIRON "OUTPUT_CHARSET", "UTF-8"
REM let user input an integer range 0 to 11 x = -1 WHILE x < 0 OR x > 11 INPUT "How many ? (1 to 11) ", x WEND
REM demo how it looks like without new function NNTL REM demo is good to show how a variable integer x can be used inside a message PRINT INTL(CONCAT$("There is/are ",STR$(x)," green bottle(s)"))
REM now the new bacon function NNTL (see: GNU ngettext) PRINT NNTL(CONCAT$("There is ",STR$(x)," green bottle"),CONCAT$("There are ",STR$(x)," green bottles"),x )
REM that's it! Thank you, Peter
|
|
|
Post by vovchik on Mar 12, 2011 19:36:33 GMT 1
Dear l18l ,
Very nice:)
With kind regards, vovchik
|
|
|
Post by barryk on Mar 13, 2011 11:07:19 GMT 1
Am I missing something here. It seems to me that it is not very nice, functionality is missing? I was looking at these references: www.gnu.org/software/hello/manual/gettext/Plural-forms.htmlwww.gnu.org/software/hello/manual/gettext/Translating-plural-forms.html#Translating-plural-formsIf NNTL is a frontend to ngettext, then shouldn't it's parameters be just like in the ngettext function. For example, C code: ngettext ("One file removed", "%d files removed", n) When you compile, a .pot file gets created with this in it: msgid "One file removed" msgid_plural "%d files removed" msgstr[0] "" msgstr[1] "" And you can edit it for your language, ex: msgid "One file removed" msgid_plural "%d files removed" msgstr[0] "%d slika uklonjenih" msgstr[1] "%d slika uklonjenih" msgstr[2] "%d slika uklonjenih" There are two points here: Firstly, the parameters of ngettext allow for automatic creation of the .pot file as per the above example. It seems that NNTL loses that capability? Second, compiling BaCon code with -x does not create a .pot file. Please do correct me if I have misunderstood something here. Regards, Barry
|
|
|
Post by Pjot on Mar 13, 2011 11:23:37 GMT 1
Hi Barry,
Indeed, this works for me:
OPTION INTERNATIONAL TRUE
x = 2
PRINT NNTL("one", "two", x), " ", x
Also compiling with the '-x' option does create a .pot file, which I can edit:
#: /tmp/intl2.bac.c:32 msgid "one" msgid_plural "two" msgstr[0] "" msgstr[1] ""
For the rest it works the same as with INTL.
BR, Peter
|
|
|
Post by barryk on Mar 13, 2011 12:20:20 GMT 1
Peter,
PROBLEM 1 Yes, your example does create a .pot file. However, the example given by L18L creates a .pot file but the text entry for the NNTL function is missing:
OPTION INTERNATIONAL TRUE SETENVIRON "OUTPUT_CHARSET", "UTF-8" PRINT INTL("hello world") PRINT INTL("some more text")
x=2 PRINT NNTL(CONCAT$("There is ",STR$(x)," green bottle"),CONCAT$("There are ",STR$(x)," green bottles"),x)
compile it with -x, the .pot file does not have eny entry for the green bottle text.
PROBLEM 2 As INTL and NNTL return strings, shouldn't they be named INTL$ and NNTL$?
PROBLEM 3 One main feature of the plural form of the text in the .po file is that is allows a numeric value to be inserted, as I gave in my example:
msgid "One file removed" msgid_plural "%d files removed" msgstr[0] "%d slika uklonjenih" msgstr[1] "%d slika uklonjenih"
When the ngettext is called with the %d parameter passed in, as in the example:
ngettext ("One file removed", "%d files removed", n)
Then in the plural case, what would print is (if n=2):
two slika uklonjenih
...NNTL cannot do this, or so it seems to me, but it is the main feature of ngettext.
Regards, Barry
|
|
|
Post by Pjot on Mar 13, 2011 12:51:35 GMT 1
Well, these problems come from the fact that we are mixing a C API wih BASIC.
For your issues:
(1) In a PM I told l18l to use STR$(), but mentioned also that I was not sure if this would work - didn't have the time to sort it out yesterday. So it does not work, because 'gettext' expects textual arguments and the generated C code will have the CONCAT in between. Therefore you must do it as follows:
PRINT NNTL("There is %d green bottle", "There are %d green bottles", x)
(2) Well observed! You are right, this will be changed to INTL$ and NNTL$. (Remember this is still a beta and I am finetuning other features also...) (3) So it can be done if you use the syntax mentioned at (1).
Thanks and regards Peter
|
|
|
Post by barryk on Mar 13, 2011 13:15:33 GMT 1
Peter, Thanks for the feedback. No, the %d does not work for me. My test program:
OPTION INTERNATIONAL TRUE SETENVIRON "OUTPUT_CHARSET", "UTF-8"
x=2 PRINT INTL("first msg here") PRINT NNTL("%d file deleted", "%d files deleted", x)
The '%d' itself prints, not the value. Regardless whether I have en locale without a translation file, or I do have a .mo translation file (setup correctly as described above).
Regards, Barry
|
|
|
Post by Pjot on Mar 13, 2011 14:14:25 GMT 1
Ah is that what you mean. In the same PM to l18l I said that one probably cannot use PRINT and NNTL in the same line... Therefore I proposed to workaround it with several lines of code, which is ugly, of course. Anyway this situation with NNTL can be written as follows: OPTION INTERNATIONAL TRUE
x = 2
PRINT x FORMAT NNTL("There is %ld green bottle\n", "There are %ld green bottles\n", x)
Now the code runs correclt and also a POT file is created. Still, this isn't very beautiful, but then again, looking at the C examples, those aren't examples of comprehensible code either Regards Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 13, 2011 14:21:29 GMT 1
Greenbottles example Apologize for having not been verbosely enough (though in troubleshooting area). I am going to mark in red my "Sorry, bacon -x ... did not produce a pot file" The problem seems to be on the way to be solved now
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 15, 2011 22:04:23 GMT 1
wow!!! problems are solved thanks Barry and Peter. vovchik, I have been starting reading your thread from the beginning and found the 99-bottles. However, my bottles are remembered from a song learned in my first English lessons at school long ago (no beer). bottle news, using FORMAT, not really new, but using variable$REM variable$ in INTL$ and NNTL$ OPTION INTERNATIONAL TRUE SETENVIRON "OUTPUT_CHARSET", "UTF-8"
LET number = 3 LET mycolor$ = "green" LET entity$ = "bottle" PRINT mycolor$,entity$ FORMAT INTL$("the %s %s is not very nice, do NOT use this.") REM English: 'green bottle' but French: 'bouteille vert' PRINT PRINT number,mycolor$ FORMAT NNTL$("you can use one %s bottle.","you can use %d %s bottles",number)
@barry, this time functionality should be ok. stuff for tutorial? just 1 %s and 1 %d can be used safely; edited later: forget next line, please. I was influenced too much by my experiences in shell's gettext.sh where eval_gettext is usedfor more than one %s / %d GNU eval_gettext / eval_ngettext would be needed. edited later for more than one %s / %d see 3 post later, pleaseThe pot file is #: test3.bac.c:41 #, c-format msgid "the %s %s is NOT very nice, do NOT use it."
It is absolutely not clear for translators what the msgid means (don't use it) @peter, is it possible to refer not to bac .c but to bac ?
|
|
|
Post by Pjot on Mar 16, 2011 3:54:53 GMT 1
No, I am afraid not, because the gettext utilities do not recognize BASIC syntax... Regards Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 16, 2011 7:33:26 GMT 1
No, I am afraid not, because the gettext utilities do not recognize BASIC syntax... Regards Peter Then I would suggest to leave it off by default; it is only wasting space and cannot be used by basic programmer nor translator.
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 16, 2011 14:05:48 GMT 1
back to my bottlesI think my problem is solved now using %n$s / %n$d where n is the position of argument Edited later: sorry, not solved. No pot file created. I was just looking at compiling without errors. My fault.
REM more variables and variable$ in INTL$ OPTION INTERNATIONAL TRUE SETENVIRON "OUTPUT_CHARSET", "UTF-8"
LET number = 3 LET mycolor$ = "green" LET entity$ = "bottle" PRINT "number = 3 mycolor$ = 'green' entity$ = 'bottle' count=3" PRINT "1 number and 2 strings: " PRINT entity$,number,mycolor$ FORMAT INTL$("Only %2$d deciliters free in '%1$s' which color is '%3$s'.") LET count = 2 PRINT PRINT "2 numbers and 1 string: " PRINT entity$,number,count FORMAT INTL$("Only %3$d deciliters free in %2$d-deciliters '%1$s' ")
behaves like exspected: # ./test4 number = 3 mycolor$ = 'green' entity$ = 'bottle' count=3 1 number and 2 strings: Only 3 deciliters free in 'bottle' which color is 'green'. 2 numbers and 1 string: Only 2 deciliters free in 3-deciliters 'bottle' # Anybody will be free to make adequate translations, I hope so.. And sorry again
|
|
|
Post by Pjot on Mar 16, 2011 18:43:29 GMT 1
Thanks l18l! I am sorry but I don't get this, you suggest to leave what off...? Regards Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 16, 2011 20:08:31 GMT 1
Thanks l18l! I am sorry but I don't get this, you suggest to leave what off...? Regards Peter Hello Peter, leave off in --add-location (saw this in xgettext --help) I was meaning the pot file should look like NOT: #: test3.bac.c:41 #, c-format msgid "the %s %s is NOT very nice, do NOT use it." msgstr "" but just: msgid "the %s %s is NOT very nice, do NOT use it." msgstr "" But the longer I think about I am coming to the conclusion that it might be useful, not the line number in (this example) test3.bac.c but the info that it is from test3.bac might be useful when several source files will be using one and the same TEXTDOMAIN. So forget this, please. Regards
|
|