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.
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.
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.
The menu bar is the part of a browser or application window, typically at the top left side, that houses drop-down menus that allow the user to interact with the content or application in various ways.
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:
In Finder, right-click on an existing app, like TextEdit, and choose "Show Package Contents"
Inside the package, go to Contents/Resources and you'll see the localization folders like en.lproj and Japanese.lproj
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With