From: | Jens Granseuer |
Date: | 30 Aug 99 at 18:07:32 |
Subject: | Re: Creating catalogs for NewMenus |
From: "Jens Granseuer" <jensgr@gmx.net>
> From: Darryl Hartwig <darrylh@powerup.com.au>
> > Declare your struct NewMenu array with default strings, then loop through
> > it's members assigning locale strings to menu[i].nm_Label as appropriate.
> > You may also need to set nm_CommKey. Then call CreateMenus, LayoutMenus
> > and attach to window.
>
> So I sort of do a while loop, and then a switch statement inside that, to
> determine which strings I'm converting?
One way to do it might be the following (not quite what Rod suggested, but close):
extern UBYTE *def_str[]; /* this is the array you store your default strings in */
[...]
void create_menu( void ) {
/* when filling in the struct, assign the MSG_ identifier to the mn_Label */
struct NewMenu new_menu[] = {
{ NM_TITLE, (STRPTR)MSG_PROJECT, NULL, 0, 0, 0 },
{ NM_ITEM, (STRPTR)MSG_LOAD, "L", 0, 0, 0 },
{ NM_ITEM, NM_BARLABEL, NULL, 0, 0, 0 },
{ NM_ITEM, (STRPTR)MSG_ABOUT, "?", 0, 0, 0 },
{ NM_ITEM, NM_BARLABEL, NULL, 0, 0, 0 },
{ NM_ITEM, (STRPTR)MSG_QUIT, "Q", 0, 0, 0 },
{ NM_END, NULL, 0, 0, 0, 0 }
};
localize_menu( new_menu );
[...]
}
void localize_menu( struct NewMenu *nm ) {
UWORD i;
for ( i = 0; nm[i].nm_Type != NM_END; i++ ) {
if (nm[i].nm_Label != NM_BARLABEL) nm[i].nm_Label = get_loc_str( (ULONG)nm[i].nm_Label );
}
}
STRPTR get_loc_str( const ULONG num ) {
if ( LocaleBase ) return GetCatalogStr( LocaleCatalog, num, def_str[num] );
return def_str[num];
}
Regards,
Jens