Author: manolo
Date: 2013-01-25 08:28:49 -0800 (Fri, 25 Jan 2013)
New Revision: 9809
Log:
Mac OS: added support for internationalization of the application menu.

Modified:
   branches/branch-1.3/FL/mac.H
   branches/branch-1.3/documentation/src/osissues.dox
   branches/branch-1.3/src/Fl.cxx
   branches/branch-1.3/src/Fl_cocoa.mm

Modified: branches/branch-1.3/FL/mac.H
===================================================================
--- branches/branch-1.3/FL/mac.H        2013-01-25 16:27:31 UTC (rev 9808)
+++ branches/branch-1.3/FL/mac.H        2013-01-25 16:28:49 UTC (rev 9809)
@@ -186,6 +186,7 @@
 
 /** \defgroup group_macosx Mac OS X-specific symbols
  Mac OS X-specific symbols declared in <FL/x.H> or <FL/gl.h>
+ \sa \ref osissues_macos
  @{ */
 
 /** @brief Register a function called for each file dropped onto an 
application icon.

Modified: branches/branch-1.3/documentation/src/osissues.dox
===================================================================
--- branches/branch-1.3/documentation/src/osissues.dox  2013-01-25 16:27:31 UTC 
(rev 9808)
+++ branches/branch-1.3/documentation/src/osissues.dox  2013-01-25 16:28:49 UTC 
(rev 9809)
@@ -716,10 +716,6 @@
 Attaches the callback \c cb to the "About myprog" item of the system 
application menu.
 \c cb will be called with NULL first argument and \c user_data second argument.
 
-Fl_Mac_App_Menu class
-\par 
-The Fl_Mac_App_Menu class allows to localize the application menu.
-
 Fl_Sys_Menu_Bar class
 
 \par
@@ -727,8 +723,8 @@
 placed in the system menu bar (at top-left of display), and, on other 
platforms,
 at a user-chosen location of a user-chosen window.
 
+
 \subsection osissues_quartz Drawing Things Using Quartz
-
 All code inside Fl_Widget::draw()
 is expected to call Quartz drawing functions. The Quartz coordinate system 
 is flipped to match
@@ -737,6 +733,27 @@
 \c fl_gc (of type \c CGContextRef) is the appropriate Quartz 2D drawing 
environment.
 Include FL/x.H to declare the \c fl_gc variable.
 
+\subsection osissues_localize Internationalization
+All FLTK programs contain an application menu with, e.g., the About xxx, Hide 
xxx, and Quit xxx items.
+This menu can be internationalized/localized by any of two means.
+\li using the Fl_Mac_App_Menu class.
+\li using the standard Mac OS X localization procedure. Create a 
language-specific .lproj directory 
+(e.g., <tt>German.lproj</tt>) in the Resources subdirectory of the application 
bundle. 
+Create therein a <tt>Localizable.strings</tt> file that translates all menu 
items to this language. 
+The German <tt>Localizable.strings</tt> file, for example, contains:
+\verbatim
+"About %@" = "Über %@";
+"Print Front Window"="Frontfenster drucken";
+"Services" = "Dienste";
+"Hide %@"="%@ ausblenden";
+"Hide Others"="Andere ausblenden";
+"Show All"="Alle einblenden";
+"Quit %@"="%@ beenden";
+\endverbatim
+Set <tt>"Print Front Window" = "";</tt> therein so the application menu 
doesn't show a "Print Front Window" item.
+To localize the application name itself, create a file 
<tt>InfoPlist.strings</tt> in each .lproj directory
+and put <tt>CFBundleName = "localized name";</tt> in each such file.
+
 Fl_Double_Window
 
 OS X double-buffers all windows automatically. On OS X,

Modified: branches/branch-1.3/src/Fl.cxx
===================================================================
--- branches/branch-1.3/src/Fl.cxx      2013-01-25 16:27:31 UTC (rev 9808)
+++ branches/branch-1.3/src/Fl.cxx      2013-01-25 16:28:49 UTC (rev 9809)
@@ -74,13 +74,13 @@
 // Globals...
 //
 #if defined(__APPLE__) || defined(FL_DOXYGEN)
-const char *Fl_Mac_App_Menu::about = "About ";
+const char *Fl_Mac_App_Menu::about = "About %@";
 const char *Fl_Mac_App_Menu::print = "Print Front Window";
 const char *Fl_Mac_App_Menu::services = "Services";
-const char *Fl_Mac_App_Menu::hide = "Hide ";
+const char *Fl_Mac_App_Menu::hide = "Hide %@";
 const char *Fl_Mac_App_Menu::hide_others = "Hide Others";
 const char *Fl_Mac_App_Menu::show = "Show All";
-const char *Fl_Mac_App_Menu::quit = "Quit ";
+const char *Fl_Mac_App_Menu::quit = "Quit %@";
 #endif // __APPLE__
 #ifndef FL_DOXYGEN
 Fl_Widget      *Fl::belowmouse_,

Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2013-01-25 16:27:31 UTC (rev 9808)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2013-01-25 16:28:49 UTC (rev 9809)
@@ -3066,21 +3066,23 @@
   NSMenu *mainmenu, *services = nil, *appleMenu;
   NSMenuItem *menuItem;
   NSString *title;
-
-  NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] 
objectForKey:@"CFBundleName"];
+  
+  SEL infodictSEL = (fl_mac_os_version >= 100200 ? 
@selector(localizedInfoDictionary) : @selector(infoDictionary));
+  NSString *nsappname = [[[NSBundle mainBundle] performSelector:infodictSEL] 
objectForKey:@"CFBundleName"];  
   if (nsappname == nil)
     nsappname = [[NSProcessInfo processInfo] processName];
   appleMenu = [[NSMenu alloc] initWithTitle:@""];
   /* Add menu items */
