xcode 具有多个具有本地化应用程序名称的目标的本地化项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10523792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Localized project with several targets with localized app names
提问by Paul Peelen
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.
我最近将我的 5 个独立项目合并到一个项目中,以拥有一个通用的代码库。所以现在我有一个有 5 个目标的项目。
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.
每个目标都有相同的文件集,除了每个目标不同的一些文件(例如 Default.png 和图标文件等)。我的应用程序被翻译成 7 种语言,默认是英语。其他语言是:瑞典语、荷兰语、德语、法语、波兰语和西班牙语。
现在我还想根据使用的语言翻译应用程序的名称。例如,对于我的瑞典航空应用程序,该应用程序在瑞典语中应称为“Flyget ARN”,而对于英语应用程序应称为“Aviation ARN”。所有这些都不是问题,因为这是在 中完成的InfoPlist.string
,但是将其与应用程序的本地化相结合是一个问题。
I recently wrote this question: Several localizations yet still showing English onlyand found out that I cannot combine several .strings files. (see the answer I wrote).
我最近写了这个问题:几个本地化但仍然只显示英语,发现我不能组合几个 .strings 文件。(见我写的答案)。
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).
所以我的问题如下:
如何从包含多个目标的项目中获得本地化应用程序,并在没有 DRY 违规(重复代码)的情况下本地化我的应用程序名称。
Update
This is still an issue, the answers given do not solve my problem.
更新
这仍然是一个问题,给出的答案不能解决我的问题。
采纳答案by Clafou
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+).
我在一个 XCode 项目中破解了这个问题,我相信它解决了与您相同的问题,所以希望这会对您有所帮助。该解决方案包含从同一代码库(具有不同的应用程序名称)构建的两个目标,它们是完全本地化的,包括应用程序的名称。(它建立打电话给我免费增值应用增长(法语:Croissance:,西班牙Crecer)和被叫付费版增长+(法语:Croissance +,西班牙语:Crecer +)。
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:
我还偶然发现了这些InfoPlist.string
文件(其中只包含应用程序的名称)。我通过在我的解决方案中使用子文件夹解决了这个问题,并将目标更改为包含来自相关子文件夹的本地化的 InfoPlist.strings 集。具体来说,我有这个结构:
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
And the only difference among my targets (other than different preprocessor symbols and different .plist file) is that AppA's build settings includes the InfoPlist.strings files under OnlyInAppA, whereas AppB's build settings includes the InfoPlist.strings files under OnlyInAppB.
我的目标之间的唯一区别(除了不同的预处理器符号和不同的 .plist 文件)是 AppA 的构建设置包括 OnlyInAppA 下的 InfoPlist.strings 文件,而 AppB 的构建设置包括 OnlyInAppB 下的 InfoPlist.strings 文件。
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.
在我个人看来,我使用的命名约定(OnlyInAppA/OnlyInAppB 文件夹、AppB/AppB plist 文件)很明显足以使这成为一种令人满意的方法。
Edit:
编辑:
Please see these two XCode 4 screenshots to see where exactly to find the settings which are changed in the targets.
请查看这两个 XCode 4 屏幕截图,以查看在目标中更改设置的确切位置。
In the target build settings, a different plist file is specified (note: XCode automatically does this for you when you add a new target)
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.
在目标构建设置中,指定了不同的 plist 文件(注意:当您添加新目标时,XCode 会自动为您执行此操作)
在目标构建阶段,在 Copy Bundle Resources 部分,从相关的 OnlyInAppX 子文件夹中选择 InfoPlist.strings 的版本(注意此屏幕截图中 InfoPlist.strings 旁边的灰色文本——这将显示另一个目标的不同位置) . 您可以通过使用 +/- 按钮并用预期的文件替换文件来实现这一点。
回答by Wladek Surala
If this problem still persist: I have found a solution on how to add multiple InfoPlist.string localized for each target in your project. Please follow these steps:
如果此问题仍然存在:我已找到有关如何为项目中的每个目标添加多个本地化的 InfoPlist.string 的解决方案。请按照以下步骤操作:
- I assume you already have multiple targets.
- Go to the project folder in Finder.
Create a folder specific for each target:
Create an InfoPlist.strings file in each folder:
Add folders to targets specifyingproper (and only!) target for each folder in your project:
Remove target dependency for original InfoPlist.strings file for each new target.
Localize new InfoPlist.strings files:
Build targets and check by changing language settings:
- 我假设您已经有多个目标。
- 转到 Finder 中的项目文件夹。
为每个目标创建一个特定的文件夹:
在每个文件夹中创建一个 InfoPlist.strings 文件:
将文件夹添加到目标,为项目中的每个文件夹指定正确(且唯一!)的目标:
为每个新目标删除原始 InfoPlist.strings 文件的目标依赖项。
本地化新的 InfoPlist.strings 文件:
构建目标并通过更改语言设置进行检查:
回答by Ken Thomases
Just keep all the InfoPlist.strings files, under separate paths. Each would only be a member of one target.
只需将所有 InfoPlist.strings 文件保存在不同的路径下即可。每个人都只能是一个目标的成员。
Or did I not understand the question?
还是我没看懂问题?
回答by John
I have a similar setup where my the same software supports multiple domains, each domain accesses the exact same paths for various modules (e.g. blog, forums). In order to retain individuality per domain especially when the database service becomes unavailable I retain critical information in files, basically meta information. For localization I would keep a variable retaining each site/project's default language. You could determine the files containing the information to have their own domain or store all the projects in the same file, either way you would want to use that for your ultimate fallback or if you simply lack further public options to any/everyone with lower permissions than you until you implement such options (users being able to override the language option).
我有一个类似的设置,其中我的相同软件支持多个域,每个域访问各种模块(例如博客、论坛)的完全相同的路径。为了保留每个域的个性,尤其是当数据库服务不可用时,我将关键信息保留在文件中,基本上是元信息。对于本地化,我会保留一个变量来保留每个站点/项目的默认语言。您可以确定包含信息的文件拥有自己的域或将所有项目存储在同一文件中,无论您希望将其用于最终后备,还是只是缺少对任何/每个人具有较低权限的进一步公共选项直到您实现此类选项(用户可以覆盖语言选项)。
回答by john.k.doe
i have been doing exactly this for my apps.
我一直在为我的应用程序做这件事。
as i change the default language for the phone, it properly picks up the names in each of my infoPlist.strings files.
当我更改手机的默认语言时,它会正确选取我的每个 infoPlist.strings 文件中的名称。
but i did this from scratch. i don't know if you will have to back up to get the behavior you want. perhaps save aside your various infoPlist.strings files from any localization folders, then perform the following steps, and then re-insert your contents from your current infoPList.strings files into your newly created files from the following steps.
但我是从头开始做的。我不知道你是否需要备份才能获得你想要的行为。也许从任何本地化文件夹中保存您的各种 infoPlist.strings 文件,然后执行以下步骤,然后通过以下步骤将您当前 infoPList.strings 文件中的内容重新插入到您新创建的文件中。
i am using Xcode 4.3 . the steps:
我正在使用 Xcode 4.3。步骤:
1) set up the strings you want in for your default language in info-plist.strings. you should end up with a single file:
1) 在 info-plist.strings 中为您的默认语言设置您想要的字符串。你应该最终得到一个文件:
2) now, open up the File Inspector
2)现在,打开文件检查器
3) in the inspector on the far right, you can now click the + sign at the bottom of the navigator:
3) 在最右侧的检查器中,您现在可以单击导航器底部的 + 号:
4) once you've chosen your language(s) of interest, they'll show up in your project navigator on the left as follows:
4) 一旦您选择了您感兴趣的语言,它们将显示在您左侧的项目导航器中,如下所示:
you also can do this for Localizable.strings and other files (such as the index.html in the following example photo):
您也可以对 Localizable.strings 和其他文件(例如以下示例照片中的 index.html)执行此操作:
回答by CReaTuS
Try see a iTunesConnect_DeveloperGuide
尝试查看iTunesConnect_DeveloperGuide
and see a "Adding a New Localization"
并查看“添加新的本地化”
Here you can write a Localized app name for each language
您可以在此处为每种语言编写本地化应用程序名称