//添加本地化strings文件 public static void AddLocalizedStrings(PBXProject pbxProject, string buildPath, string directoryName, string fileName, string localizedDirectoryPath, List <string> validLocales) { foreach (var locale in validLocales) { string fileRelatvePath = string.Format("{0}/{1}.lproj/{2}", directoryName, locale, fileName); pbxProject.AddLocalization(fileName, locale, fileRelatvePath); } }
public static void AddLocalizedStringsIOS(string projectPath, string localizedDirectoryPath, List <string> validLocales) { string projPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); foreach (var locale in validLocales) { string src = Path.Combine(localizedDirectoryPath, locale + ".lproj"); DirectoryCopy(src, Path.Combine(projectPath, locale + ".lproj")); string fileRelatvePath = string.Format("{0}.lproj/InfoPlist.strings", locale); proj.AddLocalization("InfoPlist.strings", locale, fileRelatvePath); } proj.WriteToFile(projPath); }
public static void AddLocalizedStringsIOS(string projectPath, string localizedDirectoryPath, List <string> validLocales) { string projPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); foreach (var locale in validLocales) { // copy contents in the localization directory to project directory string src = Path.Combine(localizedDirectoryPath, locale + ".lproj"); string dst = Path.Combine(projectPath, "Unity-iPhone/" + locale + ".lproj"); if (Directory.Exists(dst)) { Directory.Delete(dst, true); } DirectoryCopy(src, dst); string fileRelatvePath = string.Format("Unity-iPhone/{0}.lproj/AppiraterLocalizable.strings", locale); proj.AddLocalization("InfoPlist.strings", locale, fileRelatvePath); } proj.WriteToFile(projPath); }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget != BuildTarget.iOS) { return; } if (LocalizationManager.Sources.Count <= 0) { LocalizationManager.UpdateSources(); } var langCodes = LocalizationManager.GetAllLanguagesCode(false).Concat(LocalizationManager.GetAllLanguagesCode(true)).Distinct().ToList(); if (langCodes.Count <= 0) { return; } Debug.Log(String.Join(" ", langCodes)); try { //----[ Export localized languages to the info.plist ]--------- string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // Get Language root var langArray = rootDict.CreateArray("CFBundleLocalizations"); // Set the Language Codes foreach (var code in langCodes) { if (code == null || code.Length < 2) { continue; } langArray.AddString(code); } rootDict.SetString("CFBundleDevelopmentRegion", langCodes[0]); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); //--[ Localize App Name ]---------- string LocalizationRoot = pathToBuiltProject + "/I2Localization"; if (!Directory.Exists(LocalizationRoot)) { Directory.CreateDirectory(LocalizationRoot); } var project = new PBXProject(); string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); //if (!projPath.EndsWith("xcodeproj")) //projPath = projPath.Substring(0, projPath.LastIndexOfAny("/\\".ToCharArray())); project.ReadFromFile(projPath); //var targetName = PBXProject.GetUnityTargetName(); //string projBuild = project.TargetGuidByName( targetName ); project.RemoveLocalizationVariantGroup("I2 Localization"); // Set the Language Overrides foreach (var code in langCodes) { Debug.Log($"POST PROCESS BUILD IOS LANGCODE {code}"); if (code == null || code.Length < 2) { continue; } var LanguageDirRoot = LocalizationRoot + "/" + code + ".lproj"; if (!Directory.Exists(LanguageDirRoot)) { Directory.CreateDirectory(LanguageDirRoot); } var infoPlistPath = LanguageDirRoot + "/InfoPlist.strings"; List <string> infoPlistContents = new List <string> { string.Format("CFBundleDisplayName = \"{0}\";", LocalizationManager.GetAppName(code)) }; foreach (KeyValuePair <string, string> entry in plistStringMap) { string translation = GetTranslationForLanguage(entry.Value, code); if (!string.IsNullOrEmpty(translation)) { infoPlistContents.Add($"{entry.Key} = \"{translation}\";"); } } string InfoPlist = String.Join(Environment.NewLine, infoPlistContents.ToArray()) + Environment.NewLine; File.WriteAllText(infoPlistPath, InfoPlist); var langProjectRoot = "I2Localization/" + code + ".lproj"; var stringPaths = LanguageDirRoot + "/Localizable.strings"; File.WriteAllText(stringPaths, string.Empty); project.AddLocalization(langProjectRoot + "/Localizable.strings", langProjectRoot + "/Localizable.strings", "I2 Localization"); project.AddLocalization(langProjectRoot + "/InfoPlist.strings", langProjectRoot + "/InfoPlist.strings", "I2 Localization"); } project.WriteToFile(projPath); } catch (System.Exception e) { Debug.LogError(e); } }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget != BuildTarget.iOS) { return; } if (LocalizationManager.Sources.Count <= 0) { LocalizationManager.UpdateSources(); } var langCodes = LocalizationManager.GetAllLanguagesCode(false); if (langCodes.Count <= 0) { return; } try { //----[ Export localized languages to the info.plist ]--------- string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // Get Language root var langArray = rootDict.CreateArray("CFBundleLocalizations"); // Set the Language Codes foreach (var code in langCodes) { if (code == null || code.Length < 2) { continue; } langArray.AddString(code); } rootDict.SetString("CFBundleDevelopmentRegion", langCodes[0]); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); //--[ Localize App Name ]---------- string LocalizationRoot = pathToBuiltProject + "/I2Localization"; if (!Directory.Exists(LocalizationRoot)) { Directory.CreateDirectory(LocalizationRoot); } var project = new PBXProject(); string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); //if (!projPath.EndsWith("xcodeproj")) //projPath = projPath.Substring(0, projPath.LastIndexOfAny("/\\".ToCharArray())); project.ReadFromFile(projPath); //var targetName = PBXProject.GetUnityTargetName(); //string projBuild = project.TargetGuidByName( targetName ); // Set the Language Overrides foreach (var code in langCodes) { if (code == null || code.Length < 2) { continue; } var LanguageDirRoot = LocalizationRoot + "/" + code + ".lproj"; if (!Directory.Exists(LanguageDirRoot)) { Directory.CreateDirectory(LanguageDirRoot); } var infoPlistPath = LanguageDirRoot + "/InfoPlist.strings"; var InfoPlist = string.Format("CFBundleDisplayName = \"{0}\";", LocalizationManager.GetAppName(code)); File.WriteAllText(infoPlistPath, InfoPlist); var langProjectRoot = "I2Localization/" + code + ".lproj"; var stringPaths = LanguageDirRoot + "/Localizable.strings"; File.WriteAllText(stringPaths, string.Empty); project.AddLocalization(langProjectRoot + "/Localizable.strings", langProjectRoot + "/Localizable.strings", "I2 Localization"); project.AddLocalization(langProjectRoot + "/InfoPlist.strings", langProjectRoot + "/InfoPlist.strings", "I2 Localization"); } project.WriteToFile(projPath); } catch (System.Exception e) { Debug.Log(e); } }