Localize iOS app name in Unity

I am creating a Unity3D game that shows a different (localized) application name on the iPhone home screen according to the user's local language. Note:

  • I already know how to localize the iOS app name by editing the Xcode project (create a file InfoPlist.string

    , localize it, add a key to it CFBundleDisplayName

    , etc.)

  • I also know how to automatically localize the name of an Android app in the Unity editor (add a file values-XX.xml

    with a property app_name

    to a folder Assets/Plugins/Android/res/

    , etc.)

Question: How can I automatically localize the iOS app name in Unity Editor so that I don't have to do a consistent 1. task every time I build a project?

I think there PostprocessBuildPlayer

must be a way to go, however I haven't found any documentation on how to parse it properly and / or modify the Xcode project file to achieve this.

+3


source to share


1 answer


A long time ago I had problems when I tried to modify info.plist through the Build Player Pipeline, especially when I do it in Append mode. It only works once, and then subsequent builds fail: "The data cannot be read because it is not in the correct format." (s. Unity forum posts such as this and my blog post about this issue) So I decided to use an alternative way of combining a custom build with an Xcode pre-build action.

Three steps are required:

(1) Xcode setup:

In Xcode, go to the Edit Schematic / Assembly / Preliminary Steps section. Then click the + sign to add a New Run Script action.

  • In the build settings, select Unity-iPhone.
  • Insert . ${PROJECT_DIR}/modify_info_plist.sh

    (note the period and space at the beginning, this will ensure the Script is executed in the caller's shell)

So it should look like this: Xcode screenshot

(2) Script modify_info_plist.sh:

In your Script, you have access to all environment variables from Xcode (s. Xcode setting link ) and you can manipulate the .plist information with the command defaults

( man page ). Here's the example I used to add gyroscope

to UIRequiredDeviceCapabilities

:



# Code snippet used in Unity-iPhone scheme as "Build Pre-Action"

my_domain=${PROJECT_DIR}/Info.plist
status_bar_key=UIViewControllerBasedStatusBarAppearance

logger "Start adding keys to info.plist"
defaults write $my_domain $status_bar_key -boolean NO

if [ `defaults read $my_domain UIRequiredDeviceCapabilities | grep "gyroscope" | wc -l` = "0" ]; then
    defaults write $my_domain UIRequiredDeviceCapabilities -array-add  "gyroscope"
fi
logger "Keys added to info.plist successfully"

      

(3) Assembling the pipeline:

Place the following code in your static editor class to create a new Tools / My iOS Build menu item with a cmd+ alt+ shortcut b:

static string IOSBuildDir= "Develop";

[MenuItem("Tools/My iOS Build %&b")]
public static void IOSBuild () {
    string[] levels = { "Assets/Scenes/Boot.unity",
        "Assets/Scenes/Level-1.unity",
        // ...
        "Assets/Scenes/Menu.unity"
    };
    string path = Directory.GetCurrentDirectory ();
    path += "/" + IOSBuildDir + "/Info.plist";
    if (File.Exists (path)) {
        Debug.Log ("Removing file " + path);
        File.Delete (path);
    }
    BuildPipeline.BuildPlayer (levels, "Develop", BuildTarget.iPhone, 
        BuildOptions.AcceptExternalModificationsToPlayer);
}

      


I know this is not a perfect solution, but it is the only one that I have found stable. Two disadvantages:

  • Step (1) should be repeated after changing major Xcode format changes.
  • New scenes must be added to the editor class code in step (3)
+1


source







All Articles