Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
AmiBlitz and Locale
#1
Hi guys,
Has anyone managed to get Locale support working in their AmiBlitz programs? I know there are dictionary-type solutions but I would like to have proper locale support using locale.library. I've tried porting a basic C example using the locale.library1 calls but I can't get it to work as those calls don't give the response I would expect based on the autodocs, meaning I cannot tell when the default catalog is to be used. For example, OpenCatalogA_() gives a catalog pointer instead of null, even when the catalog doesn't exist. It should return null to indicate that I should use the internal strings.

Deflibs commands crash when the requested catalog doesn't exist, so they're not an option.

Thanks!
Zitieren
#2
I played with this a really long time ago. It should work with the local.library just like any other C-style example.

I guess how you use it is:
[ab3]#ID_HELLOWORD = 1
*myCatalog.Catalog = OpenCatalogA_("English", "myprog", Null)
sting.s = Peek.s(GetCatalogStr_ (*myCatalog, #ID_HELLOWORLD, "Hello World"));
NPrint string
CloseCatalog_ *myCatalog
End[/ab3]

It doesnt matter if the catalog exists. It is transparent for you. You just provide the default sting. So there is no extra case if the catalog is missing. Same code.

You can make it more handy if you put it in a macro:

[ab3]SHARED *myCatalog.Catalog ; make it auto global

*myCatalog.Catalog = OpenCatalogA_("English","myprog", Null)
If (*myCatalog=Null) NPrint "Unable to create catalog!" : End

Statement CloseCatalog{}
If (*myCatalog) Then CloseCatalog_ *myCatalog : *myCatalog = Null
End Statement
!autoexit{CloseCatalog} ; this is called on "End" or Debugger End

Macro LocStr ; get the localized string
Peek.s(GetCatalogStr_ (*myCatalog, ('1), ('2)));
End Macro

; or, more safe:
Function.s LocStr{id.l, default.s}; get the localized string

If (*myCatalog=Null) Then Function Return default
stringP.l = GetCatalogStr_ (*myCatalog, id, &default);
If (stringP) Function Return Peek.s(stringP)
Function Return default

End Function

NPrint LocStr{#ID_HELLOWORLD, "Hello World"}
End[/ab3]
Zitieren
#3
Thanks very much, it looks sort of like what I tried to do, but I'll have a look again when I am at home to see if I made some sort of mistake.
Zitieren
#4
Well, I'm afraid none of the examples you gave worked. They all crash at the OpenCatalogA_ command with no error message from the debugger, and also cause the whole OS to stop working - I can highlight an icon on Workbench for example, but Workbench freezes if I double-click it. I was using more or less the same code in my test program, and with the same results. Any ideas?

Thanks for your help!
Zitieren
#5
Okay, I seem to have a working solution for this. There were a couple of problems stopping things from working - first off, OpenCatalogA_() only works if the first parameter is null, or else is an exact locale name string. "English" doesn't work for that reason.

The second is strange to me.

result$ = Peek.s(GetCatalogStr_ (*myCatalog, #ID_HELLOWORLD, "Hello World"))

always returns the default string and eventually crashes after a number of runs, but

ad.l = GetCatalogStr_ (*myCatalog, #ID_HELLOWORLD, "Hello World")
result$ = Peek.s(ad)

works fine. I don't understand the difference here - are they not basically the same thing?

Anyway, it works fine now. Thanks for the pointers!
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste