Skip to content

Instantly share code, notes, and snippets.

@Draknek
Created January 31, 2025 12:19
Show Gist options
  • Save Draknek/61e18a32a72dc1dc13544c138a402214 to your computer and use it in GitHub Desktop.
Save Draknek/61e18a32a72dc1dc13544c138a402214 to your computer and use it in GitHub Desktop.
Unity iOS builds need to contain the list of supported localisations
// Taken from https://discussions.unity.com/t/defining-localization-language-for-an-ios-app/779425/6
// Not personally tested.
// The list of supported languages is hard-coded into the CFBundleLocalizations function.
#if UNITY_IOS
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public static class iOSPostBuildLocalization
{
[PostProcessBuild(int.MaxValue)]
static void OnBuildDone(BuildTarget target, string pathToBuiltProject)
{
ModifyInfoPList(pathToBuiltProject);
}
static void ModifyInfoPList(string pathToBuiltProject)
{
string path = pathToBuiltProject + "/info.plist";
var plist = new PlistDocument();
plist.ReadFromFile(path);
var root = plist.root;
CFBundleLocalizations(root);
plist.WriteToFile(path);
}
static void CFBundleLocalizations(PlistElementDict root)
{
var rootDic = root.values;
var localizations = new string[]{"en","fr"};
var array = root.CreateArray("CFBundleLocalizations");
foreach (var localization in localizations) array.AddString(localization);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment