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

Question Can the localizer be used to debug how the game runs in other Languages?

Discussion in 'Localization Tools' started by DaveKap, Aug 15, 2023.

  1. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    This might seem like a "duh" kind of question but allow me to elaborate.

    I do no localization whatsoever in my English game. A part of my game generates a .json compatible string, which gets salted and hashed and written to a file as a means of creating an obfuscated saved state. Recently, I've had a user report that the game seems to load this file in a corrupted state on their mobile devices and their PC. The fact this user had the same issue across all devices seemed odd as nobody else has reported the same problems. With a little conversation, I realized the connection is the fact that their devices are all natively Russian. It turns out that in the Russian language, decimals use a comma instead of a period. Seeing as how commas are meant to separate data in my .json string, perhaps this is where the problems are arising.

    I've installed the Localization package, generated the Russian locale, and set the only available locale to be (ru) with both the specific locale selector and project identifier as (ru). I also set and verified the locale within the code. I also added a Pseudo-Locale asset to the project, which seems to confirm the fact that the decimal symbol is a period. I've done no extra work past this, as I still do not plan on localizing my game and don't wish to learn the entirety of this package just to solve 1 bug. Thus far, I have been unable to reproduce the bug my user reported and the .json string generation still seems the same.

    Am I using the localizer package correctly and it turns out the bug is not related to language after all or is there more setup that I'm failing to understand?

    Edit: With a little more help from my user, we determined that the files are actually being written in a valid manner. It appears the reading of the files is broken, somewhere with the Encoding.UTF8.GetString method or the Convert.FromBase64String method. Google isn't telling me anything about problems these methods have on Russian machines so any help would be appreciated, although I am unsure this is the correct forum for this now. The question still stands if my localization package settings are supposed to reproduce these bugs or not.
     
    Last edited: Aug 15, 2023
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    The localization package won't be able to help you here. The reason the formatting is different will be due to the active Culture on the machine. We avoid changing the device culture as it can cause issues such as the one you are describing.
    When you call ToString on certain values, such as ints, floats etc, it will perform formatting using the current culture.
    See Remarks: https://learn.microsoft.com/en-us/d...2.tostring?view=net-7.0#system-int32-tostring

    If you have control, use the Invariant culture when formatting:

    Code (csharp):
    1. myInt.ToString(CultureInfo.InvariantCulture)
    A lot of Json serializers will already use invariant by default
    https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonSerializer_Culture.htm

    If you do this before your code then you should be able to reproduce the issue:

    Code (csharp):
    1. CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("ru");
     
  3. DaveKap

    DaveKap

    Joined:
    Mar 6, 2013
    Posts:
    94
    Last edited: Aug 15, 2023
    karl_jones likes this.