iOS permission localization at PostProcessBuild

We needed localization of ios permissions (such as NSUserTrackingUsageDescription, NSLocationWhenInUseUsageDescription, etc.). This does not cause problems directly from xcode. You need to create a file InfoPlist.strings, select the required localizations for it and set the localization keys with translate.

But I need to do it automatically at the PostProcessBuild stage. I tried to take directly created localization directories (such as en.lproj) and then add them to the project using
PBXProject.AddFile and AddFileToBuild. But in this case they are added not as InfoPlist.strings, but as just “en.lproj” folders, etc. Maybe someone has done something similar. Help me please.

Should be something like

string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(plistPath);

PlistElementDict rootDict = plist.root;

rootDict.SetString("NSPhotoLibraryUsageDescription", "This app requires access ...");
File.WriteAllText(plistPath, plist.WriteToString());

In this case, the description of the permission will not be localized.

You have to add your own localization system there since Unity currently doesn’t have localization system build-in.

Look at great example https://github.com/superbderrick/UnityiOSLocalization

1 Like