在InfoPlist.strings中本地化应用名称时,取决于配置的不同应用名称 [英] Different app-name depending on configuration when app-name is localized in InfoPlist.strings

查看:610
本文介绍了在InfoPlist.strings中本地化应用名称时,取决于配置的不同应用名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于每种配置,我们使用带有不同插件的设置.像这样: 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来实现了这一目标. >

有人知道如何完成本地化和基于配置的应用程序名称吗?

解决方案

更好的解决方案

  1. 编辑 Info.plist ,将CFBundleDisplayName的值设置为名为$(MY_DISPLAY_NAME)
  2. 之类的变量

  1. 打开项目 target 构建设置" 选项卡,在 User-Defined(用户定义)下添加一个名为MY_DISPLAY_NAME的键. 部分(您需要滚动到底部才能找到此部分),然后只需展开新添加的键,然后根据需要为每种配置设置任何名称.

在构建项目时,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

  1. Edit Info.plist, set CFBundleDisplayName's value to a variable named something like $(MY_DISPLAY_NAME)

  1. Open 'Build Settings' tab of the project or target, add a key named MY_DISPLAY_NAME under User-Defined section(you need scroll to the bottom to find this section), then just expand the newly-added key, and set any name for each configuration as you wish.

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 Solution

I 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.plist

Step 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.txt

Something 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中本地化应用名称时,取决于配置的不同应用名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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