How to add InfoPlist.strings into xcode project in script?

I know Unity has class PBXProject, it can modify xcode project, but when adding InfoPlist.strings, file will be added as a normal file.
Thus, it doesn't work. I need this file to localize product name.

Hello,
PBXProject API does not support adding strings localization files yet.

Are there any plans to support this feature or any 3rd party alternatives? With iOS 10 forcing us to give a description when using device features like NSCameraUsageDescription, it would be a pain to always have to manually re-enter the localization of these strings for each build we make.

1 Like

I second this! It'd be really useful to have the ability to localize these settings if possible. I suppose it depends on your localization implementation, but I'd imagine there are some limitations on this because of the way Apple wants you to handle localizing this text.

Until then, if anyone's interested, here's my solution:

I have a build step that will copy all of the localization folders (en.lproj, fr.lproj, es.lproj, etc...) into the build's folder and I drag and drop each and every individual InfoPlist.strings into the Xcode project to add the localization. Doing a mass drag&drop will either crash Xcode or corrupt it so the project no longer builds anymore. It's tedious but it works.

Hey. Is this somewhere on the horizon maybe? Would be pretty nice to avoid all those python postbuild scripts as workarounds.

btw: Ok, I see that you already approved the pull request here: https://bitbucket.org/Unity-Technologies/xcodeapi/pull-requests/13/creation-of-variantgroup-and/diff
Do you know when it will be merged into the release version? I can live for now with modifying my code, but it would be great to have it in the engine for all of us.

as pahe said

so, when it will be merged?

3 Likes

Can we bump this? I would really like to see that PR merged as well, and it's been 3 years...

Hi! Ten years have passed. Has anything changed yet?

1 Like

Hey, Unity? :)

1 Like

This would be a useful addition with the advent of Apple's iOS 14 tracking changes - so that we can easily localise our custom message on the popup without needing manual steps.

6179151--676662--Screenshot 2020-08-05 at 10.20.26.png

2 Likes

I managed to get it working.

I have the .strings files in my project.

6180351--676878--Screenshot 2020-08-07 at 17.03.06.png

And I call this for each one.

        guid = project.AddFolderReference(Application.dataPath + "/Editor/Localisations/en.lproj", "en.lproj");
        project.AddFileToBuild(targetGuid, guid);

Then I end up with this in my Xcode project.

6180351--676881--Screenshot 2020-08-07 at 17.06.06.png

And when running on device with one of the languages set, I get the message I want.

9 Likes


Did you have any problem with contents of those InfoPlist.strings files? Weird but mines are empty inside Xcode Project.

1 Like

Not that I can recall.


Just to be sure your string file is like this;

/* Localized versions of Info.plist keys */

"NSUserTrackingUsageDescription" = "Your data will be used to deliver personalized ads to you.";

Not like this;

/* Localized versions of Info.plist keys */

Am I really the only one facing this?

I don't have double quotes around the key.

/* Localized versions of Info.plist keys */

NSUserTrackingUsageDescription = "german";

These seem empty for me as well in Xcode, but they do appear in Xcode, just empty. I used the version provided by @andymads without double quotes for the key.

Did @kdeger manage to found a solution for this?


I managed to make it work with @andymads ' help.

As mentioned above put your.lproj files in your project, call a method something like this inside PostProcessBuild function

        string sPath = PBXProject.GetPBXProjectPath(path);
        var project = new PBXProject();
        project.ReadFromString(File.ReadAllText(sPath));

        string targetMainGuid;
        string targetFrameworkGuid;

#if UNITY_2019_3_OR_NEWER
        targetFrameworkGuid = project.GetUnityFrameworkTargetGuid();
        targetMainGuid = project.GetUnityMainTargetGuid();
#else
        targetFrameworkGuid = project.TargetGuidByName("Unity-iPhone");
#endif
        for (int i = 0; i < localizationFolderNames.Length; i++)
        {
            var guid = project.AddFolderReference(Application.dataPath + string.Format("/Editor/Localizations/{0}.lproj", localizationFolderNames[i]), string.Format("{0}.lproj", localizationFolderNames[i]), PBXSourceTree.Source);
#if UNITY_2019_3_OR_NEWER
            project.AddFileToBuild(targetMainGuid, guid);
#endif
            project.AddFileToBuild(targetFrameworkGuid, guid);
        }

        project.WriteToFile(sPath);

On Xcode the files should appear something like this on the screenshot, also don't forget to add the relevant localizations to your project, otherwise you can't validate and distribute the app to appstore (and get rid of the deprecated ones too if you have any).

7046881--835717--Screen Shot 2021-04-16 at 16.40.24.jpg

I’m trying to get this working too, what do you mean by adding ghe relevant localizations? Is this a setting in Unity? The only thing i can find about localization in unity is a preview package.

Hello. I add localization according to your code, but it does not appear in the project info in xcode. Did you add them manually?

7140602--854036--Xnip2021-05-14_16-19-28.jpg