MenuPick Localization with Menu Line Number

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

MenuPick Localization with Menu Line Number

Post by dcpbarrington » Sun Jul 13, 2014 5:57 am

Forum,

I need to localize my menus and I'm currently using the standard menuPick

Code: Select all

on menuPick pItemName
   switch pItemName
      case "Settings"
         go to card "Settings"
         break
       case "LogOut"
         logoutRequest
         break
      case "Exit"
         exitRequest
         break
      default
         break 
   end switch
end menuPick
The problem is that the menu text items change depending on the language that is selected.
I want to determine the line number of the menu that was picked instead of the text of the menu.

I know I've seen this somewhere but cannot find it and it is probably quite simple.

Thanks for the help.
dcpbarrington

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: MenuPick Localization with Menu Line Number

Post by Simon » Sun Jul 13, 2014 6:49 am

Hi dcpbarrington,
I was just looking at this myself, here is what I came up with;

Code: Select all

on menuPick pItemName
   repeat with x = 1 to the number of lines in btn 1
      put line x of btn 1 & cr after temp
   end repeat
      put lineOffset(pItemName,temp)
end menuPick
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MenuPick Localization with Menu Line Number

Post by Klaus » Sun Jul 13, 2014 11:51 am

Hi folks,

that's what the (not so new) TAGS are made for!
Check "Menu" in the dictionary for more info.

Basicall a menu item is made up like this:
LABEL_what_the_user_sees/accelerator_keyboard_shortcut|TAG_actual_menu

For a copy menu in english and german:
Kopieren/C|copy
Copy/C|copy

Code: Select all

on menupick tItem
switch tItem
case "copy"
  # For ALL languages!
...
The last thing is the TAG and that is always "static", you only need to localize the LABELS!
You get the picture..


Best

Klaus

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: MenuPick Localization with Menu Line Number

Post by dcpbarrington » Mon Jul 14, 2014 1:12 am

Thanks Klaus,

I knew it couldn't be that hard, but couldn't find an explanation in the MenuItem documentation.

So Set the Item Delimitor to "|" and select the second item before starting the Switch Statement.

Should work great.

dcp

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MenuPick Localization with Menu Line Number

Post by Klaus » Mon Jul 14, 2014 12:19 pm

dcpbarrington wrote:So Set the Item Delimitor to "|" and select the second item before starting the Switch Statement.
No need to set or select anything for the "menupick" handler, if that is what you mean!
See my example!

Post Reply