localized strings from another bundle?

  • I have a Foundation tool that's running from My.app/Contents/Resources.
    In the tool I am trying

    // in .../My.app/Contents/Resources
    NSString *path = [[[[NSBundle mainBundle] bundlePath]
                stringByDeletingLastPathComponent]
    stringByDeletingLastPathComponent];
    // now path = .../My.app
    NSBundle *bundle = [NSBundle bundleWithPath: path];
    NSLog([bundle localizedStringForKey: @"verify localized strings" value:
    nil table: nil]);

    I was expecting this code to deal with Localizable.strings correctly,
    but it does not. The localization is setup correctly because My.app is
    OK with
    NSLocalizedString(@"verify localized strings", nil);

    Any ideas? Thanks,

      Alex Rice <alex...> | Mindlube Software  |
    http://mindlube.com

      what a waste of thumbs that are opposable
      to make machines that are disposable  -Ani DiFranco
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Use the macros

    NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment)

    so do this

    NSLocalizedStringFromTableInBundle(@"My Key",@"Foo",bundle,"Some
    comment here")

    if bundle == [NSBundle mainBundle]
    then use

    NSLocalizedStringFromTable(@"My Key",@"Foo","Some comment here")

    in the above it will look for the file Foo.strings in the bundle that
    gets passed in or the main bundle

    if you want to look in a file called Localizable.strings then use this
    macro

    NSLocalizedString(@"My Key","Some comment here")

    the .strings file should look like this

    "My Key" = "Somethiing to display to the user";

    and the file should be in utf16 encoding

    vince

    On Wednesday, January 22, 2003, at 09:46  PM, Alex Rice wrote:

    > I have a Foundation tool that's running from
    > My.app/Contents/Resources. In the tool I am trying
    >
    > // in .../My.app/Contents/Resources
    > NSString *path = [[[[NSBundle mainBundle] bundlePath]
    > stringByDeletingLastPathComponent]
    > stringByDeletingLastPathComponent];
    > // now path = .../My.app
    > NSBundle *bundle = [NSBundle bundleWithPath: path];
    > NSLog([bundle localizedStringForKey: @"verify localized strings"
    > value: nil table: nil]);
    >
    > I was expecting this code to deal with Localizable.strings correctly,
    > but it does not. The localization is setup correctly because My.app is
    > OK with
    > NSLocalizedString(@"verify localized strings", nil);
    >
    > Any ideas? Thanks,
    >
    > Alex Rice <alex...> | Mindlube Software  |
    > http://mindlube.com
    >
    > what a waste of thumbs that are opposable
    > to make machines that are disposable  -Ani DiFranco
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Wednesday, January 22, 2003, at 11:51  PM, Vince DeMarco wrote:
    > NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment)
    > NSLocalizedStringFromTableInBundle(@"My Key",@"Foo",bundle,"Some
    > comment here")
    > NSLocalizedStringFromTable(@"My Key",@"Foo","Some comment here")
    > NSLocalizedString(@"My Key","Some comment here")

    OK, NSLocalizedStringFromTableInBundle() is working for me now. The
    problem was actually not that I wasn't using the macro, it was that I
    chopped off too many LastPathComponents, so the bundle wasn't valid for
    the app. D'oh!

      Alex Rice <alex...> | Mindlube Software  |
    http://mindlube.com

      what a waste of thumbs that are opposable
      to make machines that are disposable  -Ani DiFranco
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • on 03-01-23 1:51 AM, Vince DeMarco at <demarco...> wrote:

    > the .strings file should look like this
    >
    > "My Key" = "Somethiing to display to the user";
    >
    > and the file should be in utf16 encoding

    That leads to a question. Why does PB disable the File Encoding submenu
    items in the Format menu for all .strings files, and why does it disable the
    File Encloding pop-up menu in the Show Info dialog for .strings files that
    are in a localizable folder (saying it is "Not applicable") but leave it
    enabled for .strings files that are at the root level of the project file?

    --

    Bill Cheeseman - <wjcheeseman...>
    Quechee Software, Quechee, Vermont, USA
    http://www.quecheesoftware.com

    The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
    Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
    Croquet Club of Vermont - http://members.valley.net/croquetvermont
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month january 2003 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today