Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

AppName Localization for macOS

Discussion in 'macOS' started by AlexNanomonx, Aug 26, 2020.

  1. AlexNanomonx

    AlexNanomonx

    Joined:
    Jan 4, 2017
    Posts:
    35
    So I have some knowledge to share about localizing the App Name that I'd like to share on this forum for posterity, as I found very little previous things to help me with this problem either on this website or any other, and it's been a deeply frustrating few days. But I'd like to start with a questions, does anyone have any clue how to localize the AppName in the Applications folder? Is it only possible when installing through the app store?

    Ok, how to localize the AppName for macOS? This is assuming you're just going ahead and generating the .app file, if you first generate an Xcode project I'll leave that up to you.

    Fundamentally it's pretty similar to the better documented iOS, you need to generate InfoPlist.strings files in lang-code.lproj folders (eg. MyApp.app/Content/en-NZ.lproj/InfoPlist.strings). They should look like this:
    In addition to that you must update the Info.plist file. Here is a function that updates it correctly (for me at least)
    Code (CSharp):
    1. /// <summary>
    2. ///     Export localized languages to the info.plist
    3. /// </summary>
    4. /// <param name="contentsFolder">The folder in which the info.plist file should be</param>
    5. /// <param name="langCodes">The language codes eg. en, en-NZ, fr, fr-CA</param>
    6. private static void UpdatePlist(string contentsFolder, List<string> langCodes)
    7. {
    8.     string plistPath = contentsFolder + "/Info.plist";
    9.     PlistDocument plist = new PlistDocument();
    10.     plist.ReadFromString(File.ReadAllText(plistPath));
    11.  
    12.     PlistElementDict rootDict = plist.root;
    13.  
    14.     PlistElementArray langArray = rootDict.CreateArray("CFBundleLocalizations");
    15.     foreach (string code in langCodes)
    16.         langArray.AddString(code);
    17.  
    18.     rootDict.SetString("CFBundleDevelopmentRegion", langCodes[0]);
    19.     rootDict.SetString("CFBundleDisplayName", "MyAppName");
    20.     rootDict.SetString("CFBundleName", "");
    21.     rootDict.SetBoolean("LSHasLocalizedDisplayName ", true);
    22.  
    23.     // Write to file
    24.     File.WriteAllText(plistPath, plist.WriteToString());
    25. }
    26.  
    The most important thing is to set CFBundleName to an empty string, otherwise whatever you enter in the that field will be displayed in the main menu bar and will not be translated. I think the main menu bar is defined by Unity, and is very frustrating, that it doesn't consistently represent localized values.


    (in this image, in the info.plist CFBundleName was set to "CFBundleName")

    Anyway, I hope this was helpful to someone, you can learn from my pain.
     
    Last edited: Aug 26, 2020
    rozochkin13 likes this.
  2. AlexNanomonx

    AlexNanomonx

    Joined:
    Jan 4, 2017
    Posts:
    35
    Ok, I figured it out. Basically apple has the answer here. Whatever the name of the built .app file CFBundleDisplayName in the Info.Plist should be set to the same thing. If it is, it will automaticatically localize. I edited my post above to include this information, but here is my explanation. I hope it's useful!
     
unityunity