Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Classes/Commandlets/GatherTextFromMetadataCommandlet.h
Leon Huang 70f725980e Introduced a Preview cmd line arg to GatherTextCommandlet to allow the gathering of source and asset files without
checking out or writing any localization files. This makes dry runs to print all localization warnings much easier for debugging.
- Introduced the -Preview arg and -GatherType param to UGatherTextCommandlet.
- The -GatherType param can have values of All, Source, Asset or Metadata. Source will only gather source files, Asset will only gather Asset files, Metadata will only gather Metadata and All will gather all 3.
- The -GatherType param is only supported in preview mode right now. This is because manifests are updated every single gather and we don't want the manifest to only reflect partial gathers.
- Added additional logs to display when the commandlet is run with -Preview and -GatherType
- Refactored parts of UGatherTextCommandlet to reduce hard coded switch and param names.
- Introduced a virtual function in UGatherTextCommandletBase to allow commandlets to conditionally be skipped in preview mode.
#rb: Jamie.Dale, Vincent.Gauthier
#jira: UE-143692
#preflight: 62430e4a292f228e09e1e1f8

[CL 19550589 by Leon Huang in ue5-main branch]
2022-03-29 18:01:14 -04:00

102 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Commandlets/GatherTextCommandletBase.h"
#include "GatherTextFromMetadataCommandlet.generated.h"
/**
* UGatherTextFromMetaDataCommandlet: Localization commandlet that collects all text to be localized from generated metadata.
*/
UCLASS()
class UGatherTextFromMetaDataCommandlet : public UGatherTextCommandletBase
{
GENERATED_UCLASS_BODY()
public:
//~ Begin UCommandlet Interface
virtual int32 Main(const FString& Params) override;
//~ End UCommandlet Interface
//~ Begin UGatherTextCommandletBase Interface
virtual bool ShouldRunInPreview(const TArray<FString>& Switches, const TMap<FString, FString>& ParamVals) const override;
//~ End UGatherTextCommandletBase Interface
struct FGatherParameters
{
TArray<FString> InputKeys;
TArray<FString> OutputNamespaces;
TArray<FText> OutputKeys;
};
private:
void GatherTextFromUObjects(const TArray<FString>& IncludePaths, const TArray<FString>& ExcludePaths, const FGatherParameters& Arguments);
void GatherTextFromField(UField* Field, const FGatherParameters& Arguments, const FName InPlatformName);
void GatherTextFromField(FField* Field, const FGatherParameters& Arguments, const FName InPlatformName);
template <typename FieldType>
bool ShouldGatherFromField(const FieldType* Field, const bool bIsEditorOnly);
template <typename FieldType>
void GatherTextFromFieldImpl(FieldType* Field, const FGatherParameters& Arguments, const FName InPlatformName);
template <typename FieldType>
void EnsureFieldDisplayNameImpl(FieldType* Field, const bool bIsBool);
private:
bool ShouldGatherFromEditorOnlyData;
struct FFieldClassFilter
{
explicit FFieldClassFilter(const FFieldClass* InFieldClass)
: FieldClass(InFieldClass)
, ObjectClass(nullptr)
{
}
explicit FFieldClassFilter(const UClass* InObjectClass)
: FieldClass(nullptr)
, ObjectClass(InObjectClass)
{
}
FString GetName() const
{
if (FieldClass)
{
return FieldClass->GetName();
}
if (ObjectClass)
{
return ObjectClass->GetName();
}
return FString();
}
bool TestClass(const FFieldClass* InFieldClass) const
{
return FieldClass && InFieldClass->IsChildOf(FieldClass);
}
bool TestClass(const UClass* InObjectClass) const
{
return ObjectClass && InObjectClass->IsChildOf(ObjectClass);
}
private:
const FFieldClass* FieldClass;
const UClass* ObjectClass;
};
/** Array of field types (eg, FProperty, UFunction, UScriptStruct, etc) that should be included or excluded in the current gather */
TArray<FFieldClassFilter> FieldTypesToInclude;
TArray<FFieldClassFilter> FieldTypesToExclude;
/** Array of field owner types (eg, UMyClass, FMyStruct, etc) that should have fields within them included or excluded in the current gather */
TArray<const UStruct*> FieldOwnerTypesToInclude;
TArray<const UStruct*> FieldOwnerTypesToExclude;
};