Following up on the bundle.make localization, today I added
localization support to application.make.  This presented a bit of a
problem, because the gmodel loading methods don't search in the .lproj
directories for a gmodel.  The simplest solution I came up with was to
add another class method to NSBundle via the IMLoading category.  I
called it +loadGModelNamed:owner: because it mimicks
+loadNibNamed:owner: exactly.  This new method uses NSBundle
-pathForResource:ofType: to find the gmodel in a bundle, and then pass
that name to GMModel +loadIMFile:owner:.
    I like this solution, because it minimizes the changes to an
OpenStep project; it's simply a matter of converting the nibs, maybe
importing another header, then changing one method call.
Index: application.make
===================================================================
RCS file: /gnustep/gnustep/core/make/application.make,v
retrieving revision 1.45
diff -r1.45 application.make
34,35c34,37
< # The list of application resource file are in xxx_RESOURCE_FILES
< # The list of application resource directories are in xxx_RESOURCE_DIRS
---
> # The list of application resource directories is in xxx_RESOURCE_DIRS
> # The list of application resource files is in xxx_RESOURCE_FILES
> # The list of localized resource files is in xxx_LOCALIZED_RESOURCE_FILES
> # The list of supported languages is in xxx_LANGUAGES
92a95,100
> ifeq ($(strip $(LOCALIZED_RESOURCE_FILES)),)
>   override LOCALIZED_RESOURCE_FILES=""
> endif
> ifeq ($(strip $(LANGUAGES)),)
>   override LANGUAGES="English"
> endif
144c152,153
<    $(APP_DIR_NAME)/$(INTERNAL_app_NAME) app-resource-files after-$(TARGET)-all
---
>    $(APP_DIR_NAME)/$(INTERNAL_app_NAME) app-resource-files \
>    app-localized-resource-files after-$(TARGET)-all
165a175,190
> 
> app-localized-resource-files:: $(APP_DIR_NAME)/Resources/Info-gnustep.plist 
>app-resource-dir
>       @(if [ "$(LOCALIZED_RESOURCE_FILES)" != "" ]; then \
>         echo "Copying localized resources into the application wrapper..."; \
>         for l in $(LANGUAGES); do \
>           if [ ! -f $$l.lproj ]; then \
>             $(MKDIRS) $(APP_DIR_NAME)/Resources/$$l.lproj; \
>           fi; \
>           for f in $(LOCALIZED_RESOURCE_FILES); do \
>             if [ -f $$l.lproj/$$f ]; then \
>               cp -r $$l.lproj/$$f $(APP_DIR_NAME)/Resources/$$l.lproj; \
>             fi; \
>           done; \
>         done; \
>       fi)
>       
Index: IMLoading.h
===================================================================
RCS file: /gnustep/gnustep/core/gui/Headers/gnustep/gui/IMLoading.h,v
retrieving revision 1.2
diff -r1.2 IMLoading.h
36a37
> + (BOOL)loadGModelNamed:(NSString *)gmodelName owner:(id)owner;
Index: IMLoading.m
===================================================================
RCS file: /gnustep/gnustep/core/gui/Model/IMLoading.m,v
retrieving revision 1.10
diff -r1.10 IMLoading.m
46a47,65
> + (BOOL)loadGModelNamed:(NSString *)gmodelName owner:(id)owner
> {
>   NSBundle *bundle;
>   NSString *path;
> 
>   /* Pull off the .gmodel extension (if any) for pathForResource:ofType: */
>   if ([[gmodelName pathExtension] isEqualToString:@"gmodel"])
>     gmodelName = [gmodelName stringByDeletingPathExtension];
> 
>   /* Use owner's bundle (if any) just like +loadNibNamed:owner: does. */
>   bundle = [NSBundle bundleForClass: owner];
>   if (bundle == nil)
>     bundle = [NSBundle mainBundle];
> 
>   path = [bundle pathForResource:gmodelName ofType:@"gmodel"];
> 
>   return [GMModel loadIMFile:path owner:owner bundle:bundle];
> }
> 
Index: NSApplication.m
===================================================================
RCS file: /gnustep/gnustep/core/gui/Source/NSApplication.m,v
retrieving revision 1.147
diff -r1.147 NSApplication.m
565c565
<         if ([GMModel loadIMFile: mainModelFile
---
>         if ([NSBundle loadGModelNamed: mainModelFile

Reply via email to