对于每种配置,我们使用带有不同插件的设置.像这样: Target-Info-Dev.plist,Target-Info-Beta.plist ...
这样,我们的配置可以拥有自己的CFBundleDisplayName,并且可以通过设备上的应用程序名称来区分构建.像这样:"DEV Appname","BETA Appname" ...
但是,现在我们需要本地化应用名称.为此,我们为每个目标创建了本地化的InfoPlist.strings:
"CFBundleDisplayName" = "<localized-appname>"; "CFBundleName" = "<localized-appname>";但是,由于CFBundleDisplayName不再是从 Target-Info- [Configuration] .plist 派生的,因此我们无法区分不同配置的应用程序名称.
应该注意的是,对于同一个应用程序的不同品牌,我们也有几个 Targets ,但是我们已经通过为每个目标都有一个单独的InfoPlist.strings来实现了这一目标. >
有人知道如何完成本地化和基于配置的应用程序名称吗?
解决方案更好的解决方案
在构建项目时,Info.plist中的每个变量都将替换为其值.
该解决方案比原始解决方案简单得多.
原始解决方案我在项目中有相同的要求,然后找到了您的问题,最后我解决了. 编辑您的项目方案,添加操作前和操作后脚本以执行更改.像这样
第1步.在Build的预操作中更改应用名称
str="" if [ "${CONFIGURATION}" == "Debug" ];then str="dev" elif [ "${CONFIGURATION}" == "AdhocDevelopment" ];then str="dev" elif [ "${CONFIGURATION}" == "AdhocDistribution" ];then str="adhoc" elif [ "${CONFIGURATION}" == "DailyBuild" ];then str="rdm" fi perl -pi -e "s/appName[^<]*/appName${str}/g" ${PROJECT_DIR}/smd/Info.plist
第2步.在Build的后续操作中恢复应用名称
perl -pi -e "s/appName[^<]*/appName/g" ${PROJECT_DIR}/smd/Info.plist echo ${PROJECT_DIR}/${INFOPLIST_FILE} > ~/tmp.txt; rm -f ~/tmp.txt需要说明的地方:Debug/AdhocDevelopment/AdhocDistribution/DailyBuild是您的项目的配置名称; $ {CONFIGURATION}由Xcode预先定义; perl比awk和sed更可取,因为awk和sed都已预先安装在每个mac OS X上.
顺便说一句,我所做的就是更改Info.plist中的appName,您可以更改infoPlist.strings.这样,您只需要一个Info.plist文件.
We use a setup with different plists for each configuration. Like this: Target-Info-Dev.plist, Target-Info-Beta.plist...
This way our configurations could have their own CFBundleDisplayName, and we can differentiate builds by app-name on device. Like this: "DEV Appname", "BETA Appname"...
However, now we are required to localize the app-name. We have done this by creating a localized InfoPlist.strings for each target:
"CFBundleDisplayName" = "<localized-appname>"; "CFBundleName" = "<localized-appname>";But since the CFBundleDisplayName is no longer derived from Target-Info-[Configuration].plist, we cannot differentiate the app-name for different configurations.
It should be noted that we have several Targets as well, for different brands of the same app, but we already got that working by haveing a separate InfoPlist.strings for each target.
Anybody have an idea of how to accomplish both localized and configuration-based app-name?
解决方案Better Solution
When building your project, every variable in the Info.plist will be replaced to its value.
The solution is much simpler than the original one.
Original SolutionI had the same requirement in my project, and then I found your question, and at last I solved it. Edit your projects' scheme, add pre-action and post-action script to execute your change. Like this,
Step 1. change app name in Build's Pre-actions
str="" if [ "${CONFIGURATION}" == "Debug" ];then str="dev" elif [ "${CONFIGURATION}" == "AdhocDevelopment" ];then str="dev" elif [ "${CONFIGURATION}" == "AdhocDistribution" ];then str="adhoc" elif [ "${CONFIGURATION}" == "DailyBuild" ];then str="rdm" fi perl -pi -e "s/appName[^<]*/appName${str}/g" ${PROJECT_DIR}/smd/Info.plistStep 2. Restore app name in Build's Post-actions
perl -pi -e "s/appName[^<]*/appName/g" ${PROJECT_DIR}/smd/Info.plist echo ${PROJECT_DIR}/${INFOPLIST_FILE} > ~/tmp.txt; rm -f ~/tmp.txtSomething to explain: Debug/AdhocDevelopment/AdhocDistribution/DailyBuild are your projects' configuration names; ${CONFIGURATION} is predefined by Xcode; perl is preferable to awk and sed, which are all pre-installed on every mac OS X.
By the way, what I have done is changing appName in Info.plist, you can change your infoPlist.strings. In this way, you just need a single Info.plist file.
更多推荐
在InfoPlist.strings中本地化应用名称时,取决于配置的不同应用名称
发布评论