0
votes

Is there a way to localize a plist that contain hierarchical or grouped data?

For instance, if the plist contains:

  • Book 1 (dictionary)
    • Key (string)
    • Name (string)
    • Description (localizable string)
  • Book 2 (dictionary)
    • Key (string)
    • Name (string)
    • Description (localizable string)
      (etcetera...)

For the sake of the example, the Key and Name should not be translated (and preferably should not be duplicated in multiple localized property lists).

Is there a mechanism for providing localizations for the localizable Description field without localizing the entire property list? The only other strategy that came to my mind is to store a lookup key in the description field and than use that to retrieve the localized text via NSLocalizedString(...)

The plist is static and being distributed with the app bundle right now.

Thanks.

1

1 Answers

0
votes

Is this a static plist or a dynamic one? From where do you expect to get the localized strings? NSLocalizedString() gets it from the Localizable.strings file in your bundle. If the plist is static and you can ship all of the localizations with your app, then you can use the description as the key and look it up with NSLocalizedString() or one of its variants.

If the plist is dynamic, then you can make each Description into a dict mapping from locale identifiers to strings. You'd pick the right one using [NSBundle preferredLocalizationsFromArray:[theDict allKeys]]. That has the drawback that if the same Description is used for multiple Books, then its localizations have to be repeated.

To fix that drawback, you could put the localizations into the plist in a separate section. Basically, this would be a dictionary of dictionaries. The keys of the outer dictionary could be the locale identifiers, the keys of the inner dictionaries could be the English strings, and the inner values could be the localized strings. (Variant 1: use a lookup key instead of the English string. Variant 2: reverse the inner and outer dictionaries, so English string is outer and locale ID is inner.)