Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path logic and validation for UE5 #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Source/BYGLocalization/Private/BYGLocalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ TArray<FString> UBYGLocalization::GetAllLocalizationFiles() const
for ( const FDirectoryPath& Path : Paths )
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
// Directory Path will probably be /Game/Somethingd
FString LocalizationDirPath = Path.Path.Replace( TEXT( "/Game" ), *FPaths::ProjectContentDir() );
FPaths::RemoveDuplicateSlashes( LocalizationDirPath );
bool bFound = false;
TArray<FString> LocalFiles;
PlatformFile.IterateDirectoryRecursively( *LocalizationDirPath, [&bFound, &PlatformFile, &Files, &Settings]( const TCHAR* InFilenameOrDirectory, const bool bIsDir ) -> bool
// Directory Path will probably be /Localization
FString LocalizationDirPath = *FPaths::ProjectContentDir() / Path.Path;
PlatformFile.IterateDirectoryRecursively( *LocalizationDirPath, [&Files, &Settings]( const TCHAR* InFilenameOrDirectory, const bool bIsDir ) -> bool
{
// Find all .txt/.csv files in a dir
if ( !bIsDir )
Expand All @@ -68,15 +65,13 @@ TArray<FString> UBYGLocalization::GetAllLocalizationFiles() const
&& ( Settings->FilenameSuffix.IsEmpty() || BaseName.EndsWith( Settings->FilenameSuffix ) ) )
{
FString NewPath = InFilenameOrDirectory;
FPaths::RemoveDuplicateSlashes( NewPath );
FPaths::MakePathRelativeTo( NewPath, *FPaths::ProjectContentDir() );
Files.Add( NewPath );
}
}
// return true to continue searching
return true;
} );
Files.Append( LocalFiles );
}

return Files;
Expand Down
15 changes: 14 additions & 1 deletion Source/BYGLocalization/Private/BYGLocalizationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

UBYGLocalizationSettings::UBYGLocalizationSettings( const FObjectInitializer& ObjectInitializer )
{
PrimaryLocalizationDirectory.Path = "/Localization/";
PrimaryLocalizationDirectory.Path = "Localization";
}


Expand All @@ -33,6 +33,18 @@ bool UBYGLocalizationSettings::Validate()
bAnyChanges = true;
}

if ( PrimaryLocalizationDirectory.Path.StartsWith( TEXT( "/" ) ) )
{
PrimaryLocalizationDirectory.Path = PrimaryLocalizationDirectory.Path.RightChop( 1 );
bAnyChanges = true;
}

if ( PrimaryLocalizationDirectory.Path.StartsWith( TEXT( "Game/" ) ) )
{
PrimaryLocalizationDirectory.Path = PrimaryLocalizationDirectory.Path.RightChop( 5 );
bAnyChanges = true;
}

if ( bUpdateLocsWithCommandLineFlag && CommandLineFlag.IsEmpty() )
{
CommandLineFlag = "UpdateLoc";
Expand All @@ -57,6 +69,7 @@ void UBYGLocalizationSettings::PostEditChangeProperty( struct FPropertyChangedEv
|| ( PropertyChangedEvent.GetPropertyName() == GET_MEMBER_NAME_CHECKED( UBYGLocalizationSettings, AllowedExtensions ) )
)
{
Validate();
FBYGLocalizationModule::Get().ReloadLocalizations();
}

Expand Down