📜 ⬆️ ⬇️

How to add information about transfers to the game assembly at Unity

It is not enough to translate your game, you also need to convince the app stores of this fact. What for? Typically, the description of the application in the store contains supported languages, which may affect the decision of the player to purchase. Unfortunately, each platform requires its own approach to add information about translations to the assembly, but I tried to collect the most convenient methods for the three main stores.

iOS and MacOS


At the root of the project build for Xcode on iOS, there is an Info.plist file, the same file is also in the build for MacOS in the GAMENAME.app/Contents folder. You need to add the CFBundleLocalizations key to it with an array of values ​​for all languages ​​supported by your game:

<key>CFBundleLocalizations</key> <array> <string>en</string> <string>ru</string> </array> 

The problem is that after the next build of the game, this file will be overwritten and everything will have to be repeated again and again. The blessing for us is to automate it easily with a script in Unity itself:

 #if UNITY_EDITOR using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; using System.IO; using System.Xml; public class LocalizationPostBuildProcess { //       static string[] kProjectLocalizations = { "en", "ru" }; [PostProcessBuild] public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS || buildTarget == BuildTarget.StandaloneOSXUniversal || buildTarget == BuildTarget.StandaloneOSXIntel || buildTarget == BuildTarget.StandaloneOSXIntel64) { string infoPList = System.IO.Path.Combine(path, buildTarget == BuildTarget.iOS ? "Info.plist" : "/Contents/Info.plist"); if (File.Exists(infoPList) == false) { Debug.LogError("Could not add localizations to Info.plist file."); return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(infoPList); XmlNode pListDictionary = xmlDocument.SelectSingleNode("plist/dict"); if (pListDictionary == null) { Debug.LogError("Could not add localizations to Info.plist file."); return; } XmlElement localizationsKey = xmlDocument.CreateElement("key"); localizationsKey.InnerText = "CFBundleLocalizations"; pListDictionary.AppendChild(localizationsKey); XmlElement localizationsArray = xmlDocument.CreateElement("array"); foreach (string localization in kProjectLocalizations) { XmlElement localizationElement = xmlDocument.CreateElement("string"); localizationElement.InnerText = localization; localizationsArray.AppendChild(localizationElement); } pListDictionary.AppendChild(localizationsArray); xmlDocument.Save(infoPList); } } } #endif 

Android


For Android, the most convenient way is localization resource files. A big plus is that this can be done directly in the Unity project: create an xml file Assets \ Plugins \ Android \ res \ values-LANGUAGE , for example: values-ru . Inside the file, create one value:
')
 <!--?xml version="1.0" encoding="utf-8"?--> <resources> <string name="app_name">GodSpeed</string> </resources> 

Repeat the process with each location and your apk will contain information about all available languages ​​in the game.

Windows store


In the Visual Studio project created by Unity, there is a Package.appxmanifest file, in which the Resources key is present:

 <Resources> <Resource Language="x-generate" /> </Resources> 

The value indicates that Visual Studio should add supported languages ​​here when building the package. But we can manually enter the values ​​we need:

 <Resources> <Resource Language=”en-us” /> <Resource Language=”fr-fr” /> </Resources> 

Contrary to the Microsoft documentation, after downloading the package, the store ignores these values ​​and detects only the default language.

You have to go by adding resource files. The principle is similar to the method for Android, but the files need to be added in the Visual Studio project itself, and not in Unity. Create a folder with the name of the language (ru, en-US, etc.) and inside the file Resources.resw . Be sure to open the file and add at least one value inside. The process is repeated for all localizations except the default language. It is necessary to make it only once, at the subsequent assemblies of Unity will not delete these files. Done! Now when building a project, Visual Studio will find all resource files and automatically add information about supported languages ​​to appxupload .

Conclusion


Although it is possible to carry out these operations, if there is information, it will take a maximum of an hour, I would like the option to add all the necessary information to be added to Unity. Thank you all, I hope this will help you!

Source: https://habr.com/ru/post/340408/


All Articles