Search code examples
iosfilelocalizable.strings

Override a base localizable.strings file


Is there a way to have one base localizable.strings file for multiple targets within a project, and also have a second localizable.string file for each target that will override and append individual values to the base file?

EDIT

I want my app to have two .strings files - Localizable.string and Override.strings. If a string, Title.Welcome, is not found in OverrideLocalizable.strings then I would like the app to search Localizable.strings for Title.Welcome. Essentially, specifying Localizable as the fallback, but using OverrideLocalizable.strings by default.


Solution

  • Here is the solution I found:

    NSString *PSILocalizedString(NSString *key, NSString *comment)
    {
        return NSLocalizedStringWithDefaultValue(key,
                                                 @"OverrideLocalizable",
                                                 [NSBundle mainBundle],
                                                 NSLocalizedString(key, nil),
                                                 comment);
    }
    

    What this will do is search a file called OverrideLocalizable.strings for the key. If the value for key is not found in OverrideLocalizable.strings, it will search localizable.strings for key. NSLocalizedString(key, nil) by default will search localizable.strings

    Pretty simple and elegant solution