Using a LanguageSourceAsset outside of Resources?

More
6 years 3 weeks ago - 6 years 3 weeks ago #3319 by GFX47
Hi! I'm Sébastien/@GFX47, a french solo dev making Gladiabots.
I'm currently working on the localization of the game and giving I2Localization a try.

The thing is I'd like to avoid using the LanguageSource component in a scene I'd have to save every time I change terms.
Also I'm not a big fan of Unity's resources system that can be problematic in some cases.
So right now I'm using a LanguageSourceAsset (I've placed in a dedicated project folder) that I'm referencing in my localization manager component.
Basically my code is:
public LanguageSourceAsset sourceAsset;

private void AddSourceToLocalizationManager()
{
	I2.Loc.LocalizationManager.AddSource(this.sourceAsset.mSource);
	this.sourceAsset.mSource.owner = this;
}

private void Awake()
{
	this.AddSourceToLocalizationManager();
}

I also call the AddSourceToLocalizationManager method before doing anything related to localization in editor mode (game stopped).
But the problem is the owner reference often gets lost (probably because of the NonSerialized attribute), causing all kinds of null reference exceptions while using features like auto translation or category change.

The pieces of code raising those exceptions are most of the time something like that:
#if UNITY_EDITOR
	UnityEditor.EditorUtility.SetDirty(i2source.owner);
#endif

So my first question is: is there an option to disable the auto-creation of the I2Languages?
Second question: would you consider supporting the usage of LanguageSourceAsset outside of the Resources folder?
Last edit: 6 years 3 weeks ago by GFX47.

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

More
6 years 3 weeks ago #3321 by Frank
Hi,

I'm not a big fan of Unity's resources system that can be problematic in some cases.
So right now I'm using a LanguageSourceAsset (I've placed in a dedicated project folder) that I'm referencing in my localization manager component.


Given that the I2Languages.asset is loaded all the time, there is no real benefit of not using it from the Resources folder.
That should only be considered (as far as I know), in cases where you need to load and then unload assets. But the LanguageSource is always loaded, so, memory and performance wise, the benefits of not using the Resources may not be worth the trouble of the changes needed to handle that.

Said that, if you still prefer using a reference, you should add the source in the UpdateSource function of the LocalizationManager. (Assets\I2\Localization\Scripts\Manager\LocalizationManager_Sources.cs) line 22.
That way, it will be accessible whenever the plugin needs it.

Something like:
public static bool UpdateSources()
{
	UnregisterDeletededSources();
	RegisterSourceInResources();
	RegisterSceneSources();

	LanguageSourceData newSource = YourLocalizationManager.singleton.sourceAsset.Source.mSource;
	if (!Sources.Contains(newSource))
	{
		AddSource(newSource);
	}
	return Sources.Count>0;
}

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: GFX47

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

More
6 years 3 weeks ago #3324 by GFX47
Thanks for your answer! I'll try that.

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

Time to create page: 0.172 seconds
Template by JoomlaShine