Changing the Locale for a single App?

  • Is it possible to change the locale of my application without changing
    the language preference of the current user?  I have been asked to put a
    language selector in our preference panel that will allow the user to
    change the language of our entire product (including the preference
    panel).

    Currently the preference panel is the only thing using standard bundle
    localization (NSLocalizedStringFromTable).  The rest of the product has
    separate dylibs for each language which are copied into the right
    locations by a set_language script.

    However, with my preference panel, I need a way to load the correct
    localized strings from my localizable.strings file depending upon what
    the user selects.

    --
    Christopher Huyler
    Computer Associates Intl.
    mailto:<christopher.huyler...>
    _______________________________________________
    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 Dec 16, 2003, at 10:13 AM, Huyler, Christopher M wrote:

    > Is it possible to change the locale of my application without changing
    > the language preference of the current user?  I have been asked to put
    > a
    > language selector in our preference panel that will allow the user to
    > change the language of our entire product (including the preference
    > panel).
    >
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[NSArray arrayWithObjects:@"fr", @"en", nil]
    forKey:@"AppleLanguages"];

    mmalc
    _______________________________________________
    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.
  • I believe this will work...as long as it doesn't affect the rest of
    "System Preferences".  I'm working on incorporating it now...

    Thanks!

    ~ Chris

    -----Original Message-----
    From: mmalcolm crawford [mailto:<mmalc_lists...>]
    Sent: Tuesday, December 16, 2003 2:13 PM
    To: Huyler, Christopher M
    Cc: <cocoa-dev...>
    Subject: Re: Changing the Locale for a single App?

    On Dec 16, 2003, at 10:13 AM, Huyler, Christopher M wrote:

    > Is it possible to change the locale of my application without changing
    > the language preference of the current user?  I have been asked to put

    > a
    > language selector in our preference panel that will allow the user to
    > change the language of our entire product (including the preference
    > panel).
    >
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[NSArray arrayWithObjects:@"fr", @"en", nil]
    forKey:@"AppleLanguages"];

    mmalc
    _______________________________________________
    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 Dec 16, 2003, at 11:33 AM, Huyler, Christopher M wrote:

    > I believe this will work...as long as it doesn't affect the rest of
    > "System Preferences".  I'm working on incorporating it now...
    >
    Umm, yes, it works...
    See the discussion of preferences domains at:
    <http://developer.apple.com/documentation/Cocoa/Conceptual/
    UserDefaults/Concepts/DefaultsDomains.html
    >
    and language preferences, for example at:
    <http://developer.apple.com/documentation/Cocoa/Conceptual/
    Internationalization/Concepts/InternatSupport.html
    >

    mmalc
    _______________________________________________
    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 Dec 16, 2003, at 10:13 AM, Huyler, Christopher M wrote:

    > Is it possible to change the locale of my application without changing
    > the language preference of the current user?  I have been asked to put
    > a
    > language selector in our preference panel that will allow the user to
    > change the language of our entire product (including the preference
    > panel).
    >
    > Currently the preference panel is the only thing using standard bundle
    > localization (NSLocalizedStringFromTable).  The rest of the product has
    > separate dylibs for each language which are copied into the right
    > locations by a set_language script.
    >
    > However, with my preference panel, I need a way to load the correct
    > localized strings from my localizable.strings file depending upon what
    > the user selects.

    Yes.  The user's localization preferences are set using the
    AppleLanguages default.  This is a standard user default, and can be
    set globally or on a per-app basis, or as a command-line argument, like
    other defaults.  The relevant preference pane sets the global
    preferences.  If you want to run an application using some other
    preferences, you can for example launch it from the command line e.g.
    /Applications/TextEdit.app/Contents/MacOS/TextEdit -AppleLanguages
    "(fr, en)".

    However, it sounds like what you want to do is to select a specific
    localization from within the running app.  For that what you probably
    want is NSBundle's localization-specific APIs (the ones with
    forLocalization: in the name).  These allow you to locate a resource
    for a specific localization rather than use NSBundle's default
    localization selection.  What this will not do for you is parse a
    .strings file, but that is not a large amount of additional work; the
    standard plist parsing methods will parse .strings files into
    dictionaries.

    Douglas Davidson
    _______________________________________________
    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.
  • I had some problems with this...primarily because I am working with a
    Preference Pane and not a stand alone application.  So I guess my
    question should have been "Changing the Local for a single Preference
    Pane".  But anyway...

    1) You must have the language files for System Preferences (not just my
    Preference Pane) to switch the language.  So if French support of OSX is
    not installed, you cannot switch to French.
    2) Making the switch causes the entire System Preferences App to run in
    the selected language.  I suppose I should have seen this coming.

    So now my question is...can I select the language to use right when the
    bundle is loaded...and only have my Preference Pane be displayed in a
    different language?  I know it sounds stupid, but that's what I have
    been asked to do.  Right now I do not have separate Nib files for the
    different languages, only a Localizable.strings file if that makes
    things easier.

    -----Original Message-----
    From: mmalcolm crawford [mailto:<mmalc_lists...>]
    Sent: Tuesday, December 16, 2003 2:42 PM
    To: Huyler, Christopher M
    Subject: Re: Changing the Locale for a single App?

    On Dec 16, 2003, at 11:33 AM, Huyler, Christopher M wrote:

    > I believe this will work...
    _______________________________________________
    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.
  • I'm sure its possibly technically to do what you want to do.

    But from a user's perspective does it really make sense? IMHO I think
    you're wasting time trying to get your prefpane running with a
    different language to the rest of System Preferences...

    1) You wont be able to change UI owned only by the app - by this I mean
    things like menus, about box, help items, etc. Its going to be a bit
    odd having a single prefpane in English and all other prefpanes, menus,
    etc in Quenya... ;-)

    2) The user probably picked the languages he wants to use in his
    International preferences. Why bother giving the user another chance to
    pick a language (I betcha 99/100 times the user will be using the same
    language).

    3) Its inconsistent with the rest of Mac OS X. Most Apps I've used are
    quite happy relying on the system language.

    You really need to consider if this feature really makes sense from a
    user's perspective. Of course there might be something special about
    your software that makes this feature make perfect sense - but if its
    just a case of trying keep feature parity with Windows software then
    I'd really try and fight against the inclusion of this feature.

    Jon.

    On Dec 17, 2003, at 10:46, Huyler, Christopher M wrote:

    > I had some problems with this...primarily because I am working with a
    > Preference Pane and not a stand alone application.  So I guess my
    > question should have been "Changing the Local for a single Preference
    > Pane".  But anyway...
    >
    > 1) You must have the language files for System Preferences (not just my
    > Preference Pane) to switch the language.  So if French support of OSX
    > is
    > not installed, you cannot switch to French.
    > 2) Making the switch causes the entire System Preferences App to run in
    > the selected language.  I suppose I should have seen this coming.
    >
    > So now my question is...can I select the language to use right when the
    > bundle is loaded...and only have my Preference Pane be displayed in a
    > different language?  I know it sounds stupid, but that's what I have
    > been asked to do.  Right now I do not have separate Nib files for the
    > different languages, only a Localizable.strings file if that makes
    > things easier.
    >
    > -----Original Message-----
    > From: mmalcolm crawford [mailto:<mmalc_lists...>]
    > Sent: Tuesday, December 16, 2003 2:42 PM
    > To: Huyler, Christopher M
    > Subject: Re: Changing the Locale for a single App?
    >
    >
    > On Dec 16, 2003, at 11:33 AM, Huyler, Christopher M wrote:
    >
    >> I believe this will work...
    > _______________________________________________
    > 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.

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    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 Dec 17, 2003, at 8:46 AM, Huyler, Christopher M wrote:

    > I had some problems with this...primarily because I am working with a
    > Preference Pane and not a stand alone application.  So I guess my
    > question should have been "Changing the Local for a single Preference
    > Pane".  But anyway...
    >
    Umm, yes, that makes a difference...

    > 1) You must have the language files for System Preferences (not just my
    > Preference Pane) to switch the language.  So if French support of OSX
    > is
    > not installed, you cannot switch to French.

    The same applies to Catalan, for example:
    <http://cocoa.mamasam.com/COCOADEV/2003/11/2/78035.php>

    > So now my question is...can I select the language to use right when the
    > bundle is loaded...and only have my Preference Pane be displayed in a
    > different language?  I know it sounds stupid, but that's what I have
    > been asked to do.  Right now I do not have separate Nib files for the
    > different languages, only a Localizable.strings file if that makes
    > things easier.
    >
    I think Doug's answer covered the implementation basics?

    On Dec 16, 2003, at 11:40 AM, Douglas Davidson wrote:

    > However, it sounds like what you want to do is to select a specific
    > localization from within the running app.  For that what you probably
    > want is NSBundle's localization-specific APIs (the ones with
    > forLocalization: in the name).  These allow you to locate a resource
    > for a specific localization rather than use NSBundle's default
    > localization selection.  What this will not do for you is parse a
    > .strings file, but that is not a large amount of additional work; the
    > standard plist parsing methods will parse .strings files into
    > dictionaries.
    >
    What you *might* (untested) do to get the above to work is to register
    your pane's language preference in its own domain rather than the
    current app's (System Preferences) -- use:

    - (NSDictionary *)persistentDomainForName:(NSString *)domainName
    - (void)setPersistentDomain:(NSDictionary *)domain forName:(NSString
    *)domainName

    with domainName @"com.ca.LSPP" or whatever.

    I hope that makes sense?

    mmalc
    _______________________________________________
    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 Dec 17, 2003, at 10:46 AM, Huyler, Christopher M wrote:
    > So now my question is...can I select the language to use right when the
    > bundle is loaded...and only have my Preference Pane be displayed in a
    > different language?  I know it sounds stupid, but that's what I have
    > been asked to do.

    Have you considered telling them that it's not really what Mac users
    expect, and that there's no straightforward way to support it?  (Not
    that it can't be done, just that it's not easy.)

    I'm not trying to be snide in asking you that.  I've found that
    occasionally when I'm writing Macintosh software for people who aren't
    themselves Macintosh users or developers, they ask for things that
    aren't really good fits for the Macintosh user experience.  When I
    explain what Macintosh users expect and how the platform works, and
    that what they're asking for won't have much payoff, often I find that
    they'll say "Oh, OK.  Never mind then."

      -- Chris

    --
    Chris Hanson <cmh...>
    Weblog: http://www.livejournal.com/users/chanson/
    Resume: http://bdistributed.com/people/cmh/resume.html
    Looking for work developing Java or Mac OS X applications
    _______________________________________________
    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 december 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