具有多个目标的本地化项目和本地化的应用程序名称 [英] Localized project with several targets with localized app names

查看:23
本文介绍了具有多个目标的本地化项目和本地化的应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的 5 个独立项目合并到一个项目中,以拥有一个共同的代码库.所以现在我有一个项目有 5 个目标.

每个目标都有相同的文件集,除了每个目标不同的一些文件(例如 Default.png 和图标文件等).我的应用程序被翻译成 7 种语言,默认为英语.其他语言是:瑞典语、荷兰语、德语、法语、波兰语和西班牙语.
现在我还想根据使用的语言翻译应用程序的名称.例如,对于我的瑞典航空应用程序,该应用程序在瑞典语中应称为Flyget ARN",但在英语中应称为Aviation ARN".所有这一切都不是问题,因为这是在 InfoPlist.string 中完成的,但是将其与应用程序的本地化结合起来是一个问题.

我最近写了这个问题:几个本地化但仍然只显示英语 并发现我无法合并多个 .strings 文件.(见我写的答案).

所以我的问题如下:
如何从包含多个目标的项目中获得本地化应用程序,并本地化我的应用程序名称而不会出现 DRY 违规(重复代码).

更新
这仍然是一个问题,给出的答案并没有解决我的问题.

解决方案

我在一个 XCode 项目中解决了这个问题,我相信它可以解决与您相同的问题,所以希望这会对您有所帮助.该解决方案包含两个从相同代码库构建的目标(具有不同的应用程序名称)并且完全本地化,包括应用程序的名称.(它构建了我的免费增值应用程序,名为 Growth(法语:Croissance,西班牙语:Crecer)和名为 Growth+ 的付费版本>(法语:Croissance+,西班牙语:Crecer+).

我还偶然发现了 InfoPlist.string 文件(其中仅包含应用程序的名称).我通过在我的解决方案中使用子文件夹解决了这个问题,并更改了目标以包含相关子文件夹中的本地化 InfoPlist.strings 集.具体来说,我有这样的结构:

<上一页>根+-- 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 下的 InfoPlist.strings 文件,而 AppB 的构建设置包括 OnlyInAppB 下的 InfoPlist.strings 文件.

在我个人看来,我使用的命名约定(OnlyInAppA/OnlyInAppB 文件夹、AppB/AppB plist 文件)非常明显,足以让这成为一种令人满意的方法.

请查看这两个 XCode 4 屏幕截图,看看在哪里可以找到目标中更改的设置.

  1. 在目标构建设置中,指定了不同的 plist 文件(注意:当您添加新目标时,XCode 会自动为您执行此操作)

  2. 在目标构建阶段,在 Copy Bundle Resources 部分,从相关的 OnlyInAppX 子文件夹中选择 InfoPlist.strings 的版本(请注意此屏幕截图中 InfoPlist.strings 旁边的灰色文本 - 这将显示不同的另一个目标的位置).您可以通过使用 +/- 按钮并将文件替换为预期的文件来实现此目的.

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.

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.

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).

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.

解决方案

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+).

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

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.

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.

Edit:

Please see these two XCode 4 screenshots to see where exactly to find the settings which are changed in the targets.

  1. In the target build settings, a different plist file is specified (note: XCode automatically does this for you when you add a new target)

  2. 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.

这篇关于具有多个目标的本地化项目和本地化的应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