Getting Localized System Strings

  • Cocoa uses (automatically) localized strings. I would like to do the
    same.

    E.g. using NSTextView and pasting a font, the Edit menu will suddenly
    show Undo "Paste Font".
    If the same app is running with German as the preferred language, the
    Edit menu will contain Undo "Schrift einsetzen" (yes, the "Undo" also
    gets translated, but this does not interest me at this point).

    When I override this mechanism, doing my own undo handling I have to
    use setActionName: "Paste Font".
    But this is only correct if the current language is English.

    So I have to do: setActionName: NSLocalizedStringFromTable( @"Paste
    Font", @"UndoStrings",  @"setting font via menu Format → Font");

    But this means that I have to create UndoStrings.strings files for
    about 15 languages, which is kind of tedious.
    Also: If Apple decides that the correct translation for "Paste Font"
    should be "Schriftart einfügen" instead of "Schrift einsetzen", my
    app would look strange, using different words compared to all other
    apps.

    So I want something like:
    NSLocalizedStringFrom_the_Table_used_by_the_System(..).
    Or maby I could get at the official translations using NSDefaultManager?

    These strings must be somewhere - so how to find them? Neither
    Spotlight nor grep seem to handle utf-16 files (like .strings).

    Kind regards,

    Gerriet.
  • The strings you are looking for are in the AppKit ressources, but I
    don't think there are part of the API, the keys can change at anytime
    and you cannot rely on the files names. (in Leopard, the Undo.strings
    file contains a "Paste Font" key, but it's not garantee that it remain
    like that)

    Anyway, you can probably copy this Undo.strings file in your
    application.

    Le 1 avr. 08 à 11:52, Gerriet M. Denkmann a écrit :
    > Cocoa uses (automatically) localized strings. I would like to do the
    > same.
    >
    > E.g. using NSTextView and pasting a font, the Edit menu will
    > suddenly show Undo "Paste Font".
    > If the same app is running with German as the preferred language,
    > the Edit menu will contain Undo "Schrift einsetzen" (yes, the "Undo"
    > also gets translated, but this does not interest me at this point).
    >
    > When I override this mechanism, doing my own undo handling I have to
    > use setActionName: "Paste Font".
    > But this is only correct if the current language is English.
    >
    > So I have to do: setActionName: NSLocalizedStringFromTable( @"Paste
    > Font", @"UndoStrings",  @"setting font via menu Format → Font");
    >
    > But this means that I have to create UndoStrings.strings files for
    > about 15 languages, which is kind of tedious.
    > Also: If Apple decides that the correct translation for "Paste Font"
    > should be "Schriftart einfügen" instead of "Schrift einsetzen", my
    > app would look strange, using different words compared to all other
    > apps.
    >
    > So I want something like:
    > NSLocalizedStringFrom_the_Table_used_by_the_System(..).
    > Or maby I could get at the official translations using
    > NSDefaultManager?
    >
    > These strings must be somewhere - so how to find them? Neither
    > Spotlight nor grep seem to handle utf-16 files (like .strings).
    >
    >
    > Kind regards,
    >
    > Gerriet.
  • On 1 Apr 2008, at 12:25, Jean-Daniel Dupas wrote:
    >
    > The strings you are looking for are in the AppKit ressources, but I
    > don't think there are part of the API, the keys can change at
    > anytime and you cannot rely on the files names. (in Leopard, the
    > Undo.strings file contains a "Paste Font" key, but it's not
    > garantee that it remain like that)
    >
    > Anyway, you can probably copy this Undo.strings file in your
    > application.
    >
    >
    > Le 1 avr. 08 à 11:52, Gerriet M. Denkmann a écrit :
    >> Cocoa uses (automatically) localized strings. I would like to do
    >> the same.
    >>
    >> E.g. using NSTextView and pasting a font, the Edit menu will
    >> suddenly show Undo "Paste Font".
    >> If the same app is running with German as the preferred language,
    >> the Edit menu will contain Undo "Schrift einsetzen" (yes, the
    >> "Undo" also gets translated, but this does not interest me at this
    >> point).
    >>
    >> When I override this mechanism, doing my own undo handling I have
    >> to use setActionName: "Paste Font".
    >> But this is only correct if the current language is English.
    >>
    >> So I have to do: setActionName: NSLocalizedStringFromTable
    >> ( @"Paste Font", @"UndoStrings",  @"setting font via menu Format
    >> → Font");
    >>
    >> But this means that I have to create UndoStrings.strings files for
    >> about 15 languages, which is kind of tedious.
    >> Also: If Apple decides that the correct translation for "Paste
    >> Font" should be "Schriftart einfügen" instead of "Schrift
    >> einsetzen", my app would look strange, using different words
    >> compared to all other apps.
    >>
    >> So I want something like:
    >> NSLocalizedStringFrom_the_Table_used_by_the_System(..).
    >> Or maby I could get at the official translations using
    >> NSDefaultManager?

    Thanks a lot. I decided to use it like this:
    NSBundle *appBundle = [ NSBundle bundleWithIdentifier:
    @"com.apple.AppKit" ];
    NSString *localSetFont = [ appBundle localizedStringForKey: @"Set
    Font" value: nil table: @"Undo"];
    Seems to work fine.

    Kind regards,

    Gerriet.

    P.S. How can one paste into Mail without loosing all newlines?
  • Le 1 avr. 08 à 14:47, Gerriet M. Denkmann a écrit :
    >
    > On 1 Apr 2008, at 12:25, Jean-Daniel Dupas wrote:
    >>
    >> The strings you are looking for are in the AppKit ressources, but I
    >> don't think there are part of the API, the keys can change at
    >> anytime and you cannot rely on the files names. (in Leopard, the
    >> Undo.strings file contains a "Paste Font" key, but it's not
    >> garantee that it remain like that)
    >>
    >> Anyway, you can probably copy this Undo.strings file in your
    >> application.
    >
    > Thanks a lot. I decided to use it like this:
    > NSBundle *appBundle = [ NSBundle bundleWithIdentifier:
    > @"com.apple.AppKit" ];
    > NSString *localSetFont = [ appBundle localizedStringForKey: @"Set
    > Font" value: nil table: @"Undo"];
    > Seems to work fine.
    >
    > Kind regards,
    >
    > Gerriet.

    As I said, it works, but it's not futur-proof, so I would not use it
    in a shipping product.
  • >
    > Thanks a lot. I decided to use it like this:
    > NSBundle *appBundle = [ NSBundle bundleWithIdentifier:
    > @"com.apple.AppKit" ];
    > NSString *localSetFont = [ appBundle localizedStringForKey: @"Set
    > Font" value: nil table: @"Undo"];
    > Seems to work fine.
    >

    That's really not a good thing to do unless Apple has documented those keys, and I don't recall reading anywhere that they have; if they haven't, you should submit a bug for them if you want them to remain where they are for the next release, and you probably should just say, "Give us some keys for common UI text and where they were, are, and will be, so we can rely on those like you have for icons."

    A better solution without official documentation is to see if the strings you want are provided with AppleGlot's installation.  I remember a large number of strings like these were made available in its dictionaries.  Also, there used to be a place on Microsoft's site that had a similar set of dictionaries for your use, but I've lost track of the link.  And, depending on your favorite open source project's license, you might be able to use those.
previous month april 2008 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        
Go to today