5#include "Internationalization/Text.h"
6#include "Internationalization/TextPackageNamespaceUtil.h"
7#include "Serialization/TextReferenceCollector.h"
12 const auto* Settings = GetDefault<UDlgSystemSettings>();
29 OutText = RemappedText;
40 static const FString DefaultValue = TEXT(
"");
51 if (!GetNewNamespaceAndKey(
Object, Settings, Text, NewNamespace, NewKey))
59 Text = FText::ChangeKey(NewNamespace, NewKey, Text);
62bool FDlgLocalizationHelper::GetNewNamespaceAndKey(
66 FString& OutNewNamespace,
70 static const FString DefaultValue = TEXT(
"");
76 if (!Text.ShouldGatherForLocalization())
85 bool bNamespaceChanged =
false;
86 bool bKeyChanged =
false;
88 const FString CurrentFullNamespace = FTextInspector::GetNamespace(Text).Get(DefaultValue);
89 const FString CurrentKey = FTextInspector::GetKey(Text).Get(DefaultValue);
90 FString NewKey = CurrentKey;
96 NewNamespace =
Object->GetName();
105#if USE_STABLE_LOCALIZATION_KEYS
108 const UPackage* Package =
Object ?
Object->GetOutermost() :
nullptr;
109 const FString PackageNamespace = TextNamespaceUtil::EnsurePackageNamespace(
const_cast<UPackage*
>(Package));
110 const FString NewFullNamespace = TextNamespaceUtil::BuildFullNamespace(NewNamespace, PackageNamespace,
true);
111 bNamespaceChanged = !CurrentFullNamespace.Equals(NewFullNamespace, ESearchCase::CaseSensitive);
115 const FString CurrentNamespace = TextNamespaceUtil::StripPackageNamespace(CurrentFullNamespace);
116 bNamespaceChanged = !CurrentNamespace.Equals(NewNamespace, ESearchCase::CaseSensitive);
124#if USE_STABLE_LOCALIZATION_KEYS
125 if (bNamespaceChanged)
128 const FString& TextSource = *FTextInspector::GetSourceString(Text);
129 FString NewStableNamespace;
130 FString NewStableKey;
133 IEditableTextProperty::ETextPropertyEditAction::EditedNamespace,
140 NewNamespace = NewStableNamespace;
141 NewKey = NewStableKey;
146 bKeyChanged = !CurrentKey.Equals(NewKey, ESearchCase::CaseSensitive);
149 if (bNamespaceChanged || bKeyChanged)
151 OutNewNamespace = NewNamespace;
160#if USE_STABLE_LOCALIZATION_KEYS
162void FDlgLocalizationHelper::StaticStableTextId(
const UObject* InObject, IEditableTextProperty::ETextPropertyEditAction InEditAction,
const FString& InTextSource,
const FString& InProposedNamespace,
const FString& InProposedKey, FString& OutStableNamespace, FString& OutStableKey)
164 const UPackage* Package = InObject ? InObject->GetOutermost() :
nullptr;
165 StaticStableTextId(Package, InEditAction, InTextSource, InProposedNamespace, InProposedKey, OutStableNamespace, OutStableKey);
168void FDlgLocalizationHelper::StaticStableTextId(
const UPackage* InPackage, IEditableTextProperty::ETextPropertyEditAction InEditAction,
const FString& InTextSource,
const FString& InProposedNamespace,
const FString& InProposedKey, FString& OutStableNamespace, FString& OutStableKey)
170 bool bPersistKey =
false;
172 const FString PackageNamespace = TextNamespaceUtil::EnsurePackageNamespace(
const_cast<UPackage*
>(InPackage));
173 if (!PackageNamespace.IsEmpty())
176 OutStableNamespace = TextNamespaceUtil::BuildFullNamespace(InProposedNamespace, PackageNamespace,
true);
178 if (InProposedNamespace.Equals(OutStableNamespace, ESearchCase::CaseSensitive) || InEditAction == IEditableTextProperty::ETextPropertyEditAction::EditedNamespace)
181 if (!InProposedKey.IsEmpty())
185 const FTextReferenceCollector::EComparisonMode ReferenceComparisonMode = InEditAction == IEditableTextProperty::ETextPropertyEditAction::EditedSource ? FTextReferenceCollector::EComparisonMode::MatchId : FTextReferenceCollector::EComparisonMode::MismatchSource;
186 const int32 RequiredReferenceCount = InEditAction == IEditableTextProperty::ETextPropertyEditAction::EditedSource ? 1 : 0;
188 int32 ReferenceCount = 0;
189 FTextReferenceCollector(InPackage, ReferenceComparisonMode, OutStableNamespace, InProposedKey, InTextSource, ReferenceCount);
191 if (ReferenceCount == RequiredReferenceCount)
194 OutStableKey = InProposedKey;
198 else if (InEditAction != IEditableTextProperty::ETextPropertyEditAction::EditedNamespace)
202 OutStableNamespace = TextNamespaceUtil::BuildFullNamespace(FString(), PackageNamespace,
true);
208 OutStableKey = FGuid::NewGuid().ToString();
static void UpdateTextFromRemapping(const UDlgSystemSettings &Settings, FText &OutText)
static bool WillTextNamespaceBeUpdated(const FText &Text)
static void UpdateTextNamespaceAndKey(const UObject *Object, const UDlgSystemSettings &Settings, FText &Text)
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
EDlgTextNamespaceLocalization DialogueTextNamespaceLocalization
UPROPERTY(Category = "Localization", Config, EditAnywhere, DisplayName = "Text Namespace")
FString DialogueTextPrefixNamespaceName
UPROPERTY(Category = "Localization", Config, EditAnywhere, DisplayName = "Text Namespace Name Prefix"...
FString DialogueTextGlobalNamespaceName
UPROPERTY(Category = "Localization", Config, EditAnywhere, DisplayName = "Text Global Namespace Name"...
bool IsIgnoredTextForLocalization(const FText &Text) const
FORCEINLINE const FText & GetTextRemappedText(const FText &Text) const
FORCEINLINE bool IsTextRemapped(const FText &Text) const