在InfoPlist.strings中本地化应用名称时,取决于配置的不同应用名称

编程入门 行业动态 更新时间:2024-10-27 16:33:10
本文介绍了在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来实现了这一目标. >

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

解决方案

更好的解决方案

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

  • 打开项目或 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

  • Edit Info.plist, set CFBundleDisplayName's value to a variable named something like $(MY_DISPLAY_NAME)
  • 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中本地化应用名称时,取决于配置的不同应用名称

    本文发布于:2023-11-04 10:29:54,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1557686.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:名称   InfoPlist   strings

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!