Override a base localizable.strings file

谁说我不能喝 提交于 2019-12-04 15:43:17

问题


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.


回答1:


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




回答2:


For swift 4 users that come across this issue...

    func get_overridable_string_for_key(string_key: String)-> String{
    return NSLocalizedString(string_key, tableName: "OverrideLocalizable", bundle: Bundle.main, value: NSLocalizedString(string_key, comment: ""), comment: "");
}


来源:https://stackoverflow.com/questions/23063096/override-a-base-localizable-strings-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!