Some times it can be convenient to store the localization in your own servers, or provide the players with ways to modify the localization data to create mods.

To make this easy, the plugin allows saving the Spreadsheets and then load them at run time.




Reading the CSV file


If the file is hosted in your own server (e.g. www.inter-illusion/mygame/localization.csv), it can be download by using the WWW class from unity:



// Calling DownloadCSV will download the file and call UseLocalizationCSV with the file content

IEnumerator DownloadCSV()

{

     var www = new WWW("www.inter-illusion/mygame/localization.csv");

     yield return www;    // Wait for the file to be downloaded


  // Check for errors (url not found, no internet, etc)

     if (!string.IsNullOrEmpty(www.error))

     {

           Debug.LogWarning("Unable to download Localization data: " + www.error);

           yield break;

     }


     UseLocalizationCSV( www.text );

}




If the file is stored within the Game:



void ReadCSVFrom_Resources()

{

     var asset = Resources.Load<TextAsset>( "localization.csv");

     

  // Check for errors (file not found)

     if (asset==null)

     {

           Debug.LogWarning("Unable to load Localization data");

           return

     }


     UseLocalizationCSV( asset.text );

}


// This approach is useful for letting the user modify the csv file

void ReadCSVFrom_StreamingFolder()

{

     try{

           var CSVstring = File.ReadAllText(Application.streamingAssetsPath + "/localization.csv");

           UseLocalizationCSV( CSVstring );

     }

     catch (System.Exception e)

     {

           Debug.LogWarning("Unable to load Localization data");

     }

}



Importing the CSV content


Once the file is read, it can be imported into a LanguageSource by using the function Import_CSV.



void UseLocalizationCSV( string CSVfile )

{

   // Source[0] is the I2Languages.prefab

   I2.Loc.LocalizationManager.Sources[0].Import_CSV( string.Empty, CSVfile, eSpreadsheetUpdateMode.Replace, ',');


   LocalizationManager.LocalizeAll();    // Force localing all enabled labels/sprites with the new data

}



Created with the Personal Edition of HelpNDoc: Easily create Web Help sites