Localizing the Edit menu and other standard menus
Asked Answered
R

3

12

I'm trying to translate my Mac app into a few different languages. There are a large number of menu items, particularly in the Edit menu, that are provided by OS X and work automatically. I assumed these items would be translated automatically as well, but they don't seem to be. As you can see in the screenshot below, I'm getting a mix of translated and untranslated items.

The Edit menu, partially localized

Strangely, the same menu items are translated when they appear in a contextual menu, for example in an NSTextView. In this case everything is translated automatically, aside from the two Services at the bottom.

A contextual menu, automatically translated

So I'm very confused: do I really have to translate the Edit menu myself? I obviously want my translations to match Apple's, so I'd be doing an awful lot of copy and pasting. Or is there some secret to getting the localization to kick in? My app requires 10.7 or later, so if there's anything newish that makes this easier, that shouldn't be a problem.

Addendum: Assuming there is no easier way to do this, is there at least an easy way to copy the text of Apple's translations so I can paste them into my app? I was thinking I could just open up a NIB from one of their apps, but they're all compiled, and can't be opened in Xcode. I can open them in a text editor, but trying to find the appropriate strings this way doesn't seem any faster than just retyping everything.

Ramiah answered 2/8, 2012 at 19:47 Comment(1)
I noted that if you empty the Title property of some "default" NSMenuItem like "Undo" or "Redo", OS X will fill in the blanks with the localized value, provided the language is supported by the OS itself. It doesn't work for all menu items though, so better check for each one.Candracandy
R
6

Update:

Thanks to this helpful post by Douglas Hill I've learned there is actually a proper solution to this. Apple maintains a list of Glossaries that include strings for a huge number of uses. They're designed for a command line tool named AppleGlot, but they can also be opened in a text editor. Apple's Internationalization page includes links to these tools. Localizing Strings Files Using AppleGlot includes some information on how to use AppleGlot—though currently the app's installer has an expired certificate, and it doesn't appear to be compatible with Catalina regardless. Douglas Hill's post offers some alternative ideas for how to automate the translation process.


Original Answer:

From what I can tell, there really is no easy way to do this. For Japanese in particular, I ended up using a process like this:

  1. In Finder, right-click on an existing app, like TextEdit, and choose "Show Package Contents"

  2. Inside the package, go to Contents/Resources and you'll see the localization folders like en.lproj and Japanese.lproj

  3. Inside those folders, you'll see the NIB files. Using a plain text edit (like BBEdit), open the main NIB file for your main language and the language you want translations for. In many cases the files you want will be named MainMenu.nib. With TextEdit, the files are named Edit.nib. The files are XML, so they're clearly structured, but there's a lot of stuff you don't care about. Having the two files open makes it easier.

  4. In the English file, you can search for something like "Check Document Now". Directly below that is the keyboard shortcut (;) and the method the menu item calls (checkSpelling:). Now you can search the Japanese file for checkSpelling and the translation you need is right above it. It sounds tedious, but I've found it pretty quick for the most part, especially since you rarely need to type everything out fully to find what you need. Many of the method names are obvious too—like cut: paste: copy: and so on, so as you go you may be able to skip checking the English file first.

  5. Menu items that are submenus are a bit trickier, since the method will just be submenuAction:. You can use the surrounding XML to help verify you're looking at the same thing in both NIBs, or you can check in the app itself to make sure you're looking at the right text. Google Translate was also helpful when I wanted to make sure I copied the right thing. You might even try using Google Translate first, and just verify that it matches what Apple uses.

Obviously you need to either be very careful, or have someone who speaks the language verify everything works as expected. It'd be better to just have a translator do all the work. In my case, I've had people volunteer to do translations, and all the text unique to my app is already translated. I didn't want to bother them with the tedious work of translating a bunch of text someone else has already translated.

Ramiah answered 3/8, 2012 at 18:53 Comment(0)
C
8

Localized Nibs contains MainMenu.nib files, with the menubars pre-localized into various languages. All items are connected to the proper actions, and several additional resources are included (such as flag graphics, ISO language tables, and more).

localize-mainmenu - Command line tool that localizes the common main menu items of an OS X app automatically.

Catton answered 4/12, 2014 at 18:9 Comment(0)
R
6

Update:

Thanks to this helpful post by Douglas Hill I've learned there is actually a proper solution to this. Apple maintains a list of Glossaries that include strings for a huge number of uses. They're designed for a command line tool named AppleGlot, but they can also be opened in a text editor. Apple's Internationalization page includes links to these tools. Localizing Strings Files Using AppleGlot includes some information on how to use AppleGlot—though currently the app's installer has an expired certificate, and it doesn't appear to be compatible with Catalina regardless. Douglas Hill's post offers some alternative ideas for how to automate the translation process.


Original Answer:

From what I can tell, there really is no easy way to do this. For Japanese in particular, I ended up using a process like this:

  1. In Finder, right-click on an existing app, like TextEdit, and choose "Show Package Contents"

  2. Inside the package, go to Contents/Resources and you'll see the localization folders like en.lproj and Japanese.lproj

  3. Inside those folders, you'll see the NIB files. Using a plain text edit (like BBEdit), open the main NIB file for your main language and the language you want translations for. In many cases the files you want will be named MainMenu.nib. With TextEdit, the files are named Edit.nib. The files are XML, so they're clearly structured, but there's a lot of stuff you don't care about. Having the two files open makes it easier.

  4. In the English file, you can search for something like "Check Document Now". Directly below that is the keyboard shortcut (;) and the method the menu item calls (checkSpelling:). Now you can search the Japanese file for checkSpelling and the translation you need is right above it. It sounds tedious, but I've found it pretty quick for the most part, especially since you rarely need to type everything out fully to find what you need. Many of the method names are obvious too—like cut: paste: copy: and so on, so as you go you may be able to skip checking the English file first.

  5. Menu items that are submenus are a bit trickier, since the method will just be submenuAction:. You can use the surrounding XML to help verify you're looking at the same thing in both NIBs, or you can check in the app itself to make sure you're looking at the right text. Google Translate was also helpful when I wanted to make sure I copied the right thing. You might even try using Google Translate first, and just verify that it matches what Apple uses.

Obviously you need to either be very careful, or have someone who speaks the language verify everything works as expected. It'd be better to just have a translator do all the work. In my case, I've had people volunteer to do translations, and all the text unique to my app is already translated. I didn't want to bother them with the tedious work of translating a bunch of text someone else has already translated.

Ramiah answered 3/8, 2012 at 18:53 Comment(0)
A
2

I found Martin Stemmel's git project useful (FYI: I have connection to the author). It is free and you can simply browse the various language files for the standard main menu strings u need or use the project.

https://github.com/martnst/localize-mainmenu

Algo answered 8/3, 2020 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.