Search Unity

Question Custom Localization System

Discussion in 'Scripting' started by BlackSabin, Mar 12, 2023.

  1. BlackSabin

    BlackSabin

    Joined:
    Feb 27, 2021
    Posts:
    75
    So I was following Game Dev Guide's Localization System tutorial stuff. For the most part, everything works just fine but as one of the commenters on the first of the two tutorial videos mentioned, having all of the translated text from every language implemented is an amount of memory unnecessarily loaded. In the interest of changing that, I had begun making some modifications to the system used but I have come across a rather large issue;

    File.AppendAllText and File.WriteAllText failed to write anything.

    I have debug statements showing that the values and arguments passed do in fact include the data I wished to add, and yet no changes were made to the file. No errors in my log either mentioning anything about "failure to access file" or the like. The code runs, and the final debug statement that would show the final change shows an empty string, and the changes are never made. I'm rather puzzled as my understanding and google-fu presents itself like I'm using the statements correctly.
    I have no idea whats going wrong. For clarity; the intended use is to have the LocalizedString draw an extra couple buttons, one of which allows you to "add" a value to the given key. Press the "Add" button on the prompt it shows and presto, we *should* have a new key-value pair in the language file, and the code reloads the assets to reflect it.

    Any clues?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Are you telling AssetDatabase to refresh?
     
  3. BlackSabin

    BlackSabin

    Joined:
    Feb 27, 2021
    Posts:
    75
    Yes. The debug lines I've made shows that it doesn't make it that far though; the file itself doesn't seem to be modified at any point, despite the function calls to do so.
     
  4. BlackSabin

    BlackSabin

    Joined:
    Feb 27, 2021
    Posts:
    75
    Fixed my issue; I missed typing a backslash in the path for the .csv files, so it saved the file somewhere else that it didn't load the files. Oopsies.
     
    Kurt-Dekker likes this.
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,934
    Also worth noting Unity has their own localisation package. It utilises addressables to handle remote content and memory management.

    Worth looking at if you don't want to handle it all yourself.
     
    Bunny83 likes this.