Created
January 31, 2025 12:19
-
-
Save Draknek/61e18a32a72dc1dc13544c138a402214 to your computer and use it in GitHub Desktop.
Unity iOS builds need to contain the list of supported localisations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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