bool UTextProperty::Identical_Implementation(const FText& ValueA, const FText& ValueB, uint32 PortFlags)
{
	if (ValueA.IsCultureInvariant() != ValueB.IsCultureInvariant() || ValueA.IsTransient() != ValueB.IsTransient())
	{
		//A culture variant text is never equal to a culture invariant text
		//A transient text is never equal to a non-transient text
		return false;
	}

	if (ValueA.IsCultureInvariant() == ValueB.IsCultureInvariant() || ValueA.IsTransient() == ValueB.IsTransient())
	{
		//Culture invariant text don't have a namespace/key so we compare the source string
		//Transient text don't have a namespace/key or source so we compare the display string
		return FTextInspector::GetDisplayString(ValueA) == FTextInspector::GetDisplayString(ValueB);
	}

	if (GIsEditor)
	{
		return FTextInspector::GetSourceString(ValueA)->Compare(*FTextInspector::GetSourceString(ValueB), ESearchCase::CaseSensitive) == 0;
	}
	else
	{
		return	FTextInspector::GetNamespace(ValueA) == FTextInspector::GetNamespace(ValueB) &&
			FTextInspector::GetKey(ValueA) == FTextInspector::GetKey(ValueB);
	}
}
Example #2
0
void UEdGraphSchema::TrySetDefaultText(UEdGraphPin& InPin, const FText& InNewDefaultText) const
{
	if(InNewDefaultText.IsEmpty())
	{
		InPin.DefaultTextValue = InNewDefaultText;
	}
	else
	{
#if WITH_EDITOR
		if(InNewDefaultText.IsCultureInvariant())
		{
			InPin.DefaultTextValue = InNewDefaultText;
		}
		else
		{
			InPin.DefaultTextValue = FText::ChangeKey(TEXT(""), InPin.GetOwningNode()->NodeGuid.ToString() + TEXT("_") + InPin.PinName, InNewDefaultText);
		}
#endif
	}

#if WITH_EDITOR
	UEdGraphNode* Node = InPin.GetOwningNode();
	check(Node);
	Node->PinDefaultValueChanged(&InPin);
#endif	//#if WITH_EDITOR
}
bool UKismetTextLibrary::TextIsCultureInvariant(const FText& InText)
{
	return InText.IsCultureInvariant();
}
FString UTextProperty::GenerateCppCodeForTextValue(const FText& InValue, const FString& Indent)
{
	FString CppCode;

	const FString& StringValue = FTextInspector::GetDisplayString(InValue);

	if (InValue.IsEmpty())
	{
		CppCode += TEXT("FText::GetEmpty()");
	}
	else if (InValue.IsCultureInvariant())
	{
		// Produces FText::AsCultureInvariant(TEXT("..."))
		CppCode += TEXT("FText::AsCultureInvariant(");
		CppCode += UStrProperty::ExportCppHardcodedText(StringValue, Indent + TEXT("\t"));
		CppCode += TEXT(")");
	}
	else
	{
		bool bIsLocalized = false;
		FString Namespace;
		FString Key;
		const FString* SourceString = FTextInspector::GetSourceString(InValue);

		if (SourceString && InValue.ShouldGatherForLocalization())
		{
			bIsLocalized = FTextLocalizationManager::Get().FindNamespaceAndKeyFromDisplayString(FTextInspector::GetSharedDisplayString(InValue), Namespace, Key);
		}

		if (bIsLocalized)
		{
			// Produces FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText(TEXT("..."), TEXT("..."), TEXT("..."))
			CppCode += TEXT("FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText(\n");

			CppCode += Indent;
			CppCode += TEXT("\t");
			CppCode += UStrProperty::ExportCppHardcodedText(*SourceString, Indent + TEXT("\t\t"));
			CppCode += TEXT(", /* Literal Text */\n");

			CppCode += Indent;
			CppCode += TEXT("\t");
			CppCode += UStrProperty::ExportCppHardcodedText(Namespace, Indent + TEXT("\t\t"));
			CppCode += TEXT(", /* Namespace */\n");

			CppCode += Indent;
			CppCode += TEXT("\t");
			CppCode += UStrProperty::ExportCppHardcodedText(Key, Indent + TEXT("\t\t"));
			CppCode += TEXT(" /* Key */\n");

			CppCode += Indent;
			CppCode += TEXT("\t)");
		}
		else
		{
			// Produces FText::FromString(TEXT("..."))
			CppCode += TEXT("FText::FromString(");
			CppCode += UStrProperty::ExportCppHardcodedText(StringValue, Indent + TEXT("\t"));
			CppCode += TEXT(")");
		}
	}

	return CppCode;
}