How to set the right language automatically?

  • #1, z marvelSaturday, 31. January 2015, 12:47 hodinky 10 years ago
    Hey everybody,
    is there a chance to select the "Operation System Language" via lua? I'd like to set the game language automatically, when the player starts the game for the first time. smile

    Zabiják klíčů

    599 Posts


  • #2, z afrlmeSaturday, 31. January 2015, 12:53 hodinky 10 years ago
    http://wiki.visionaire-tracker.net/wiki/GetProperty

    Check out the last example on the page. wink

    Here's a revised version using the new shorthand code...
    local sysLang = getProperty("system_language")
     
    if sysLang == "English" then
      game.StandardLanguage = Languages["English"]
    elseif sysLang == "German" then
      game.StandardLanguage = Languages["Deutsch"]
    else -- fallback to English in case OS language is not one in this list...
     game.StandardLanguage = Languages["English"]
    end
    

    ..I've not actually tried with the shorthand code, but it should be correct.

    Imperátor

    7285 Posts

  • #3, z marvelSaturday, 31. January 2015, 13:33 hodinky 10 years ago
    Seems to work like a charm. Thanks Leeman smile

    Zabiják klíčů

    599 Posts

  • #4, z sebastianSunday, 12. June 2016, 21:22 hodinky 8 years ago
    Heyho bois'n'gurls,

    the problem I have right now is that the language changes back to system_language after each restart.
    Of course i have to save the language inside my config i guess.

    What would be a "best practice" to implement the above script but only run it if you don't set the language in the game settings later?

    I had in mind the the config could contain 3 states of language= :
    "system, german, english" and would be "system" at default.

    Is there a better way?

    thanks,
    Sebastian.

    Kapitán

    2346 Posts

  • #5, z afrlmeMonday, 13. June 2016, 03:32 hodinky 8 years ago
    The intial config ini that is created when you compile your game is irrelevant. It's only used if a custom one is not found in the c:/users... appData/local... whatsit folder.

    What you could do is check to see if the file exists in the folder location I mentioned & if not then use system language. You should be executing the function that reads your config ini file at game launch anyway, which should contain a safeguard measure to check if file exists.

    I'm not going to go into how to sort out your config ini script though as there's already an example & tutorial on the wiki I wrote ages back under the script index section.

    Imperátor

    7285 Posts

  • #6, z sebastianMonday, 13. June 2016, 09:21 hodinky 8 years ago
    Is the custom ini included in the game when I compile it or do I have to create it at game launch again?
    My ini itself works great right now. Thanks to your tutorials.

    Wasn't sure how to implement the language though as there are a lot possibilities

    I tried now to have it like described above but I dont know if it works when the config isnt created at start (or the system language is changed) . I have to look into my start script and check if the ini creation is before checking its content...

    Kapitán

    2346 Posts

  • #7, z afrlmeMonday, 13. June 2016, 12:57 hodinky 8 years ago
    When you compile the game it usually automatically generates one that it includes in the folder that your game gets exported to, but it's only a basic template. The engine automatically searches for a config file in your user folder & if one isn't found then it defaults to the one in your games root folder where the exe file is located.

    The general idea behind config ini files (custom ones) is that you should allow the player to save their changes or you save the changes automatically when they click leave the options menu & then you check if the file exists & if not then you create & write to it. When you open the option screen you should check if the file exists & read it, so that you can correctly update your options screen, which should be ready before it even has time to fade in.

    Quick note: most things inside of the config ini files don't actually get automatically read & executed by the game engine. Mostly it only bothers with things such as resolution, fullscreen, log level & volumes. Volumes are the only thing that get automatically written into the config file without your input, everything else you have to manually write yourself.

    Could you post some screenshots or a video of something of what you have done / tried so far please?

    Imperátor

    7285 Posts

  • #8, z sebastianMonday, 13. June 2016, 15:54 hodinky 8 years ago
    Basically its the script you provided in the wiki.
    I will post my config at evening when im back from work. Thanks so far

    Kapitán

    2346 Posts

  • #9, z afrlmeMonday, 13. June 2016, 15:59 hodinky 8 years ago
    You mean the example script I posted on the wiki! It's meant as a guideline template of options you could potentially include, most of those options require you to manually create actions / scripts to actually make them do what they are supposed to do.

    & ok, no worries mate. wink

    Imperátor

    7285 Posts

  • #10, z sebastianMonday, 13. June 2016, 20:23 hodinky 8 years ago
    Here is what i have right now:
    https://gist.github.com/anonymous/6c123002cb59dc5b85ad97ccd5...

    questionable lines are 62-64 and 132 onwards...
    This solution has no fallback if the line "language=" is not recognized or has an invalid string behind it. I guess i should run the setsystemlanguage() function before reading the config, right?

    So system language gets set at first and then the config ini gets inspected and checks if he can find system, english, or german as a language and overwrite it...


    Because i only have german and english as a language i used a condition which gets set to true(german) or false(english). "system" is only a settings which gets recognized but changes the same condition then to true or false.

    Kapitán

    2346 Posts

  • #11, z afrlmeMonday, 13. June 2016, 21:37 hodinky 8 years ago
    I wouldn't use the system language line at all. Your idea about running the system language function / query first isn't a bad idea at all...

    I would query something like...

    if sytem language is german or austrian or belgian (whichever countries / languages would prefer german over english as default language) then language = german else language = english end

    As you've probably noticed, I've not written it out as it's supposed to be as it's more sort of a suggestion as to what you could query / do for the system language function.

    For the language just query if it's english then set english elseif it's german set german. That way if it's neither then your system language function will have automatically taken care of it beforehand. wink

    Hopefully this will have been some help towards a step in the right direction. If not then let me know.

    Imperátor

    7285 Posts