Search Unity

C# CurrentCulture always return "en-US"

Discussion in 'Scripting' started by Raitoning, Jun 11, 2016.

  1. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Hello everybody,

    I've a problem when trying to retrieve the current langage on which the game runs. When I call CurrentCulture.CurrentUICulture, Unity always gives me back "en-us". However, my Windows is not English but French, and if I run the very same code on a new separate project from Unity, it returns me "fr-FR", which is right. I really need to retrieve the current language because I'm localizating my game and I need to adapt the display of the date and time to the local standard where the player is living.

    This is the code I've put in the separate project:
    Code (CSharp):
    1. static void Main(string[] args)
    2. {
    3.      CultureInfo Culture;
    4.      Culture = CultureInfo.CurrentUICulture;
    5.      Console.Write("Current culture: " + Culture);
    6.      Console.Read();
    7. }
    Which returns me the correct current culture:
    WindowsCulture.png

    But on Unity, the nearly same code doesn't return the same thing:
    Code (CSharp):
    1. void Start(){
    2.  
    3.         Culture = CultureInfo.CurrentUICulture;
    4.         Debug.Log("Current culture: " + Culture);
    5. }
    Which always return "en-US":
    UnityCulture.png

    I saw someone else having the very same problem but nobody answered him already, this is why I create a thread for this issue.

    Link of the other thread: http://answers.unity3d.com/questions/1166314/why-current-culture-is-always-en-us-and-what-is-th.html

    If someone knows why, or if it's related to the Unity Engine, please let us know :) Thanks for reading :)
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    What platform are you on? If you're on Universal Windows Platform for Windows 10 I use this to get the current language
    Code (csharp):
    1. Windows.System.UserProfile.GlobalizationPreferences.Languages[0]
     
  3. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    I am on Windows 10, but I already had this problem on Windows 7 and Windows 8.1.

    I don't know what "Universal Windows Platform for Windows 10" is, a kind of a special development platform for all Windows 10 products ?
     
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    It may be that your code or Unity sets this property somewhere. Have you tried using CultureInfo.InstalledUICulture instead? That should return the cultureinfo installed with the Os.
     
  5. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    The two codes are the same. I've already tried to use InstalledUICulture too, and it show the same result. I'm not the only one having this issue, as I've put a link to a question from someone else that also have this issue. Maybe Unity runs on it own version of the .net, that would explain why it always return "en-US".
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Unity does run on it's own version of .Net - an old (2009) version of Mono.

    Yeah, it's bad.

    Google is your friend, by the way. This was the first search result.

    Edit: more search results.
     
  7. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  8. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Some people don't use Google, and I used the search toolbar at the top of the forum, and I didn't found something usefull.

    If I knew before that those functions were broken, I would have checked the Script References before.

    Anyway, thanks for your answers.

    SystemLanguage doesn't fit very well for what I'm doing, because I'd like to adapt the display of the date and time to the locale standard where the player live. So I'll have to lock everybody with the English way of writing the date/time, unless there is another way to retrieve the player's OS language.