AmiBlitz and Locale - Druckversion

+- AmiBlitz³ (
+-- Forum: AmiBlitz³ (
+--- Forum: Questions & Answers (
+--- Thema: AmiBlitz and Locale (/thread-96.html)

AmiBlitz and Locale - Daedalus - 17.09.2014

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.


Re: AmiBlitz and Locale - Der Wanderer - 18.09.2014

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

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"}

Re: AmiBlitz and Locale - Daedalus - 19.09.2014

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.

Re: AmiBlitz and Locale - Daedalus - 19.09.2014

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!

Re: AmiBlitz and Locale - Daedalus - 27.09.2014

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!