Accessing languages.catalog and countries.catalog

Have a question about our Software Developer Kit? Ask them here.
Post Reply
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Accessing languages.catalog and countries.catalog

Post by trixie »

I'm working on a program that uses country and language names, which I naturally want to display localized. Considering that these are already available in the system's countries.catalog and languages.catalog, I think it would be quite absurd (and a waste of resources) if programs had to put country and language names in their own catalogs. I'd prefer if I could open the respective system catalog and retrieve the strings from there.

Would it be possible to publish the relevant locale string ID definitions as part of the SDK? So that a third-party program could request, for example, MSG_GERMANY from the system's countries.catalog.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

Re: Accessing languages.catalog and countries.catalog

Post by gazelle »

It's pretty easy.

For countries.catalog the IDs are derived from the ISO 3166 country code (alpha-3 names):

Code: Select all

...
MSG_AUS ($41555300//)
Australia
;
MSG_AUT ($41555400//)
Austria
;
...
And for languages.catalog it's the ISO-639-2/T 3-letter lowercase language code:

Code: Select all

...
MSG_eng ($656e6700//)
English
;
...
MSG_deu ($64657500//)
German
;
...
edit1: Of course an official list (or maybe function in one of the libs Get(Countries|Languages)List)) would be better.

edit2: As catalog files are in IFF format, you can also use iffparse.library to read them.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Accessing languages.catalog and countries.catalog

Post by broadblues »

Accessing the catalogs directly in such a way would be a bad idea, restricting the OS devs from updating them in any way they see fit.

IMHO, if such a feature was added it should be via the locale.library API.

And it does seem like a good idea.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: Accessing languages.catalog and countries.catalog

Post by nbache »

It is already done in the Locale prefs editor, presumably.

It would be interesting to know how it goes about it. Maybe there is already an appropriate function which would just need to be exposed publically.

Of course, it would probably already be possible to do it with existing public functionality by opening languages.catalog repeatedly for each of the languages - but quite cumbersome.

Best regards,

Niels
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Accessing languages.catalog and countries.catalog

Post by xenic »

@trixie
The ctlg2ct.lha file at OS4Depot includes sources that have an IFF parse of catologs in the code which might be a good example for you to get the language names from within your program.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Accessing languages.catalog and countries.catalog

Post by trixie »

@broadblues
broadblues wrote:Accessing the catalogs directly in such a way would be a bad idea, restricting the OS devs from updating them in any way they see fit.
That is true.
IMHO, if such a feature was added it should be via the locale.library API.
I agree - although I don't hold out much hope for that being added any time soon.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: Accessing languages.catalog and countries.catalog

Post by javierdlr »

trixie wrote:@broadblues
broadblues wrote:Accessing the catalogs directly in such a way would be a bad idea, restricting the OS devs from updating them in any way they see fit.
That is true.
IMHO, if such a feature was added it should be via the locale.library API.
I agree - although I don't hold out much hope for that being added any time soon.

Maybe you can take a look into SDK's example 'Locale' drawer and make_country_files.c file as it creates the .country files and helps you somehow:

...
struct CountryData
{
STRPTR cd_Name;
ULONG cd_Charset; /* TetiSoft: If this is non-zero, */
STRPTR cd_NativeName; /* this is the name in this charset */
STRPTR cd_Version;
struct CountryPrefs cd_Prefs;
};
...
User avatar
jaokim
Beta Tester
Beta Tester
Posts: 90
Joined: Sat Jun 18, 2011 12:41 am

Re: Accessing languages.catalog and countries.catalog

Post by jaokim »

broadblues wrote:Accessing the catalogs directly in such a way would be a bad idea, restricting the OS devs from updating them in any way they see fit.

IMHO, if such a feature was added it should be via the locale.library API.
Without knowing how the OS devs work, I'd reckon someone changing the naming from ISO standards to something different, is less likely then someone adding a function for it (which I think is already very unlikely [hopefully that remark will persuade someone to do it ;) ]).
But I'd say: use the catalogs, but make sure to check the version of the catalog! The likelihood of the namng standard changing without version bumping should be zero. Perhaps even include a hidden feature to disable the catalog lookup if it should change in the future, and the sources to whatever you're making should be lost.
Btw: how does locale do catalog search? Is CURRDIR: the first path to search? If so, then any incompatible changes could be fixed that way.
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: Accessing languages.catalog and countries.catalog

Post by javierdlr »

jaokim wrote:
broadblues wrote:Accessing the catalogs directly in such a way would be a bad idea, restricting the OS devs from ...
Btw: how does locale do catalog search? Is CURRDIR: the first path to search? If so, then any incompatible changes could be fixed that way.
SDK's ILocale->OpenCatalog():
...
Since V50, the function searches for catalogs in this directories:

PROGDIR:Catalogs/languageName/name
LOCALE:Catalogs/languageName/name
PROGDIR:Catalogs/languageName_UTF-8/name
LOCALE:Catalogs/languageName_UTF-8/name
PROGDIR:Catalogs/languageName_US-ASCII/name
LOCALE:Catalogs/languageName_US-ASCII/name
Post Reply