本文介绍了覆盖基本的localizable.strings文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法为一个项目中的多个目标提供一个基本的localizable.strings文件,并为每个目标提供第二个localizable.strings文件,以覆盖单个值并将其附加到基本文件中?

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?

编辑

我希望我的应用具有两个.strings文件-Localizable.string和Override.strings.如果在OverrideLocalizable.strings中找不到字符串Title.Welcome,那么我希望该应用程序在Localizable.strings中搜索Title.Welcome.本质上,将Localizable指定为后备,但默认情况下使用OverrideLocalizable.strings.

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.

推荐答案

这是我找到的解决方案:

Here is the solution I found:

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

这将在名为OverrideLocalizable.strings的文件中搜索key.如果在OverrideLocalizable.strings中找不到key的值,它将在localizable.strings中搜索key. NSLocalizedString(key, nil)默认情况下将搜索localizable.strings

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

这篇关于覆盖基本的localizable.strings文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 01:42