Reputation: 345
I have a simple problem and I can't figure out how to make it work.
I have two targets:
I have two Localizable.strings:
Example: I have a button, a text, or something. On each app it should be different.
I tried keeping the first Localizable.strings for both targets and making the second Localizable.strings for the second target only. The problem is that only ONE Localizable.strings is loaded at a time. I wanna know how to make the TargetApp2 make both Localizable.strings complement each other.
Upvotes: 0
Views: 916
Reputation: 32066
If I've understood your problem correctly, you'll need to give your Localizable.strings
files different names and then use NSLocalizedStringFromTable, otherwise, as you've discovered, they'll conflict and only one is used at runtime.
e.g.
Localizable.strings
as it isLocalizable.strings
to Extra.strings
NSLocalizedStringFromTable(key, @"Extra", comment)
I first encountered this problem when adding the Amazon AWS library which contains its own Localizable.strings
which would arbitrarily be used instead of mine. However, because there are only a few strings in that file, it appeared as if localisation just wasn't working. That was a fun 2 days debugging!
The NSLocalizedStringFromTable
doesn't exist with that exact name in Swift. Instead the table
is an optional parameter in NSLocalizedString
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
With Swift, you'll just need to change your NSLocalizedString(key: key, comment: "")
to NSLocalizedString(key: key, table:"Extra" comment: "")
for the affected strings.
Upvotes: 2