Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: internationalisation « Reply #1 on Mar 6, 2011, 2:40pm »
Gutentag,
The first line in the HUG INCLUDE is:
Code:
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:
Code:
var$ = GETENVIRON$("LANG") INCLUDE "hug.bac" SETENVIRON "LANG", var$
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: internationalisation « Reply #3 on Mar 6, 2011, 7:44pm »
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:
Code:
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)
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: internationalisation « Reply #4 on Mar 6, 2011, 8:03pm »
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.
Re: internationalisation « Reply #6 on Mar 7, 2011, 8:11pm »
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
Code:
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"
# 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:
Code:
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)
Re: internationalisation [SOLVED] « Reply #9 on Mar 8, 2011, 11:38am »
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:
Code:
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:
Code:
# 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:
Code:
# 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"
Re: internationalisation « Reply #11 on Mar 8, 2011, 3:51pm »
Code:
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
Code:
bacon -x hello.bac
and edit hello.pot so that there is a valid charset, UTF-8 (required if worlwide usage is intended) _________________________________
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
Code:
SYSTEM "export OUTPUT_CHARSET=UTF-8"
be included in next HUG ?
it works in barry's test
Code:
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)
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: internationalisation « Reply #12 on Mar 8, 2011, 10:46pm »
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'
Code:
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:
Quote:
msginit -l nl_NL -o nl.po -i hello.pot
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.
Quote:
msgfmt -c -v -o hello.mo nl.po
(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.
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: internationalisation « Reply #14 on Mar 9, 2011, 11:22am »
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?