Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to add InfoPlist.strings into xcode project in script?

Discussion in 'iOS and tvOS' started by bluesky139, Mar 29, 2016.

  1. bluesky139

    bluesky139

    Joined:
    Aug 24, 2012
    Posts:
    8
    I know Unity has class PBXProject, it can modify xcode project, but when adding InfoPlist.strings, file will be added as a normal file.
    Thus, it doesn't work. I need this file to localize product name.
     
  2. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hello,
    PBXProject API does not support adding strings localization files yet.
     
  3. rrsimon

    rrsimon

    Joined:
    Apr 16, 2012
    Posts:
    27
    Are there any plans to support this feature or any 3rd party alternatives? With iOS 10 forcing us to give a description when using device features like NSCameraUsageDescription, it would be a pain to always have to manually re-enter the localization of these strings for each build we make.
     
    gamecakestudios likes this.
  4. gamecakestudios

    gamecakestudios

    Joined:
    Nov 13, 2013
    Posts:
    21
    I second this! It'd be really useful to have the ability to localize these settings if possible. I suppose it depends on your localization implementation, but I'd imagine there are some limitations on this because of the way Apple wants you to handle localizing this text.
     
  5. rrsimon

    rrsimon

    Joined:
    Apr 16, 2012
    Posts:
    27
    Until then, if anyone's interested, here's my solution:

    I have a build step that will copy all of the localization folders (en.lproj, fr.lproj, es.lproj, etc...) into the build's folder and I drag and drop each and every individual InfoPlist.strings into the Xcode project to add the localization. Doing a mass drag&drop will either crash Xcode or corrupt it so the project no longer builds anymore. It's tedious but it works.
     
  6. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hey. Is this somewhere on the horizon maybe? Would be pretty nice to avoid all those python postbuild scripts as workarounds.

    btw: Ok, I see that you already approved the pull request here: https://bitbucket.org/Unity-Technologies/xcodeapi/pull-requests/13/creation-of-variantgroup-and/diff
    Do you know when it will be merged into the release version? I can live for now with modifying my code, but it would be great to have it in the engine for all of us.
     
    Last edited: Sep 21, 2016
  7. mopsicus

    mopsicus

    Joined:
    Feb 15, 2016
    Posts:
    13
    as pahe said
    so, when it will be merged?
     
    leni8ec, FIFTYTWO and pahe like this.
  8. nevumx

    nevumx

    Joined:
    Mar 11, 2015
    Posts:
    2
    Can we bump this? I would really like to see that PR merged as well, and it's been 3 years...
     
  9. marcin-huuuge

    marcin-huuuge

    Joined:
    Sep 5, 2018
    Posts:
    15
    Hi! Ten years have passed. Has anything changed yet?
     
    Mishganches likes this.
  10. leni8ec

    leni8ec

    Joined:
    May 23, 2013
    Posts:
    23
    Hey, Unity? :)
     
    Mishganches likes this.
  11. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    This would be a useful addition with the advent of Apple's iOS 14 tracking changes - so that we can easily localise our custom message on the popup without needing manual steps.

    Screenshot 2020-08-05 at 10.20.26.png
     
    Dust999Games and Petr777 like this.
  12. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I managed to get it working.

    I have the .strings files in my project.

    Screenshot 2020-08-07 at 17.03.06.png

    And I call this for each one.

    Code (CSharp):
    1.         guid = project.AddFolderReference(Application.dataPath + "/Editor/Localisations/en.lproj", "en.lproj");
    2.         project.AddFileToBuild(targetGuid, guid);
    3.  
    Then I end up with this in my Xcode project.

    Screenshot 2020-08-07 at 17.06.06.png

    And when running on device with one of the languages set, I get the message I want.
     
  13. kdeger

    kdeger

    Joined:
    Mar 4, 2018
    Posts:
    22
    Did you have any problem with contents of those InfoPlist.strings files? Weird but mines are empty inside Xcode Project.
     
    myama likes this.
  14. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Not that I can recall.
     
  15. kdeger

    kdeger

    Joined:
    Mar 4, 2018
    Posts:
    22
    Just to be sure your string file is like this;
    Code (JavaScript):
    1. /* Localized versions of Info.plist keys */
    2.  
    3. "NSUserTrackingUsageDescription" = "Your data will be used to deliver personalized ads to you.";
    4.  
    Not like this;
    Code (JavaScript):
    1. /* Localized versions of Info.plist keys */
    2.  
    3.  
    Am I really the only one facing this?
     
  16. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I don't have double quotes around the key.

    Code (CSharp):
    1. /* Localized versions of Info.plist keys */
    2.  
    3. NSUserTrackingUsageDescription = "german";
     
  17. tarmo-jussila

    tarmo-jussila

    Joined:
    Jun 4, 2015
    Posts:
    42
    These seem empty for me as well in Xcode, but they do appear in Xcode, just empty. I used the version provided by @andymads without double quotes for the key.

    Did @kdeger manage to found a solution for this?
     
  18. kdeger

    kdeger

    Joined:
    Mar 4, 2018
    Posts:
    22
    I managed to make it work with @andymads ' help.

    As mentioned above put your.lproj files in your project, call a method something like this inside PostProcessBuild function

    Code (CSharp):
    1.         string sPath = PBXProject.GetPBXProjectPath(path);
    2.         var project = new PBXProject();
    3.         project.ReadFromString(File.ReadAllText(sPath));
    4.  
    5.         string targetMainGuid;
    6.         string targetFrameworkGuid;
    7.  
    8. #if UNITY_2019_3_OR_NEWER
    9.         targetFrameworkGuid = project.GetUnityFrameworkTargetGuid();
    10.         targetMainGuid = project.GetUnityMainTargetGuid();
    11. #else
    12.         targetFrameworkGuid = project.TargetGuidByName("Unity-iPhone");
    13. #endif
    14.         for (int i = 0; i < localizationFolderNames.Length; i++)
    15.         {
    16.             var guid = project.AddFolderReference(Application.dataPath + string.Format("/Editor/Localizations/{0}.lproj", localizationFolderNames[i]), string.Format("{0}.lproj", localizationFolderNames[i]), PBXSourceTree.Source);
    17. #if UNITY_2019_3_OR_NEWER
    18.             project.AddFileToBuild(targetMainGuid, guid);
    19. #endif
    20.             project.AddFileToBuild(targetFrameworkGuid, guid);
    21.         }
    22.  
    23.         project.WriteToFile(sPath);
    On Xcode the files should appear something like this on the screenshot, also don't forget to add the relevant localizations to your project, otherwise you can't validate and distribute the app to appstore (and get rid of the deprecated ones too if you have any).
     

    Attached Files:

  19. jeanbaptistelai

    jeanbaptistelai

    Joined:
    Jul 17, 2017
    Posts:
    13
    I'm trying to get this working too, what do you mean by adding ghe relevant localizations? Is this a setting in Unity? The only thing i can find about localization in unity is a preview package.
     
  20. aveNger0101

    aveNger0101

    Joined:
    Feb 12, 2018
    Posts:
    7
    Hello. I add localization according to your code, but it does not appear in the project info in xcode. Did you add them manually?
     

    Attached Files:

  21. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    For me the same and I couldn't find out why not. Still, the localized InfoPlist.strings are correctly used though, so I considered that a minor xCode problem. Does it still work it for you or not?
     
  22. kdeger

    kdeger

    Joined:
    Mar 4, 2018
    Posts:
    22
    It works for me without any problem, I also can't see the added localizations in the project info in xcode. Published more than 5 apps like this to the appstore and each one of them passed and worked fine without any issue.
     
  23. ABerlemont

    ABerlemont

    Joined:
    Sep 27, 2012
    Posts:
    67
    Hey people,

    I'm having the exact same result as @aveNger0101.

    Would it be because of a new version of xcode ? (i'm working with 12.5)

    Do you guys have some documentation link to share on how you found out how to achieve this result ?
    Also, I'm wondering how you know you don't have a typo on country initials ?


    Thanks for the help !
     
  24. ABerlemont

    ABerlemont

    Joined:
    Sep 27, 2012
    Posts:
    67
    I used superbderrick integration ( repo : https://github.com/superbderrick/UnityiOSLocalization )
    and it seems to work (it showed the right language when testing) even if the repo is 2 years old :D

    Main difference is that the InfoPlist.strings end up in Unity-iPhone Test/Supporting Files/

    2021-05-26_000627.png
     
    tomcech likes this.
  25. tomcech

    tomcech

    Joined:
    May 4, 2019
    Posts:
    4
    Thanks for the repo link. The code worked perfectly! It is a bit old but still works. Only had to change line 151 in "Editor->Xcode->PlistParser.cs" to "settings.DtdProcessing = DtdProcessing.Parse" to get rid of the Unity warning.

    Also a note for those like me who successfully built the project, see the localization files but still can't get it to work:
    Make sure the key in each InfoPlist.strings file is without the quotation marks (like so: NSCameraUsageDescription = "Your text")
     
  26. igor_rst

    igor_rst

    Joined:
    Apr 20, 2017
    Posts:
    40
    You can check my solution https://github.com/mopsicus/unity-ios-localization
    Just 2 files and everything works fine.