/// <summary> /// Updates the Xcode project file with localized values using <see cref="AppInfo"/>. /// </summary> /// <param name="projectDirectory">The root project directory to be updated. This is where the iOS player was built to.</param> /// <param name="appInfo">Contains the localized values for the App.</param> public static void AddLocalizationToXcodeProject(string projectDirectory, AppInfo appInfo) { if (appInfo == null) { throw new ArgumentNullException(nameof(appInfo)); } var pbxPath = PBXProject.GetPBXProjectPath(projectDirectory); var project = new PBXProject(); project.ReadFromFile(pbxPath); project.ClearKnownRegions(); // Remove the deprecated regions that get added automatically. var plistDocument = new PlistDocument(); var plistPath = Path.Combine(projectDirectory, "Info.plist"); plistDocument.ReadFromFile(plistPath); var bundleLanguages = plistDocument.root.CreateArray("CFBundleLocalizations"); foreach (var locale in LocalizationEditorSettings.GetLocales()) { var code = locale.Identifier.Code.Replace("-", "_"); project.AddKnownRegion(code); bundleLanguages.AddString(code); var localeDir = code + ".lproj"; var dir = Path.Combine(projectDirectory, localeDir); Directory.CreateDirectory(dir); var filePath = Path.Combine(dir, kInfoFile); var relativePath = Path.Combine(localeDir, kInfoFile); GenerateLocalizedInfoPlistFile(locale, appInfo, plistDocument, filePath); project.AddLocaleVariantFile(kInfoFile, code, relativePath); } plistDocument.WriteToFile(plistPath); project.WriteToFile(pbxPath); }