NULL Reference Error:

More
9 years 1 month ago #525 by gdbj
NULL Reference Error: was created by gdbj
Hello, thought I would pass this along. Received a NULL Reference error when I clicked "Translate" in the Editor. Looks like ` www.text ` is coming back null, if I had my guess. I'm going to poke at it a bit and see if I can see why this is.

NullReferenceException: Object reference not set to an instance of an object
I2.Loc.GoogleTranslation.ForceTranslate (System.String text, System.String LanguageCodeFrom, System.String LanguageCodeTo) (at Assets/ThirdParty/I2/Localization/Scripts/Google/GoogleTranslation.cs:50)
I2.Loc.LocalizationEditor.Translate (System.String Key, I2.Loc.TermData& termdata, System.String& sTarget, System.String TargetLanguageCode) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Localization/LocalizationEditor_Terms_Description.cs:331)
I2.Loc.LocalizationEditor.OnGUI_Keys_Languages (System.String Key, I2.Loc.Localize localizeCmp, Boolean IsPrimaryKey) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Localization/LocalizationEditor_Terms_Description.cs:195)
I2.Loc.LocalizeInspector.OnGUI_PrimaryTerm (Boolean OnOpen) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:217)
I2.Loc.LocalizeInspector.OnGUI_Terms () (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:176)
I2.Loc.LocalizeInspector.OnInspectorGUI () (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:87)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty)
UnityEditor.DockArea:OnGUI()

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

More
9 years 1 month ago #526 by gdbj
Replied by gdbj on topic NULL Reference Error:
Actually, it was the text to translate. For some reason this was NULL.

It magically started working again now, so not sure what changed, or why the text to be translated started coming through again. Strange.

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

More
9 years 1 month ago #527 by gdbj
Replied by gdbj on topic NULL Reference Error:
Problem is back.

Steps I took:

Instantiated a prefab item (a UI.Button), with a UI.Text object as a child. The child has a Localize script attached.

The Localize script detected the new term, and codemagically added it to the Terms drop-down list. I added a description. Then for English (United States) I clicked translate.

NullReferenceException: Object reference not set to an instance of an object
I2.Loc.GoogleTranslation.ForceTranslate (System.String text, System.String LanguageCodeFrom, System.String LanguageCodeTo) (at Assets/ThirdParty/I2/Localization/Scripts/Google/GoogleTranslation.cs:51)
I2.Loc.LocalizationEditor.Translate (System.String Key, I2.Loc.TermData& termdata, System.String& sTarget, System.String TargetLanguageCode) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Localization/LocalizationEditor_Terms_Description.cs:331)
I2.Loc.LocalizationEditor.OnGUI_Keys_Languages (System.String Key, I2.Loc.Localize localizeCmp, Boolean IsPrimaryKey) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Localization/LocalizationEditor_Terms_Description.cs:195)
I2.Loc.LocalizeInspector.OnGUI_PrimaryTerm (Boolean OnOpen) (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:217)
I2.Loc.LocalizeInspector.OnGUI_Terms () (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:176)
I2.Loc.LocalizeInspector.OnInspectorGUI () (at Assets/ThirdParty/I2/Localization/Scripts/Editor/Inspectors/LocalizeInspector.cs:87)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty)
UnityEditor.DockArea:OnGUI()

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

More
9 years 1 month ago #528 by Frank
Replied by Frank on topic NULL Reference Error:
Hi
I was able to verify that issue. The problem is that when you click the Translate button, it tries translating using one of the translations already set. So, you need to write at least 1 translation so that google could translate that to other languages.

I just changed that behavior so that if no translation is set, then it translate the Term name.

Terms don't usually need to match whats translated (e.g. Term: "TIP 1" = "Refill your energy before every race") but in most situation developers name the terms closely to whats been translated ("PLAY" = "Play").

That change is going to be released as part of 2.4.4. But there has been a delay in the AssetStore approval process because of GDC, and I'm still waiting in the queue for version 2.4.3f1 to be approved.

Nonetheless, you can make a quick modification in the code to make it work for you:

Just need to replace function Translate in I2\Localization\Scripts\Editor\Localization\LocalizationEditor_Terms_Description.cs line 348
by this one:
		static void Translate ( string Key, ref TermData termdata, ref string sTarget, string TargetLanguageCode )
		{
			#if UNITY_WEBPLAYER
			ShowError ("Contacting google translation is not yet supported on WebPlayer" );
			#else
			// Translate first language that has something
			// If no language found, translation will fallback to autodetect language from key
			string SourceCode = "auto";
			string text = Key;
			
			for (int i=0, imax=termdata.Languages.Length; i<imax; ++i)
				if (!string.IsNullOrEmpty(termdata.Languages[i]))
				{
					text = termdata.Languages[i];
					if (mLanguageSource.mLanguages[i].Code != TargetLanguageCode)
					{
						SourceCode = mLanguageSource.mLanguages[i].Code;
						break;
					}
				}
			sTarget = GoogleTranslation.ForceTranslate( text, SourceCode, TargetLanguageCode );
			
			#endif
		}

Thanks,
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

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

More
9 years 1 month ago #529 by gdbj
Replied by gdbj on topic NULL Reference Error:
Ah, this makes a lot of sense. In truth, I wondered at translating English to English. This felt a bit awkward. So, the intention is to write in the phase you want for the given term in the first row of the language options, and then hitting "Translate" on the sibling rows, which will translate based on what's entered on the top line.

Your line number below doesn't match mine, so I will hold off on editing the source code, and will use the tool as expected instead.

Just a UI suggestion which you've probably already considered: put a text box in that indicates that it is the "master" phrase from which the following rows in the table will be translated from. When this master field is empty and I click Translate, it is then obvious why the translation comes back empty / fails.

Despite this small thing, the tool is exceptional. And crowd-sourced translations is a fantastic idea, assuming quality can be determined. I will watch for future products.

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

Time to create page: 0.612 seconds
Template by JoomlaShine