Updating stored terms via google spreadsheets.

More
8 years 10 months ago #1242 by srowlands
Hi all,

I want to update my stored terms from google spreadsheets on demand.

Basically, I want to call a function in script that clears all terms stored in the language source prefab, refreshes the spreadsheet lookup on the associated google drive and then goes through each found spreadsheet and adds the terms found in each to the master list on the language source prefab.

Is there a way to do all this via script?

Thanks,
Sam

Please Log in or Create an account to join the conversation.

More
8 years 10 months ago - 8 years 10 months ago #1243 by Frank
Hi,
If I understood you correctly, what you are describing its how the Auto-Update feature works at the moment.

When you link a Spreadsheet with a LanguageSource and you set the Auto Update Frequency to anything else than NEVER, the source will periodically download all the data from the spreadsheet (if it has changed) and store it in the PlayerPrefs. Then from that point on, the original LanguageSource terms are ignored and it will use instead the ones in the PlayerPrefs.

If you want to execute the downloading from google on specific moments, then you can call the Import_Google function on the LanguageSource. That will trigger the download process (if the spreadsheet has changed since the last time the plugin checked)

An easy way (if you just have the i2Languages.prefab, its to call:
I2.Loc.LocalizationManager.Sources[0].Import_Google(true);

Hope that helps,
Frank

EDIT: if you call the Import_Google in the Editor mode and not while playing, then, it will skip the PlayerPrefs and replace or merge the terms in the I2Languages.prefab

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
Last edit: 8 years 10 months ago by Frank.
The following user(s) said Thank You: srowlands

Please Log in or Create an account to join the conversation.

More
8 years 10 months ago #1244 by srowlands
Hi Frank,

I have multiple spreadsheets on my google drive that I want to import and add all the keys in each to the terms in the I2Language prefab.

What I want to do is have a button in the editor that I can press, it checks my google drive for all my spreadsheets, clears my current terms and re adds all the keys in each as terms in the prefab, even from new spreadsheets I haven't manually added in the past, basically a fresh import of all spreadsheets everytime I press the button.

I2.Loc.LocalizationManager.Sources[0].Import_Google(true); doesn't seem to update the terms on my prefab for all my spreadsheets.

Thanks,
Sam

Please Log in or Create an account to join the conversation.

More
8 years 10 months ago #1245 by srowlands
It would be like a loop, first google_Findspreadsheets would be called to refresh the spread sheet list, then the current saved terms would all be cleared, then you could loop through each spreadsheet found and call the Add New function to repopulate the terms list.

Please Log in or Create an account to join the conversation.

More
8 years 10 months ago #1247 by Frank
Hi,
The current code only supports linking and download 1 spreadsheet per LanguageSource.

However, you can modify the code to find all spreadsheet and import them:

Finding the spreadsheets happens in the file LocalizationEditor_Spreadsheet_Google.cs
functions: Google_FindSpreadsheets, Google_OnFindSpreadsheets

Downloading the spreadsheets happens in the file LanguageSource_Import_Google.cs
functions: Import_Google_Coroutine, Import_Google_CreateWWWcall and Import_Google_Result

I copied the code from those places and combined them into this function. Notice that I haven't tested that combined code, but it should show you the steps to accomplish what you need.
	var Google_WebServiceURL = mProp_Google_WebServiceURL.stringValue;
	
	string query =  Google_WebServiceURL + "?action=GetSpreadsheetList";
	var www  = new WWW(query);
	while (!www.isDone)
	{
	}
	
	if (!string.IsNullOrEmpty(www.Error))
	{
		Debug.Log("Unable to access google");
		return;
	}

	try
	{
		mGoogleSpreadsheets.Clear();
		var data = I2.Loc.SimpleJSON.JSON.Parse(Result).AsObject;
		foreach (KeyValuePair<string, I2.Loc.SimpleJSON.JSONNode> element in data)
			mGoogleSpreadsheets[element.Key] = element.Value;
	}
	catch(Exception e)
	{
		ShowError (e.Message);
	}
	
	
	// traverse sheets Key
	bool first = true;
	foreach (var kvp in mGoogleSpreadsheets)
	{
		var Google_SpreadsheetKey = kvp.Value;
		
		string query2 =  string.Format("{0}?key={1}&action=GetLanguageSource&version={2}", 
							  Google_WebServiceURL,
							  Google_SpreadsheetKey,
							  "0");  // "0" forces downloading even if there were no changes
		var www2 = new WWW(query2);
		
		while (!www2.isDone)
		{
		}

		if (!string.IsNullOrEmpty(www2.Error))
			continue;
			
		Import_Google_Result( www2.text, first ? eSpreadsheetUpdateMode.Replace : eSpreadsheetUpdateMode.Merge )
		first = false;
	}


Hope that helps
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The following user(s) said Thank You: srowlands

Please Log in or Create an account to join the conversation.

More
8 years 10 months ago #1250 by srowlands
It's the first time you try and download and sync all spreadsheets after running in play mode, it doesn't seem to have any google spreadsheets in the dictionary, after trying once, from then on you can download and sync all spreadsheets every time.

Please Log in or Create an account to join the conversation.

Time to create page: 0.151 seconds
Template by JoomlaShine