问题描述
我最近将我的5个独立项目合并到一个项目中,以拥有一个共同的代码库。所以现在我有一个项目有5个目标。
I have recently merged together 5 of my stand-alone projects into one project to have a common code base. So now I have one project with 5 targets instead.
除了每个目标不同的一些文件(例如Default.png和图标文件等)。
我的应用程序被翻译成7种语言,默认为英语。其他语言包括:瑞典语,荷兰语,德语,法语,波兰语和西班牙语。
现在我还要根据使用的语言翻译应用程序的名称。
例如,对于我的瑞典航空应用程序,应用程序应该在瑞典语中称为Flyget ARN,但对于英语,它应该被称为航空ARN。
所有这些都不是问题,因为这是在 InfoPlist.string
中完成的,但是将其与应用程序的本地化相结合是一个问题。
Each target has the same fileset, except for some files which differ for each target (such as Default.png, and icons files amongst others).My application is translated to 7 languages with English as default. The other languages are: Swedish, Dutch, German, French, Polish and Spanish.
Now I would also like to translate the name of the application depending the language used.For instance, for my Swedish aviation app, the app should be called "Flyget ARN" in Swedish, but for English it should be called "Aviation ARN".All this is not a problem since this is done in the InfoPlist.string
, however combining this with the localization of the app Is a problem.
我最近写了这个问题:并发现我无法合并多个.strings文件。 (见我写的答案)。
I recently wrote this question: Several localizations yet still showing English only and found out that I cannot combine several .strings files. (see the answer I wrote).
所以我的问题如下:
如何从包含多个目标的项目中获得本地化应用程序,并且还可以本地化我的应用程序名称违反DRY(重复代码)。
So my question is the following:
How can I have a localized app from a project containing several targets and also localize my applications name without having a DRY-violation (Duplicate code).
更新
这是仍然是一个问题,给出的答案并没有解决我的问题。
Update
This is still an issue, the answers given do not solve my problem.
推荐答案
我在一个XCode项目中破解了这个问题,我相信,解决与您相同的问题,希望这对您有所帮助。该解决方案包含两个使用相同代码库(具有不同的应用程序名称)构建的目标,这两个目标是完全本地化的,包括应用程序的名称。 (它构建我的免费增值应用程序,名为增长(法语: Croissance ,西班牙语: Crecer )和付费版本,名为 Growth + (法语: Croissance + ,西班牙语: Crecer + )。
I cracked this nut in an XCode project which, I believe, tackles the same issue as you have, so hopefully this will help you. The solution contains two targets built from the same codebase (with a different app name) and which are fully localized, including the app's names. (It builds my freemium app called Growth (French: Croissance, Spanish: Crecer) and the paid version called Growth+ (French: Croissance+, Spanish: Crecer+).
我偶然发现 InfoPlist.string
文件(仅包含应用程序的名称)。我通过在我的解决方案中使用子文件夹解决了这个问题,并更改了目标以包含来自的解决方案的本地化InfoPlist.strings集。相关的子文件夹。具体来说,我有这样的结构:
I also stumbled on the InfoPlist.string
files (which contain only the app's name). I got around the issue through the use of subfolders in my solution, and changing the targets to include the localized set of InfoPlist.strings from the relevant subfolder. Specifically, I have this structure:
Root
+-- en.lproj
¦ +-- Localizable.strings
¦ +-- SomeXib.xib
+-- es.lproj
¦ +-- Localizable.strings
¦ +-- SomeXib.xib
+-- fr.lproj
¦ +-- Localizable.strings
¦ +-- SomeXib.xib
+-- OnlyInAppA
¦ +-- en.lproj
¦ ¦ +-- InfoPlist.strings
¦ +-- es.lproj
¦ ¦ +-- InfoPlist.strings
¦ +-- fr.lproj
¦ +-- InfoPlist.strings
+-- OnlyInAppB
¦ +-- en.lproj
¦ ¦ +-- InfoPlist.strings
¦ +-- es.lproj
¦ ¦ +-- InfoPlist.strings
¦ +-- fr.lproj
¦ +-- InfoPlist.strings
+-- AppA.plist
+-- AppB.plist
我的目标之间的唯一区别(其他比不同的预处理器符号和不同的.plist文件)是AppA的构建设置包含OnlyInAppA下的Info.Plist.strings文件,而AppB的构建设置包括OnlyInAppB下的Info.Plist.strings文件。
And the only difference between my targets (other than different preprocessor symbols and different .plist file) is that AppA's build settings includes the Info.Plist.strings files under OnlyInAppA, whereas AppB's build settings includes the Info.Plist.strings files under OnlyInAppB.
我个人认为,我使用的命名约定(OnlyInAppA / OnlyInAppB文件夹,AppB / AppB plist文件)非常明显,使其成为一种令人满意的方法。
The naming convention I used (OnlyInAppA/OnlyInAppB folders, AppB/AppB plist files) is obvious enough to make this a satisfactory approach, in my personal opinion.
修改
请参阅这两个XCode 4屏幕截图,看看究竟要找到哪些设置已更改目标。
Please see these two XCode 4 screenshots to see where exactly to find the settings which are changed in the targets.
-
在目标构建设置中,指定了不同的plist文件(注意:XCode会自动执行此操作当你添加一个新目标时你)
In the target build settings, a different plist file is specified (note: XCode automatically does this for you when you add a new target)
在目标构建阶段,在Copy Bundle Resources部分中,从相关的OnlyInAppX子文件夹中选择InfoPlist.strings的版本(请注意此屏幕截图中InfoPlist.strings旁边的灰色文本 - 这将是显示另一个目标的不同位置)。您可以使用+/-按钮将文件替换为预期的文件来实现此目的。
In the target build phases, in section Copy Bundle Resources, pick the version of InfoPlist.strings from the relevant OnlyInAppX subfolder (notice the gray text next to InfoPlist.strings on this screenshot--this will show a different location for the other target). You can achieve this by using the +/- buttons and replace the file with the intended one.
这篇关于具有本地化应用名称的多个目标的本地化项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!