Catalogs in RapaGui

Discuss GUI programming with the RapaGUI plugin here

Catalogs in RapaGui

Postby ilbarbax » Tue Oct 11, 2016 6:24 pm

Sorry I can't figure how they should work. Any hint?
ilbarbax
 
Posts: 77
Joined: Thu Apr 01, 2010 6:41 pm

Re: Catalogs in RapaGui

Postby airsoftsoftwair » Thu Oct 13, 2016 5:25 pm

User avatar
airsoftsoftwair
 
Posts: 2157
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Catalogs in RapaGui

Postby emeck » Thu May 04, 2017 11:18 pm

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?
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Postby evil » Sun May 07, 2017 3:31 am

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
evil
 
Posts: 108
Joined: Mon Jun 14, 2010 1:38 pm

Re: Catalogs in RapaGui

Postby emeck » Sun May 07, 2017 9:02 am

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
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Postby airsoftsoftwair » Sun May 07, 2017 5:53 pm

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
airsoftsoftwair
 
Posts: 2157
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Catalogs in RapaGui

Postby emeck » Sat May 13, 2017 7:53 pm

@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.
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Re: Catalogs in RapaGui

Postby airsoftsoftwair » Sun May 14, 2017 7:39 pm

Of course, this contradicts the DRY programming paradigm ("don't repeat yourself") but for smaller projects it probably doesn't matter :)
User avatar
airsoftsoftwair
 
Posts: 2157
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Catalogs in RapaGui

Postby ilbarbax » Thu May 18, 2017 1:49 pm

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).
ilbarbax
 
Posts: 77
Joined: Thu Apr 01, 2010 6:41 pm

Re: Catalogs in RapaGui

Postby emeck » Wed May 24, 2017 12:22 am

@ilbarbax
Thanks! I followed your instructions and got it working.
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Next

Return to RapaGUI

Who is online

Users browsing this forum: No registered users and 1 guest