Search code examples
ioslocalizationapple-push-notificationsxliff

Specify base localization for Localized formatted APNS strings


My base localizations are in storyboards, but also in a struct like this:

struct Strings {  

  struct Restaurant {
    static let makeCall = NSLocalizedString("Restaurant-makeCall", value: "Call %@", comment: "Restaurant-makeCall: title for button that allows you to call a place")
  }

  //...many more

}

This works pretty well because it keeps them in one place, defines a key that is separate from the base translation value, and gives me autocomplete when I'm using them: Strings.Restaurant.makeCall

To enter translations, I use the xliff import/export process: editor > export for localization. I found genstrings had trouble with the longhand form of NSLocalizedString.

This all works well until I get to Localized APNS Messages. Given an loc-key and optional loc-args, They search for a matching localization key.

For the translations, this works, because there's a Localizable.strings built for each translation when I import the translated xliff file.

There is no Localizable.strings file for my base translation. I attempted to make one, but the xliff export does not notice those fields to add to other translations, so I think that's not the right way to do it.

How do I add base translations in a way that will work for APNS?


Solution

  • One functional, but duplicative approach is to define them in both places:

    • Define keys (and unused values) in the Strings struct. The xliff export notices these and this allows other languages to provide translations
    • Define keys and values in a Localizable.strings file you create for your base translation. This allows APNS to find the values when you're in the base language, but xliff export can't see these.

    This works, but if somebody ever changes one without keeping the other file up-to-date, differences in translation will occur that will be hard to detect, so I don't like it very much.