LanguageSourceData_Export_Google.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace I2.Loc
  6. {
  7. public enum eSpreadsheetUpdateMode { None, Replace, Merge, AddNewTerms }
  8. public partial class LanguageSourceData
  9. {
  10. public UnityWebRequest Export_Google_CreateWWWcall( eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace )
  11. {
  12. #if UNITY_WEBPLAYER
  13. Debug.Log ("Contacting google translation is not yet supported on WebPlayer" );
  14. return null;
  15. #else
  16. string Data = Export_Google_CreateData();
  17. WWWForm form = new WWWForm();
  18. form.AddField("key", Google_SpreadsheetKey);
  19. form.AddField("action", "SetLanguageSource");
  20. form.AddField("data", Data);
  21. form.AddField("updateMode", UpdateMode.ToString());
  22. #if UNITY_EDITOR
  23. form.AddField("password", Google_Password);
  24. #endif
  25. UnityWebRequest www = UnityWebRequest.Post(LocalizationManager.GetWebServiceURL(this), form);
  26. I2Utils.SendWebRequest(www);
  27. return www;
  28. #endif
  29. }
  30. string Export_Google_CreateData()
  31. {
  32. List<string> Categories = GetCategories(true);
  33. StringBuilder Builder = new StringBuilder();
  34. bool bFirst = true;
  35. foreach (string category in Categories)
  36. {
  37. if (bFirst)
  38. bFirst = false;
  39. else
  40. Builder.Append("<I2Loc>");
  41. #if !UNITY_EDITOR
  42. bool Spreadsheet_SpecializationAsRows = true;
  43. #endif
  44. string CSV = Export_I2CSV(category, specializationsAsRows:Spreadsheet_SpecializationAsRows);
  45. Builder.Append(category);
  46. Builder.Append("<I2Loc>");
  47. Builder.Append(CSV);
  48. }
  49. return Builder.ToString();
  50. }
  51. }
  52. }