The BAsic CONverter Forum
« internationalisation - [SOLVED] »

Welcome Guest. Please Login or Register.
May 24, 2013, 2:43pm




The BAsic CONverter Forum :: General :: Troubleshooting area :: internationalisation - [SOLVED]
Page 1 of 4 » Jump to page   Go    [Search This Thread] [Share Topic] [Print]
 AuthorTopic: internationalisation - [SOLVED] (Read 1,681 times)
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 internationalisation - [SOLVED]
« Thread Started on Mar 6, 2011, 12:06pm »

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
Code:
REM hello world international GUI
REM L18L 2011-03-06
OPTION INTERNATIONAL 1
PRINT INTL("hello world")
END
it is working well.
Code:
# bacon hello_international.bac
Starting conversion... done.
Starting compilation... done.
Program 'hello_international' ready.
# ./hello_international
Hallo Welt

But having just included
Code:
INCLUDE "../hug.bac"
it is
Code:
# 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.

« Last Edit: Apr 2, 2011, 2:44pm by Pjot »Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

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$

Herzliche Grüsse,
Peter
Link to Post - Back to Top  IP: Logged
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 Re: internationalisation
« Reply #2 on Mar 6, 2011, 5:16pm »

Hello Peter,
thank you for the reply but the problem still exists.
What I have so far is now
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$
PRINT INTL("hello world")

REM now the GUI
mainwin = WINDOW("Hello World", 400, 285)

Code:
# 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.
« Last Edit: Mar 6, 2011, 5:17pm by l18l »Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

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)

Regards
Peter
Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

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.

Greetings,
Peter
Link to Post - Back to Top  IP: Logged
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 Re: internationalisation
« Reply #5 on Mar 6, 2011, 8:39pm »

Success on my 1st step on internationalisation :)
applied HUG 0.33
Code:
# 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
Link to Post - Back to Top  IP: Logged
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 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"

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
Code:
bacon -x hello.bac
:
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: 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)
Code:
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
« Last Edit: Mar 8, 2011, 9:39am by l18l »Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

Joined: Apr 2010
Gender: Male
Posts: 938
Location: The Hague, The Netherlands
Karma: 9
 Re: internationalisation [SOLVED]
« Reply #7 on Mar 7, 2011, 10:45pm »

Thanks,

So I have tested it, and it works. BTW your program also works without these lines:
Code:
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
Link to Post - Back to Top  IP: Logged
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 Re: internationalisation [SOLVED]
« Reply #8 on Mar 8, 2011, 9:37am »


Quote:
program also works without these lines

So I change the above code :)
Thank you again
Best regards
Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 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"

#: 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.
Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: internationalisation [SOLVED]
« Reply #10 on Mar 8, 2011, 11:49am »

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.
« Last Edit: Mar 8, 2011, 11:53am by barryk »Link to Post - Back to Top  IP: Logged
l18l
New Member
*
member is offline

[avatar]



Joined: Mar 2011
Gender: Male
Posts: 44
Karma: 0
 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)
_________________________________


edited later: another fault

Quote:

Code:
msgfmt hello-<language-code>.po -o - > /usr/share/locale/<language-code>/hello.mo

was faulty, too.
must be:
_________________________________
Code:
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.
Code:
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
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)
« Last Edit: Mar 8, 2011, 8:51pm by l18l »Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

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.

Quote:

sudo cp hello.mo /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
« Last Edit: Mar 8, 2011, 10:48pm by Pjot »Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: internationalisation
« Reply #13 on Mar 9, 2011, 3:41am »

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:

http://bkhome.org/bacon/international.htm

...feedback is welcome if that page needs improving in any way.
Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

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?

Regards
Peter
Link to Post - Back to Top  IP: Logged
Page 1 of 4 » Jump to page   Go    [Search This Thread] [Share Topic] [Print]

Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Notice | FTC Disclosure | Report Abuse | Mobile