Search Unity

Localization within an iphone app made in unity

Discussion in 'iOS and tvOS' started by EducaSoft, Oct 27, 2008.

  1. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    On the ADC they tell us we can make the store pages localized by filling out our data in multiple languages, but they also clearly mention that the localization in the app should be all in 1 application.

    Is this possible in the current Unity Iphone build ?

    For example, can I make an app which is automatically capable of sensing which local language is active on the iphone ?

    If possible -> How ?


    Kind regards,
    Bart
     
  2. Mathieu

    Mathieu

    Joined:
    Jun 13, 2005
    Posts:
    103
    We're having the same interrogation here at Frogames.

    Does anyone managed to push a Unity iPhone app with localized support?

    Is there a way to know which language the user iPhone is running?
     
  3. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    You could create localized strings in XCode like you do normally, and then pass them into Unity via PlayerPrefs. So inside the app delegate before Unity is started:

    Code (csharp):
    1.  
    2. NSString *s = NSLocalizedString(@"Player one", @"Player One");
    3. [[NSUserDefaults sharedDefaults] setObject: s forKey: @"Player one"];
    4.  

    Or, you can map the strings to localized equivalents inside Unity code, and just pass in the current language. I've never tried it, but the docs say you can get the current language like this:

    Code (csharp):
    1. NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    2. NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    3. NSString* preferredLang = [languages objectAtIndex:0];
    4. [[NSUserDefaults sharedDefaults] setObject: preferredLang forKey: @"language"];
    5.  
     
  4. Mathieu

    Mathieu

    Joined:
    Jun 13, 2005
    Posts:
    103
    Thanks bliprob! :)
    I'll try the second method.

    Does anyone know if it's something that will be work on on a futur version of Unity iPhone? It would be interesting to have an Application.preferredLang variable.
     
  5. azeitler

    azeitler

    Joined:
    May 14, 2008
    Posts:
    162
    has anyone succesfully implemented this?
    How and where needs this code to be placed?
    Where can I find the above mentioned documentation about this?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The last line should be

    Code (csharp):
    1. [[NSUserDefaults standardUserDefaults] setObject: preferredLang forKey: @"language"];
    Put it somewhere before the line that launches Unity.

    --Eric
     
  7. azeitler

    azeitler

    Joined:
    May 14, 2008
    Posts:
    162
    Thanks for the tipp! This works fine!
    But the changes I make to the xCode Project are overwritten when I build the project in unity.
    Can I circumwent that somehow?

    EDIT:
    I a now using PostProcessBuildPlayer to copy a modified AppController.mm to the xCode Project after the Unity-Build is done. Works fine.. :)
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    alternatively you can just alter the trampoline in unity iphone.app
     
  9. Leymon

    Leymon

    Joined:
    Mar 25, 2010
    Posts:
    6
    Please, can you explain what you mean by "alter the trampoline"?
     
  10. BogdanDude

    BogdanDude

    Joined:
    Jun 18, 2009
    Posts:
    89
    Hi!

    We integrated localization in English, French, German, Italian and Spanish for our Predators game.

    We did all this by writing a simple C# class and accessing it in Unity.

    We just have one problem: The iTunes Appstore description shows only 'English' as the supported language.

    Here's a screenshot:



    Do you know of any settings on the Xcode side, to enable the other 4 languages, so they'd show up on iTunes? (French, German, Italian Spanish)
    There were no hidden checkboxes when uploading the app through iTunes Connect :?

    Thanks a lot,
    Bogdan
     
    mentalup likes this.
  11. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Can somebody explain more detailed for Xcode n00bs how this works? (what is the line that starts unity? And how do I access the language from inside unity?) And does it work with iphone basic?

    @BogdanDude I think you have to set the language inside a plist file to be shown in the AppStore (as written somewhere in the apple documentation)
     
  12. BogdanDude

    BogdanDude

    Joined:
    Jun 18, 2009
    Posts:
    89
    I did a quick search on Google, but I didn't find any info.plist settings for showing those languages.

    If you know what those settings are, please let me know.

    Thanks a lot!
     
  13. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
  14. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Anyway still trying to get that working with iphone basic for an already finished update, the enhancement pack makes audio problems with multitasking so I hope to be able to avoid it. Can someone please take me by the hand and explain how to do it? :oops:
     
  15. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What I did for Realmaze3D was to (in XCode) select MainWindow.xib, get info, make the file localizable, then add the two-letter country codes for the languages I had. As long as something is marked as localized like this, then it shows up in iTunes properly, regardless of whether you actually do anything else in XCode (the actual localization in my case was done in Unity).

    --Eric
     
  17. BogdanDude

    BogdanDude

    Joined:
    Jun 18, 2009
    Posts:
    89
    Thanks a lot guys! That was really easy :)
    Now let's see if they actually turn up in iTunes :)
     
  18. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    I still don't get it to work with iphone basic and playerprefs :(
     
  19. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    No one who can help?
     
  20. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Bump :oops:

    Really no one with a solution for javascript and iphone basic?
     
  21. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    And what about made a simply menu for language selection inside the game?, use the playerprefs and import the current language it's good, but what about if I have my phone configured in english and I want to play in french?, I'm not gonna waste my time changing the iphone properties to french only for play the game....
     
  22. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    I already have that menu in 1.0 but also automatic language detection. So this would be a kind of downgrade possibly ending in 1 star reviews. I'm sure a lot of people never saw that menu, they can reach it by pressing the usual tiny "i"-symbol in the right lower corner.
     
  23. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Then get the current language through the playerprefs and xcode, first get the language from xcode and save it to userdefaults
    Code (csharp):
    1.  
    2. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    3.         NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    4.         NSString *currentLanguage = [languages objectAtIndex:0];
    5.        
    6.         [[NSUserDefaults standardUserDefaults] setObject:currentLanguage forKey:@"language"];
    7.         [[NSUserDefaults standardUserDefaults] synchronize];
    8.  
    Then load the value from unity as usual with playerprefs
     
  24. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Thanks, where do i have to enter these lines in xcode?
     
  25. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    on the appcontroller of course, just before unity starts on the "applicationDidFinishLaunching"
     
  26. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    thank you!
     
  27. sendel76

    sendel76

    Joined:
    Mar 17, 2010
    Posts:
    36
  28. sendel76

    sendel76

    Joined:
    Mar 17, 2010
    Posts:
    36
    My first guess would be something like:
    ----------------------------------------------------------------------
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. /// <summary>
    5. /// Web communicator class to serve functions for webplayer.
    6. /// Usage:
    7. /// <script type="text/javascript" language="javascript">
    8. /// <!--
    9. /// function SetSystemLanguage(var language)
    10. /// {    
    11. ///     var unity = GetUnity();
    12. ///     unity.SendMessage("WebCommmunicator", "SetSystemLanguage", language);
    13. /// }
    14. /// -->
    15. /// </script>
    16. /// </summary>
    17. public class WebCommunicator : MonoBehaviour
    18. {
    19.     #region Singelton
    20.     private static WebCommunicator _instance = null;
    21.    
    22.     /// <summary>
    23.     /// Creates and/or returns the singelton instance of WebCommunicator.
    24.     /// </summary>
    25.     /// <value>
    26.     /// The singelton instance.
    27.     /// </value>
    28.     public static WebCommunicator Instance
    29.     {
    30.         get
    31.         {
    32.             if ( null == _instance )
    33.             {
    34.                 WebCommunicator webCom = FindObjectOfType( typeof( WebCommunicator ) ) as WebCommunicator;
    35.            
    36.                 if ( null == webCom )
    37.                 {
    38.                     GameObject webComObject = new GameObject("WebCommmunicator");
    39.                     webCom = webComObject.AddComponent<WebCommunicator>();
    40.                 }
    41.                 _instance = webCom;            
    42.             }
    43.             return _instance;          
    44.         }      
    45.     }
    46.     #endregion
    47.    
    48.     /// <summary>
    49.     /// Sets the system language, will be called from website.
    50.     /// </summary>
    51.     /// <param name='language'>
    52.     /// Language key you want to work with.
    53.     /// </param>
    54.     public void SetSystemLanguage( string language )
    55.     {
    56.         PlayerPrefs.SetString( "SystemLanguage", language );
    57.     }
    58.    
    59.     // Make it persistant
    60.     public void Awake()
    61.     {
    62.         DontDestroyOnLoad( gameObject );
    63.     }
    64. }
    ----------------------------------------------------------------------


    but how to actually detect system language in javascript?
     
    Last edited: Jul 26, 2012
  29. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251