-  title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::about] 
stringByAppendingString:nsappname];
+  title = [NSString stringWithFormat:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::about],nil), nsappname];
   menuItem = [appleMenu addItemWithTitle:title action:@selector(showPanel) 
keyEquivalent:@""];
   FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init];
   [menuItem setTarget:about];
   [appleMenu addItem:[NSMenuItem separatorItem]];
   // Print front window
-  if (strlen(Fl_Mac_App_Menu::print) > 0) {
+  title = NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::print], nil);
+  if ([title length] > 0) {
     menuItem = [appleMenu 
-               addItemWithTitle:[NSString 
stringWithUTF8String:Fl_Mac_App_Menu::print] 
+               addItemWithTitle:title
                action:@selector(printPanel) 
                keyEquivalent:@""];
     [menuItem setTarget:about];
@@ -3092,29 +3094,29 @@
     // Services Menu
     services = [[NSMenu alloc] init];
     menuItem = [appleMenu 
-               addItemWithTitle:[NSString 
stringWithUTF8String:Fl_Mac_App_Menu::services] 
+               addItemWithTitle:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::services], nil)
                action:nil 
                keyEquivalent:@""];
     [appleMenu setSubmenu:services forItem:menuItem];
     [appleMenu addItem:[NSMenuItem separatorItem]];
     // Hide AppName
-    title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::hide] 
stringByAppendingString:nsappname];
+    title = [NSString stringWithFormat:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::hide],nil), nsappname];
     [appleMenu addItemWithTitle:title 
                         action:@selector(hide:) 
                  keyEquivalent:@"h"];
     // Hide Others
     menuItem = [appleMenu 
-               addItemWithTitle:[NSString 
stringWithUTF8String:Fl_Mac_App_Menu::hide_others] 
+               addItemWithTitle:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::hide_others] , nil)
                action:@selector(hideOtherApplications:) 
                keyEquivalent:@"h"];
     [menuItem 
setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
     // Show All
-    [appleMenu addItemWithTitle:[NSString 
stringWithUTF8String:Fl_Mac_App_Menu::show] 
+    [appleMenu addItemWithTitle:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::show] , nil)
                         action:@selector(unhideAllApplications:) 
keyEquivalent:@""];
     [appleMenu addItem:[NSMenuItem separatorItem]];
     // Quit AppName
-    title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::quit] 
-            stringByAppendingString:nsappname];
+    title = [NSString stringWithFormat:NSLocalizedString([NSString 
stringWithUTF8String:Fl_Mac_App_Menu::quit] , nil),
+            nsappname];
     [appleMenu addItemWithTitle:title 
                         action:@selector(terminate:) 
                  keyEquivalent:@"q"];

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to