l18l
New Member
Posts: 44
|
Post by l18l on Mar 6, 2011 12:06:46 GMT 1
Hi, I am coming here from puppy and am interested in internationalisation.
I was trying to produce a simple 'hello world' but no success doing it in GUI.
in cli REM hello world international GUI REM L18L 2011-03-06 OPTION INTERNATIONAL 1 PRINT INTL("hello world") END it is working well. # bacon hello_international.bac Starting conversion... done. Starting compilation... done. Program 'hello_international' ready. # ./hello_international Hallo Welt But having just included INCLUDE "../hug.bac" it is # bacon hello_international.bac Starting conversion... done. Starting compilation... done. Program 'hello_international' ready. # ./hello_international hello world
So my questions is: How does internationalisation work with hug? Or am I missing something? Thanks in advance.
|
|
|
Post by Pjot on Mar 6, 2011 14:40:16 GMT 1
Gutentag,
The first line in the HUG INCLUDE is:
SETENVIRON "LANG", "C"
This sets your localization to the default "C" locale. I almost forgot why I have put this in there - it had to do with the SPIN widget which reads values as float values, and the problem with Dutch and German locale is that these use the dot '.' as a separator for thousands and the ',' as a separator for decimals, while in English locale this is the other way around.
Therefore to get the SPIN interpreting values correctly a neutral C locale had to be forced.
So for your problem, things might work if you surround the HUG include with two lines, for example:
var$ = GETENVIRON$("LANG") INCLUDE "hug.bac" SETENVIRON "LANG", var$
Herzliche Grüsse, Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 6, 2011 17:16:25 GMT 1
Hello Peter, thank you for the reply but the problem still exists. What I have so far is now
REM hello world international GUI REM L18L 2011-03-06
OPTION INTERNATIONAL 1 var$ = GETENVIRON$("LANG") PRINT var$ INCLUDE "../hug.bac" SETENVIRON "LANG", var$ PRINT INTL("hello world")
REM now the GUI mainwin = WINDOW("Hello World", 400, 285)
# bacon hello_international.bac Starting conversion... done. Starting compilation... done. Program 'hello_international' ready. # ./hello_international de_DE.UTF-8 hello world # GUI does not appear, but anyhow I think my "Hallo Welt" should appear first.
|
|
|
Post by Pjot on Mar 6, 2011 19:44:31 GMT 1
Well you are right. It appears that GTK not only checks the LANG variable, but also actively changes the locale based on LANG. So plainly restoring the LANG variable does not help.
I have to think about a structural solution. For now, you can work around this problem by adding 'setlocale' to your code.
For example:
REM hello world international GUI REM L18L 2011-03-06
OPTION INTERNATIONAL 1 var$ = GETENVIRON$("LANG") PRINT var$ INCLUDE "../hug.bac" SETENVIRON "LANG", var$
USEC setlocale(LC_ALL, var$); END USEC
PRINT INTL("hello world")
REM now the GUI mainwin = WINDOW("Hello World", 400, 285)
Regards Peter
|
|
|
Post by Pjot on Mar 6, 2011 20:03:09 GMT 1
So I have tested the PROGRESS and SPIN widget without the SETENVIRON setting, and on my Ubu it seems to be working. Values for SPIN can be set with values like 0.5, 10.7 and so on, even in my Dutch environment. Therefore I have removed the SETENVIRON line from the HUG include completely, please get the latest HUG 0.33. Greetings, Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 6, 2011 20:39:37 GMT 1
Success on my 1st step on internationalisation applied HUG 0.33 # bacon hello_international.bac Starting conversion... done. Starting compilation... done. Program 'hello_international' ready. # ./hello_international de_DE.UTF-8 Hallo Welt # is working correctly in Quickset Wary-502q, too Thank you, Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 7, 2011 20:11:34 GMT 1
Hello world, my 2nd step, hello world in GUI, succeeded: A small example, there are just 2 strings prepared for internationalisation: 'hello world' and 'OKAY'. Here is howto get languages other than English. hello.bac
REM hello world international REM L18L 2011-03-07 with a little help from Peter and ian
OPTION INTERNATIONAL 1 var$ = GETENVIRON$("LANG") INCLUDE "../hug.bac"
REM PRINT INTL("hello world")
mainwin = WINDOW("hello world", 200, 100) frame0 = FRAME(190,90) ATTACH(mainwin, frame0, 5, 5) label_mainw=MARK(INTL("hello world"),170,30) FONT(label_mainw,"DejaVu Sans 18") ATTACH(mainwin,label_mainw,20,25) ok_btn = BUTTON(INTL("OKAY"), 90, 30) ATTACH(mainwin, ok_btn, 108, 68)
DISPLAY
hello.pot generated by bacon -x hello.bac :
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: hello 0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2011-03-07 18:45+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n"#: hello.bac.c:325 msgid "OKAY" msgstr ""
#: hello.bac.c:319 msgid "hello world" msgstr ""
create your translation:
cp hello.pot hello-<language-code>.po edit <language-code>.po: fill the empty msgstr's (or leave blank e.g. if OKAY will be understood)
msgfmt hello-<language-code>.po -o - > /usr/share/locale/<language-code>/hello.mo launch hello and admire your translation
I hope this will help people who have never used internationalisation. (The OKAY button hasn't got any function yet) Cheers
|
|
|
Post by Pjot on Mar 7, 2011 22:45:50 GMT 1
Thanks,
So I have tested it, and it works. BTW your program also works without these lines:
SETENVIRON "LANG", var$
USEC setlocale(LC_ALL, var$); END USEC
So simply including "hug.bac" version 0.33 or later should be sufficient!
Best regards Peter
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 8, 2011 9:37:43 GMT 1
So I change the above code Thank you again Best regards
|
|
|
Post by barryk on Mar 8, 2011 11:38:36 GMT 1
L18L, Thanks for the little tutorial, very helpful!
I am repeating your first CLI example, and it is not working for me. I have LANG=en_US, not UTF8, which might be the problem.
My source:
REM hello world international GUI REM L18L 2011-03-06 OPTION INTERNATIONAL 1 PRINT INTL("hello world") PRINT INTL("some more text") END
Then I followed the steps:
# bacon -x test1.bac Starting conversion... done. Executing xgettext... done. Starting compilation... done. Program 'test1' ready. # msgfmt test1-en_US.po -o - > /usr/share/locale/en_US/test1.mo test1-en_US.po: warning: Charset "CHARSET" is not a portable encoding name. Message conversion to user's charset might not work.
My test1.pot, that I copied to test1-en_US.po:
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2011-03-08 18:32+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n"
#: test1.bac.c:32 msgid "hello world" msgstr "Hi Guys"
#: test1.bac.c:36 msgid "some more text" msgstr "yadda yadda"
...whereas your example has "charset=utf-8"
When I test it, there is no conversion.
|
|
|
Post by barryk on Mar 8, 2011 11:49:11 GMT 1
I changed my locale to en_US.utf8, but makes no difference, the .pot file still has "charset=CHARSET"
I manually edited test1-en_US.po, so "charset=utf-8", so when ran the msgfmt program there was no error message. However, it still doesn't work.
I'm using Wary Puppy 5.1.1.
|
|
l18l
New Member
Posts: 44
|
Post by l18l on Mar 8, 2011 15:51:33 GMT 1
barryk, thanks for testing :)
isn't finding bugs a good test result ? It was my fault having [b]not exactly[/b] described what has to be done :-[ [quote] hello.pot generated by [code]bacon -x hello.bac [/quote] was faulty. Should correctly become: __________________________________generate hello.pot by bacon -x hello.bac and edit hello.pot so that there is a valid charset, UTF-8 (required if worlwide usage is intended) _________________________________edited later: another fault was faulty, too. must be: _________________________________msgfmt hello-<language-code>.po -o - > /usr/share/locale/<language-code>/LC_MESSAGES/hello.mo _________________________________Note1, it is absolutely not necessary to define test1-en _US.po and test1-en.po. msgfmt test1-en.po -o - > /usr/share/locale/en/LC_MESSAGES/test1.mo will be sufficent. Note2, (not relevant for English language because it is all ASCII) need to test and find a solution for users having not enabled utf8 encoding. With puppy shell scripts it was shinobar who found the solution. removed [SOLVED] for now. @ Peter, could SYSTEM "export OUTPUT_CHARSET=UTF-8" be included in next HUG ? it works in barry's test OPTION INTERNATIONAL 1 SYSTEM "export OUTPUT_CHARSET=UTF-8" PRINT INTL("hello world") PRINT INTL("some more text") END # locale -a C de_DE de_DE.utf8 de-DE.utf8 en_US POSIX # echo $LANG de_DE # ./test1 Hi Guys yadda yadda äöüßÖÜÄ # LANG=en ./test1 hello world some more text # LANG=fr ./test1 hello world some more text # [/code] äöüß... with LANG=de_DE (without utf-8)
|
|
|
Post by Pjot on Mar 8, 2011 22:46:25 GMT 1
Folks, Reading through this thread, it seems a step is missing, which also solves the 'charset' problem. Let me show you how I do it. (1) Create a program and save it as 'hello.bac' OPTION INTERNATIONAL TRUE
PRINT INTL("Hello world")
(2) Run bacon with the '-x' option. This will create a template message file called 'hello.pot'. (3) So now the step I am missing: run msginit on the catalog template file, as follows: As you can see, I am using the nl_NL locale here, which is Dutch. It will create a genuine catalog file called 'nl.po' from the template 'hello.pot'. If you look into this file you will see that the 'charset=' option has been filled in. (4) Edit this catalog file by adding your translations. (5) Now run msgfmt. This will create a binary format so the C gettext function can lookup the translations quickly. (6) Copy the resulting binary formatted catalog file 'hello.mo' into the correct locale directory, for Dutch this is /usr/share/locale/nl_NL/LC_MESSAGES. That's it, now if you run your program you'll see it is translated. For a complete tutorial you can look here. Regards Peter
|
|
|
Post by barryk on Mar 9, 2011 3:41:18 GMT 1
Thanks for the help! I have got it all sorted out (I think), it is now working for me, and I have even written a HOWTO: bkhome.org/bacon/international.htm...feedback is welcome if that page needs improving in any way.
|
|
|
Post by Pjot on Mar 9, 2011 11:22:38 GMT 1
Thanks Barry, looks good to me. I guess for Chinese or Hebrew or Cyrillic we probably need to define the charset as UTF-16.
Also I was thinking, you need to say something about the environment variable 'LC_MESSAGES' which actually defines in which language your application will be displayed?
Regards Peter
|
|