Catalogs in RapaGui

Discuss GUI programming with the RapaGUI plugin here
ilbarbax
Posts: 112
Joined: Thu Apr 01, 2010 6:41 pm

Catalogs in RapaGui

Post by ilbarbax »

Sorry I can't figure how they should work. Any hint?
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Catalogs in RapaGui

Post by airsoftsoftwair »

User avatar
emeck
Posts: 169
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Post by emeck »

airsoftsoftwair wrote:Just check out the documentation:
http://www.hollywood-mal.com/docs/html/ ... tNote.html
I'm also having trouble with this. My catalog strings work when used in the hws script but nos when used in the xml file. I get this message:

Error parsing XML: not well-formed (invalid token) (line 4)
File: convi.hws (current line: 124 - In function: CreateApp)

Is there any small example on how to call the catalog strings in the xml file?
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
evil
Posts: 175
Joined: Mon Jun 14, 2010 1:38 pm

Re: Catalogs in RapaGui

Post by evil »

Possibly you have some special characters like german "ä" "ö" or french accents in your xml-file??

Try to avoid them.

Possibly changing from ISO to UTF might help, too.

Best regards

George
User avatar
emeck
Posts: 169
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Post by emeck »

evil wrote:Possibly you have some special characters like german "ä" "ö" or french accents in your xml-file??
No special characters. I tried only with english as default and english catalog too. The catalog table with the strings works when the string variables are called inside the HW script for each corresponding catalog, as shown by debugprinting the variables. But the same variables written in the xml file dont't work.

For example, I have this:

Code: Select all

def_cat$={}    ;default language table
def_cat$[0]="File"
def_cat$[1]="About..."
def_cat$[2]="About RapaGui..."
def_cat$[3]="Quit"
def_cat$[4]="Input filename"

OpenCatalog("convi.catalog")

convi_cat$={}	;catalog table
convi_cat$[0]=GetCatalogString(0, def_cat$[0])
convi_cat$[1]=GetCatalogString(1, def_cat$[1])
convi_cat$[2]=GetCatalogString(2, def_cat$[2])
convi_cat$[3]=GetCatalogString(3, def_cat$[3])
convi_cat$[4]=GetCatalogString(4, def_cat$[4])
I can use the convi_cat$ variables to show the strings when used in the .hws file but not inside the .xml file. This is the line that calls the .xml file: moai.CreateApp(FileToString("data/convi.xml"))

I suppose the FileToString function converts all, including the catalog variables to string and hence the malformed call I get. There must be a way to localize the .xml file, right?

My workaround for now, to have english, spanish and catalan GUI, is:

Code: Select all

day$=GetWeekday()
If(day$="lunes" Or day$="martes" Or day$="miércoles" Or day$="jueves" Or day$="viernes" Or day$="sábado" Or day$="domingo")
	moai.CreateApp(FileToString("data/convi_esp.xml"))
	ElseIf(day$="dilluns" Or day$="dimarts" Or day$="dimecres" Or day$="dijous" Or day$="divendres" Or day$="dissabte" Or day$="diumenge")
	moai.CreateApp(FileToString("data/convi_cat.xml"))
	Else
	moai.CreateApp(FileToString("data/convi.xml"))
EndIf
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Catalogs in RapaGui

Post by airsoftsoftwair »

You can't access catalogs from XML files because XML doesn't contain code. You need to find a way to workaround this, e.g. use something like this:

Code: Select all

<button>%CATALOGID:0,Hello%</button>
Then write a parser which replaces all %CATALOGID% strings with calls to GetCatalogString(). The number after %CATALOGID is the index and the string is the default string. Not sure if my idea is the nicest solution, though.
User avatar
emeck
Posts: 169
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Post by emeck »

@airsoftsoftwair
that is too complex for me now. But I found a solutions that is working nicely for the small GUIs I'm writing now and simpler than the one posted before for using an xml file for each language that have a catalog.

Code: Select all

/**** Read GUI file ****/
;detect system's language, change
;encoding from MorphOS char set to UTF-8
;and switch to the corresponding xml GUI
language$=ConvertStr(GetEnv("language"), #ENCODING_AMIGA, #ENCODING_UTF8)
	Switch language$
	Case "español":
		moai.CreateApp(FileToString("data/convi_esp.xml"))
	Case "català":
		moai.CreateApp(FileToString("data/convi_cat.xml"))
	Default:
		moai.CreateApp(FileToString("data/convi.xml"))
EndSwitch
/***********************/
Maybe it is usefull for someone else.
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Catalogs in RapaGui

Post by airsoftsoftwair »

Of course, this contradicts the DRY programming paradigm ("don't repeat yourself") but for smaller projects it probably doesn't matter :)
ilbarbax
Posts: 112
Joined: Thu Apr 01, 2010 6:41 pm

Re: Catalogs in RapaGui

Post by ilbarbax »

At the end I applied what is the proper way (at least I think) as follow:

1. Create a table with the translations...use the conventional catalog way as described in the manual.
2. assign an ID to your xml items like <text ID="Year" align="Right">Year:</text>
3. after creating the moai application set the ID with the translation as follow

moai.CreateApp(f$)
moai.Set("Year", "Text", Cat_string$[6]..":")

and you will have your application in your language. It is bit boring because you have to do that for all text items of your interface, but works.

Drop me an e-mail and I send you copy of my source for reference (sb5@libero.it).
User avatar
emeck
Posts: 169
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Post by emeck »

@ilbarbax
Thanks! I followed your instructions and got it working.
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
Post Reply