Esempio n. 1
0
void FTextHistory_Base::SerializeForDisplayString(FArchive& Ar, FTextDisplayStringRef& InOutDisplayString)
{
	if(Ar.IsLoading())
	{
		// We will definitely need to do a rebuild later
		Revision = INDEX_NONE;

		FString Namespace;
		FString Key;
		FString SourceStringRaw;

		Ar << Namespace;
		Ar << Key;
		Ar << SourceStringRaw;

		// If there was a SourceString, store it in the member variable
		if(!SourceStringRaw.IsEmpty())
		{
			SourceString = MakeShareable(new FString(SourceStringRaw));
		}

		// Using the deserialized namespace and key, find the DisplayString.
		InOutDisplayString = FTextLocalizationManager::Get().GetDisplayString(Namespace, Key, SourceString.Get());
	}
	else if(Ar.IsSaving())
	{
		FString Namespace;
		FString Key;

		const bool FoundNamespaceAndKey = FTextLocalizationManager::Get().FindNamespaceAndKeyFromDisplayString(InOutDisplayString, Namespace, Key);

		// If this has no namespace or key, attempt to give it a GUID for a key and register it.
		if (!FoundNamespaceAndKey && GIsEditor && (Ar.IsPersistent() && !Ar.HasAnyPortFlags(PPF_Duplicate)))
		{
			Key = FGuid::NewGuid().ToString();
			if (!FTextLocalizationManager::Get().AddDisplayString(InOutDisplayString, Namespace, Key))
			{
				// Could not add display string, reset namespace and key.
				Namespace.Empty();
				Key.Empty();
			}
		}

		// Serialize the Namespace
		Ar << Namespace;

		// Serialize the Key
		Ar << Key;

		// Serialize the SourceString, or an empty string if there is none
		if( SourceString.IsValid() )
		{
			Ar << *(SourceString);
		}
		else
		{
			FString Empty;
			Ar << Empty;
		}
	}
}