Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Translate

Discussion in 'Scripting' started by Deleted User, Apr 16, 2016.

  1. Deleted User

    Deleted User

    Guest

    Hello, so yesterday i started creating a simple app, i wanted to translate it into 2 languages - English and Latvian, but i couldn't find any good and simple way to do it as i wanted, or i just couldn't figure it out, anyways here is what i want to do - if(Language == English){ english = true;} That's all i need, and same for Latvian language, like, if you android devices system language is set to english then english = true, but if latvian then latvian = true. Is it even possible? If it is then please help! Thank you! :)
     
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Hi,

    Maybe you could determine the user language by checking:

    Code (CSharp):
    1. System.Globalization.CultureInfo.CurrentCulture
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest


    It shows me en-US but how to use it in the if statement?
     
  4. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Something like:
    Code (CSharp):
    1. if(System.Globalization.CultureInfo.CurrentCulture.Name == "en-US")
    2. {
    3.     // Apply english translation
    4. }
     
    Deleted User likes this.
  5. Deleted User

    Deleted User

    Guest

    Sorry, it doesn't work, your code works but only on unity, when i built my game and installed it on my phone it didn't. :(
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Have you tried to figure out what will be returned on your phone? E.g. output it on a gui element or use the dev console in your build and see what will be returned.
     
    Deleted User likes this.
  7. Deleted User

    Deleted User

    Guest

    If you mean this then yes - if language = en-US then it translates all text into english, i don't have a lot of text there bcz there is mostly letters and numbers but still xd And i said it works on PC, tought it works on phone too but when i tested it on phone, i changed language to englis (United States) and nothing happened, also tried to restart my phone - nothing.
     
  8. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Sorry, but I'm confused now. Is it working or not?
    You said it's not working on your phone, so either the property returns something different than 'en-US' or it just doesn't work at all.
     
    Deleted User likes this.
  9. Deleted User

    Deleted User

    Guest

    Sorry im tired and english isn't my first language, it works on pc in unity editor, but for some reasion it doesn't work on phone. And yes maybe it returns something else but i tried to switch my phone language to English (US), English (UK) etc. and still didn't work.
     
  10. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Then, as I said, just try to output (on your phone) what will be returned by

    Code (CSharp):
    1. System.Globalization.CultureInfo.CurrentCulture.Name
    .

    Then you'll see why it doesn't work.
     
    Deleted User likes this.
  11. Deleted User

    Deleted User

    Guest

    Just tried that, it returns nothing, on pc it returns en-US, on phone - *empty space*, doesn't matter witch language i choose, none returns anything.
     
  12. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Okay, I guessed so.

    Try Application.systemLanguage which is part of the Unity API.
    It's hopefully implemented in a way so that it does the platform specific calls to figure out the language.
     
    Deleted User and ericbegue like this.
  13. Deleted User

    Deleted User

    Guest

    Thank you, it works perfectly! This is what i ended up using - Application.systemLanguage.ToString() == "English"
     
    Suddoha likes this.