Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS应用程序测试本地化翻译是否具有相同的密钥_Ios_Swift_Xcode_Shell_Localization - Fatal编程技术网

iOS应用程序测试本地化翻译是否具有相同的密钥

iOS应用程序测试本地化翻译是否具有相同的密钥,ios,swift,xcode,shell,localization,Ios,Swift,Xcode,Shell,Localization,在我的iOS应用程序中,我有本地化文件,如Localizable.strings。 我想检查他们是否有相同的钥匙,并且在每个本地化中没有遗漏钥匙 我考虑过在单元测试中执行这个 单元测试是否适合这种情况?也许有更简单的工具 如何进行单元测试 我在5年前的Obj-C中找到了关于这个主题的文章。也许可以使用其他东西?你可以使用这个shell脚本我编写的脚本,作为你的应用目标的运行脚本(在构建阶段) 首先,创建shell脚本并将其保存在应用程序项目中的某个位置,我将其保存为check_missing_k

在我的iOS应用程序中,我有本地化文件,如Localizable.strings。 我想检查他们是否有相同的钥匙,并且在每个本地化中没有遗漏钥匙

我考虑过在单元测试中执行这个

  • 单元测试是否适合这种情况?也许有更简单的工具
  • 如何进行单元测试
    我在5年前的Obj-C中找到了关于这个主题的文章。也许可以使用其他东西?

    你可以使用这个shell脚本我编写的脚本,作为你的应用目标的运行脚本(在构建阶段)

    首先,创建shell脚本并将其保存在应用程序项目中的某个位置,我将其保存为check_missing_keys_in_translations.sh,例如:

    #!/bin/sh
    
    #  check_missing_keys_in_translations.sh
    #
    #  Overview: Script will be executed from Build Phases > Run Script
    #
    #  Script: Extract sorted localization keys using "$1" as language code
    #  given as parameter to locate the right Localizable.strings.
    #
    #  Build Phases > Run Script: The result will be compared to see if 
    #  translations have the same keys or if one of them have more or less.
    
    plutil -convert json 'AppProject/Resources/Localization/'"$1"'.lproj/Localizable.strings' -o - | ruby -r json -e 'puts JSON.parse(STDIN.read).keys.sort'
    
    只需将路径
    AppProject/Resources/Localization/
    更改为您的
    en.lproj
    it.lproj
    。。。本地化文件夹位于您的应用程序中(在本例中称为
    AppProject

    其次,转到应用程序项目,选择应用程序目标,并在构建阶段下将此脚本代码放入运行脚本中:

    # Check missing localization keys in translations
    MISSING_KEYS_TRANSLATIONS=$(diff <($SRCROOT/tools/localization/check_missing_keys_in_translations.sh en) <($SRCROOT/tools/localization/check_missing_keys_in_translations.sh it))
    if [ "$MISSING_KEYS_TRANSLATIONS" ]; then
    echo "warning: $MISSING_KEYS_TRANSLATIONS"
    fi
    
    #检查翻译中缺少的本地化键
    
    缺少_KEYS_TRANSLATIONS=$(不同的是,我认为在每次构建之前运行shell脚本是一种更好的检查方法