2015-03-18 19:14:43 -04:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2015-01-27 16:31:40 -05:00
# include "LocalizationDashboardPrivatePCH.h"
# include "LocalizationConfigurationScript.h"
2015-03-28 19:17:15 -04:00
# include "LocalizationTargetTypes.h"
# include "LocalizationDashboardSettings.h"
2015-01-27 16:31:40 -05:00
2015-03-09 18:56:46 -04:00
namespace
{
FString GetConfigDir ( const ULocalizationTarget * const Target )
{
2015-03-12 19:41:56 -04:00
return Target - > IsMemberOfEngineTargetSet ( ) ? FPaths : : EngineConfigDir ( ) : FPaths : : GameConfigDir ( ) ;
2015-03-09 18:56:46 -04:00
}
FString GetContentDir ( const ULocalizationTarget * const Target )
{
2015-03-12 19:41:56 -04:00
return Target - > IsMemberOfEngineTargetSet ( ) ? FPaths : : EngineContentDir ( ) : FPaths : : GameContentDir ( ) ;
2015-03-09 18:56:46 -04:00
}
}
2015-01-27 16:31:40 -05:00
namespace LocalizationConfigurationScript
{
2015-03-12 19:41:56 -04:00
FString MakePathRelativeForCommandletProcess ( const FString & Path , const bool IsUsingProjectFile )
2015-01-27 16:31:40 -05:00
{
FString Result = Path ;
2015-03-12 19:41:56 -04:00
const FString ProjectDir = ! IsUsingProjectFile ? FPaths : : EngineDir ( ) : FPaths : : GameDir ( ) ;
FPaths : : MakePathRelativeTo ( Result , * ProjectDir ) ;
2015-01-27 16:31:40 -05:00
return Result ;
}
2015-03-09 18:56:46 -04:00
FString GetScriptDirectory ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
return GetConfigDir ( Target ) / TEXT ( " Localization " ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetDataDirectory ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
return GetContentDir ( Target ) / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
TArray < FString > GetScriptPaths ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
TArray < FString > Result ;
Result . Add ( GetGatherScriptPath ( Target ) ) ;
Result . Add ( GetImportScriptPath ( Target ) ) ;
Result . Add ( GetExportScriptPath ( Target ) ) ;
2015-03-18 19:14:43 -04:00
Result . Add ( GetWordCountReportScriptPath ( Target ) ) ;
2015-01-27 16:31:40 -05:00
return Result ;
}
2015-03-09 15:38:32 -04:00
FString GetManifestPath ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
return GetDataDirectory ( Target ) / FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " manifest " ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetArchivePath ( const ULocalizationTarget * const Target , const FString & CultureName )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
return GetDataDirectory ( Target ) / CultureName / FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " archive " ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetDefaultPOFileName ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
return FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " po " ) ) ;
2015-01-30 16:29:01 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetDefaultPOPath ( const ULocalizationTarget * const Target , const FString & CultureName )
2015-01-30 16:29:01 -05:00
{
return GetDataDirectory ( Target ) / CultureName / GetDefaultPOFileName ( Target ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetLocResPath ( const ULocalizationTarget * const Target , const FString & CultureName )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
return GetDataDirectory ( Target ) / CultureName / FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " locres " ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetWordCountCSVPath ( const ULocalizationTarget * const Target )
2015-01-30 17:29:25 -05:00
{
2015-03-09 15:38:32 -04:00
return GetDataDirectory ( Target ) / FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " csv " ) ) ;
2015-01-30 17:29:25 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetConflictReportPath ( const ULocalizationTarget * const Target )
2015-01-30 17:29:25 -05:00
{
2015-03-09 15:38:32 -04:00
return GetDataDirectory ( Target ) / FString : : Printf ( TEXT ( " %s_Conflicts.%s " ) , * Target - > Settings . Name , TEXT ( " txt " ) ) ;
2015-01-30 17:29:25 -05:00
}
2015-03-09 15:38:32 -04:00
FLocalizationConfigurationScript GenerateGatherScript ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
FLocalizationConfigurationScript Script ;
2015-03-12 19:41:56 -04:00
const FString ConfigDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetConfigDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
const FString ContentDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetContentDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-27 16:31:40 -05:00
// CommonSettings
{
FConfigSection & ConfigSection = Script . CommonSettings ( ) ;
2015-03-04 22:31:03 -05:00
const ULocalizationTargetSet * const LocalizationTargetSet = GetDefault < ULocalizationTargetSet > ( ULocalizationTargetSet : : StaticClass ( ) ) ;
2015-03-26 20:23:29 -04:00
for ( const FGuid & TargetDependencyGuid : Target - > Settings . TargetDependencies )
2015-01-27 16:31:40 -05:00
{
2015-03-18 22:22:06 -04:00
TArray < ULocalizationTarget * > AllLocalizationTargets ;
2015-03-28 19:17:15 -04:00
ULocalizationTargetSet * EngineTargetSet = ULocalizationDashboardSettings : : GetEngineTargetSet ( ) ;
2015-03-18 22:22:06 -04:00
if ( EngineTargetSet ! = LocalizationTargetSet )
{
AllLocalizationTargets . Append ( EngineTargetSet - > TargetObjects ) ;
}
AllLocalizationTargets . Append ( LocalizationTargetSet - > TargetObjects ) ;
2015-04-10 11:23:49 -04:00
ULocalizationTarget * const * OtherTarget = AllLocalizationTargets . FindByPredicate ( [ & TargetDependencyGuid ] ( ULocalizationTarget * const InOtherTarget ) - > bool { return InOtherTarget - > Settings . Guid = = TargetDependencyGuid ; } ) ;
2015-01-27 16:31:40 -05:00
if ( OtherTarget )
{
2015-03-12 19:41:56 -04:00
ConfigSection . Add ( TEXT ( " ManifestDependencies " ) , MakePathRelativeForCommandletProcess ( GetManifestPath ( * OtherTarget ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ) ;
2015-01-27 16:31:40 -05:00
}
}
2015-03-09 15:38:32 -04:00
for ( const FFilePath & Path : Target - > Settings . AdditionalManifestDependencies )
2015-01-27 16:31:40 -05:00
{
2015-03-12 19:41:56 -04:00
ConfigSection . Add ( TEXT ( " ManifestDependencies " ) , MakePathRelativeForCommandletProcess ( Path . FilePath , ! Target - > IsMemberOfEngineTargetSet ( ) ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-12 19:57:57 -04:00
for ( const FString & ModuleName : Target - > Settings . RequiredModuleNames )
{
ConfigSection . Add ( TEXT ( " ModulesToPreload " ) , ModuleName ) ;
}
2015-03-09 15:38:32 -04:00
const FString SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
2015-03-09 15:38:32 -04:00
const FString DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
ConfigSection . Add ( TEXT ( " ManifestName " ) , FPaths : : GetCleanFilename ( GetManifestPath ( Target ) ) ) ;
ConfigSection . Add ( TEXT ( " ArchiveName " ) , FPaths : : GetCleanFilename ( GetArchivePath ( Target , FString ( ) ) ) ) ;
2015-03-09 15:38:32 -04:00
ConfigSection . Add ( TEXT ( " SourceCulture " ) , Target - > Settings . NativeCultureStatistics . CultureName ) ;
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , Target - > Settings . NativeCultureStatistics . CultureName ) ;
for ( const FCultureStatistics & CultureStatistics : Target - > Settings . SupportedCulturesStatistics )
2015-01-27 16:31:40 -05:00
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureStatistics . CultureName ) ;
}
}
uint32 GatherTextStepIndex = 0 ;
// GatherTextFromSource
2015-03-09 15:38:32 -04:00
if ( Target - > Settings . GatherFromTextFiles . SearchDirectories . Num ( ) & & Target - > Settings . GatherFromTextFiles . FileExtensions . Num ( ) ) // Don't gather from source if there are no source files.
2015-01-27 16:31:40 -05:00
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GatherTextFromSource " ) ) ;
// Include Paths
2015-03-09 15:38:32 -04:00
for ( const auto & IncludePath : Target - > Settings . GatherFromTextFiles . SearchDirectories )
2015-01-27 16:31:40 -05:00
{
2015-03-06 18:22:14 -05:00
ConfigSection . Add ( TEXT ( " IncludePaths " ) , IncludePath ) ;
2015-01-27 16:31:40 -05:00
}
// Exclude Paths
2015-03-12 19:41:56 -04:00
ConfigSection . Add ( TEXT ( " ExcludePaths " ) , TEXT ( " */Config/Localization/* " ) ) ;
2015-03-09 15:38:32 -04:00
for ( const auto & ExcludePath : Target - > Settings . GatherFromTextFiles . ExcludePathWildcards )
2015-01-27 16:31:40 -05:00
{
2015-03-06 18:22:14 -05:00
ConfigSection . Add ( TEXT ( " ExcludePaths " ) , ExcludePath ) ;
}
// Source File Search Filters
2015-03-09 15:38:32 -04:00
for ( const auto & FileExtension : Target - > Settings . GatherFromTextFiles . FileExtensions )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " SourceFileSearchFilters " ) , FileExtension ) ;
2015-01-27 16:31:40 -05:00
}
}
// GatherTextFromAssets
2015-03-18 14:19:52 -04:00
if ( Target - > Settings . GatherFromPackages . IncludePathWildcards . Num ( ) & & Target - > Settings . GatherFromPackages . FileExtensions . Num ( ) ) // Don't gather from packages if there are none specified.
2015-01-27 16:31:40 -05:00
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GatherTextFromAssets " ) ) ;
2015-03-06 18:22:14 -05:00
// Include Paths
2015-03-09 15:38:32 -04:00
for ( const auto & IncludePath : Target - > Settings . GatherFromPackages . IncludePathWildcards )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " IncludePaths " ) , IncludePath ) ;
}
2015-01-27 16:31:40 -05:00
2015-03-06 18:22:14 -05:00
// Exclude Paths
2015-03-12 19:41:56 -04:00
ConfigSection . Add ( TEXT ( " ExcludePaths " ) , TEXT ( " */Content/Localization/* " ) ) ;
2015-03-09 15:38:32 -04:00
for ( const auto & ExcludePath : Target - > Settings . GatherFromPackages . ExcludePathWildcards )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " ExcludePaths " ) , ExcludePath ) ;
}
2015-01-27 16:31:40 -05:00
2015-03-06 18:22:14 -05:00
// Package Extensions
2015-03-09 15:38:32 -04:00
for ( const auto & FileExtension : Target - > Settings . GatherFromPackages . FileExtensions )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " PackageExtensions " ) , FileExtension ) ;
}
}
// GatherTextFromMetadata
2015-03-09 15:38:32 -04:00
if ( Target - > Settings . GatherFromMetaData . IncludePathWildcards . Num ( ) & & Target - > Settings . GatherFromMetaData . KeySpecifications . Num ( ) ) // Don't gather from metadata if there are none specified.
2015-03-06 18:22:14 -05:00
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GatherTextFromMetadata " ) ) ;
// Include Paths
2015-03-09 15:38:32 -04:00
for ( const auto & IncludePath : Target - > Settings . GatherFromMetaData . IncludePathWildcards )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " IncludePaths " ) , IncludePath ) ;
}
// Exclude Paths
2015-03-09 15:38:32 -04:00
for ( const auto & ExcludePath : Target - > Settings . GatherFromMetaData . ExcludePathWildcards )
2015-03-06 18:22:14 -05:00
{
ConfigSection . Add ( TEXT ( " ExcludePaths " ) , ExcludePath ) ;
}
// Package Extensions
2015-03-09 15:38:32 -04:00
for ( const FMetaDataKeyGatherSpecification & Specification : Target - > Settings . GatherFromMetaData . KeySpecifications )
2015-03-06 18:22:14 -05:00
{
2015-03-06 18:23:24 -05:00
ConfigSection . Add ( TEXT ( " InputKeys " ) , Specification . MetaDataKey ) ;
2015-03-06 18:22:14 -05:00
ConfigSection . Add ( TEXT ( " OutputNamespaces " ) , Specification . TextNamespace ) ;
ConfigSection . Add ( TEXT ( " OutputKeys " ) , FString : : Printf ( TEXT ( " \" %s \" " ) , * Specification . TextKeyPattern ) ) ;
}
2015-01-27 16:31:40 -05:00
}
// GenerateGatherManifest
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GenerateGatherManifest " ) ) ;
}
// GenerateGatherArchive
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GenerateGatherArchive " ) ) ;
}
2015-03-18 19:14:43 -04:00
// GenerateTextLocalizationReport
{
FConfigSection & ConfigSection = Script . GatherTextStep ( GatherTextStepIndex + + ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GenerateTextLocalizationReport " ) ) ;
const FString SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
const FString DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
ConfigSection . Add ( TEXT ( " ManifestName " ) , FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " manifest " ) ) ) ;
for ( const FCultureStatistics & CultureStatistics : Target - > Settings . SupportedCulturesStatistics )
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureStatistics . CultureName ) ;
}
ConfigSection . Add ( TEXT ( " bWordCountReport " ) , TEXT ( " true " ) ) ;
ConfigSection . Add ( TEXT ( " WordCountReportName " ) , FPaths : : GetCleanFilename ( GetWordCountCSVPath ( Target ) ) ) ;
ConfigSection . Add ( TEXT ( " bConflictReport " ) , TEXT ( " true " ) ) ;
ConfigSection . Add ( TEXT ( " ConflictReportName " ) , FPaths : : GetCleanFilename ( GetConflictReportPath ( Target ) ) ) ;
}
2015-01-27 16:31:40 -05:00
Script . Dirty = true ;
return Script ;
}
2015-03-09 15:38:32 -04:00
FString GetGatherScriptPath ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
return GetScriptDirectory ( Target ) / FString : : Printf ( TEXT ( " %s_Gather.%s " ) , * ( Target - > Settings . Name ) , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FLocalizationConfigurationScript GenerateImportScript ( const ULocalizationTarget * const Target , const TOptional < FString > CultureName , const TOptional < FString > OutputPathOverride )
2015-01-27 16:31:40 -05:00
{
FLocalizationConfigurationScript Script ;
2015-03-12 19:41:56 -04:00
const FString ContentDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetContentDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-27 16:31:40 -05:00
// GatherTextStep0 - InternationalizationExport
{
FConfigSection & ConfigSection = Script . GatherTextStep ( 0 ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " InternationalizationExport " ) ) ;
ConfigSection . Add ( TEXT ( " bImportLoc " ) , TEXT ( " true " ) ) ;
2015-01-30 16:29:01 -05:00
FString SourcePath ;
// Overriding output path changes the source directory for the PO file.
if ( OutputPathOverride . IsSet ( ) )
{
// The output path for a specific culture is a file path.
if ( CultureName . IsSet ( ) )
{
2015-03-12 19:41:56 -04:00
SourcePath = MakePathRelativeForCommandletProcess ( FPaths : : GetPath ( OutputPathOverride . GetValue ( ) ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-30 16:29:01 -05:00
}
// Otherwise, it is a directory path.
else
{
2015-03-12 19:41:56 -04:00
SourcePath = MakePathRelativeForCommandletProcess ( OutputPathOverride . GetValue ( ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-30 16:29:01 -05:00
}
}
// Use the default PO file's directory path.
else
{
2015-03-09 15:38:32 -04:00
SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-30 16:29:01 -05:00
}
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
2015-01-30 16:29:01 -05:00
2015-03-09 15:38:32 -04:00
const FString DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
const auto & AddCultureToGenerate = [ & ] ( const int32 Index )
{
2015-03-09 15:38:32 -04:00
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , Target - > Settings . SupportedCulturesStatistics [ Index ] . CultureName ) ;
2015-01-27 16:31:40 -05:00
} ;
// Export for a specific culture.
2015-01-30 16:29:01 -05:00
if ( CultureName . IsSet ( ) )
2015-01-27 16:31:40 -05:00
{
2015-01-30 16:29:01 -05:00
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureName . GetValue ( ) ) ;
2015-01-27 16:31:40 -05:00
}
// Export for all cultures.
else
{
2015-03-09 15:38:32 -04:00
for ( const FCultureStatistics & CultureStatistics : Target - > Settings . SupportedCulturesStatistics )
2015-01-27 16:31:40 -05:00
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureStatistics . CultureName ) ;
}
}
2015-01-30 16:29:01 -05:00
// Do not use culture subdirectories if importing a single culture to a specific directory.
if ( CultureName . IsSet ( ) & & OutputPathOverride . IsSet ( ) )
{
ConfigSection . Add ( TEXT ( " bUseCultureDirectory " ) , " false " ) ;
}
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " ManifestName " ) , FPaths : : GetCleanFilename ( GetManifestPath ( Target ) ) ) ;
ConfigSection . Add ( TEXT ( " ArchiveName " ) , FPaths : : GetCleanFilename ( GetArchivePath ( Target , FString ( ) ) ) ) ;
2015-01-30 16:29:01 -05:00
FString POFileName ;
// The output path for a specific culture is a file path.
if ( CultureName . IsSet ( ) & & OutputPathOverride . IsSet ( ) )
{
POFileName = FPaths : : GetCleanFilename ( OutputPathOverride . GetValue ( ) ) ;
}
// Use the default PO file's name.
else
{
POFileName = FPaths : : GetCleanFilename ( GetDefaultPOFileName ( Target ) ) ;
}
ConfigSection . Add ( TEXT ( " PortableObjectName " ) , POFileName ) ;
2015-01-27 16:31:40 -05:00
}
Script . Dirty = true ;
return Script ;
}
2015-03-09 15:38:32 -04:00
FString GetImportScriptPath ( const ULocalizationTarget * const Target , const TOptional < FString > CultureName )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
const FString ConfigFileDirectory = GetScriptDirectory ( Target ) ;
2015-01-27 16:31:40 -05:00
FString ConfigFilePath ;
2015-01-30 16:29:01 -05:00
if ( CultureName . IsSet ( ) )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
ConfigFilePath = ConfigFileDirectory / FString : : Printf ( TEXT ( " %s_Import_%s.%s " ) , * Target - > Settings . Name , * CultureName . GetValue ( ) , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
else
{
2015-03-09 15:38:32 -04:00
ConfigFilePath = ConfigFileDirectory / FString : : Printf ( TEXT ( " %s_Import.%s " ) , * Target - > Settings . Name , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
return ConfigFilePath ;
}
2015-03-09 15:38:32 -04:00
FLocalizationConfigurationScript GenerateExportScript ( const ULocalizationTarget * const Target , const TOptional < FString > CultureName , const TOptional < FString > OutputPathOverride )
2015-01-27 16:31:40 -05:00
{
FLocalizationConfigurationScript Script ;
2015-03-12 19:41:56 -04:00
const FString ContentDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetContentDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-27 16:31:40 -05:00
// GatherTextStep0 - InternationalizationExport
{
FConfigSection & ConfigSection = Script . GatherTextStep ( 0 ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " InternationalizationExport " ) ) ;
ConfigSection . Add ( TEXT ( " bExportLoc " ) , TEXT ( " true " ) ) ;
2015-03-09 15:38:32 -04:00
const FString SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
2015-01-30 16:29:01 -05:00
FString DestinationPath ;
// Overriding output path changes the destination directory for the PO file.
if ( OutputPathOverride . IsSet ( ) )
{
// The output path for a specific culture is a file path.
if ( CultureName . IsSet ( ) )
{
2015-03-12 19:41:56 -04:00
DestinationPath = MakePathRelativeForCommandletProcess ( FPaths : : GetPath ( OutputPathOverride . GetValue ( ) ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-30 16:29:01 -05:00
}
// Otherwise, it is a directory path.
else
{
2015-03-12 19:41:56 -04:00
DestinationPath = MakePathRelativeForCommandletProcess ( OutputPathOverride . GetValue ( ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-30 16:29:01 -05:00
}
}
// Use the default PO file's directory path.
else
{
2015-03-09 15:38:32 -04:00
DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-30 16:29:01 -05:00
}
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
TArray < const FCultureStatistics * > AllCultureStatistics ;
2015-03-09 15:38:32 -04:00
AllCultureStatistics . Add ( & Target - > Settings . NativeCultureStatistics ) ;
for ( const FCultureStatistics & SupportedCultureStatistics : Target - > Settings . SupportedCulturesStatistics )
2015-01-27 16:31:40 -05:00
{
AllCultureStatistics . Add ( & SupportedCultureStatistics ) ;
}
const auto & AddCultureToGenerate = [ & ] ( const int32 Index )
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , AllCultureStatistics [ Index ] - > CultureName ) ;
} ;
// Export for a specific culture.
2015-01-30 16:29:01 -05:00
if ( CultureName . IsSet ( ) )
2015-01-27 16:31:40 -05:00
{
2015-01-30 16:29:01 -05:00
const int32 CultureIndex = AllCultureStatistics . IndexOfByPredicate ( [ CultureName ] ( const FCultureStatistics * Culture ) { return Culture - > CultureName = = CultureName . GetValue ( ) ; } ) ;
2015-01-27 16:31:40 -05:00
AddCultureToGenerate ( CultureIndex ) ;
}
// Export for all cultures.
else
{
for ( int32 CultureIndex = 0 ; CultureIndex < AllCultureStatistics . Num ( ) ; + + CultureIndex )
{
AddCultureToGenerate ( CultureIndex ) ;
}
}
2015-01-30 16:29:01 -05:00
// Do not use culture subdirectories if exporting a single culture to a specific directory.
if ( CultureName . IsSet ( ) & & OutputPathOverride . IsSet ( ) )
{
ConfigSection . Add ( TEXT ( " bUseCultureDirectory " ) , " false " ) ;
}
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " ManifestName " ) , FPaths : : GetCleanFilename ( GetManifestPath ( Target ) ) ) ;
ConfigSection . Add ( TEXT ( " ArchiveName " ) , FPaths : : GetCleanFilename ( GetArchivePath ( Target , FString ( ) ) ) ) ;
2015-01-30 16:29:01 -05:00
FString POFileName ;
// The output path for a specific culture is a file path.
if ( CultureName . IsSet ( ) & & OutputPathOverride . IsSet ( ) )
{
POFileName = FPaths : : GetCleanFilename ( OutputPathOverride . GetValue ( ) ) ;
}
// Use the default PO file's name.
else
{
POFileName = FPaths : : GetCleanFilename ( GetDefaultPOPath ( Target , CultureName . Get ( TEXT ( " " ) ) ) ) ;
}
ConfigSection . Add ( TEXT ( " PortableObjectName " ) , POFileName ) ;
2015-01-27 16:31:40 -05:00
}
Script . Dirty = true ;
return Script ;
}
2015-03-09 15:38:32 -04:00
FString GetExportScriptPath ( const ULocalizationTarget * const Target , const TOptional < FString > CultureName )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
const FString ConfigFileDirectory = GetScriptDirectory ( Target ) ;
2015-01-27 16:31:40 -05:00
FString ConfigFilePath ;
2015-01-30 16:29:01 -05:00
if ( CultureName . IsSet ( ) )
2015-01-27 16:31:40 -05:00
{
2015-03-09 15:38:32 -04:00
ConfigFilePath = ConfigFileDirectory / FString : : Printf ( TEXT ( " %s_Export_%s.%s " ) , * Target - > Settings . Name , * CultureName . GetValue ( ) , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
else
{
2015-03-09 15:38:32 -04:00
ConfigFilePath = ConfigFileDirectory / FString : : Printf ( TEXT ( " %s_Export.%s " ) , * Target - > Settings . Name , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
return ConfigFilePath ;
}
2015-03-18 19:14:43 -04:00
FLocalizationConfigurationScript GenerateWordCountReportScript ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
FLocalizationConfigurationScript Script ;
2015-03-12 19:41:56 -04:00
const FString ContentDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetContentDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-27 16:31:40 -05:00
// GatherTextStep0 - GenerateTextLocalizationReport
{
FConfigSection & ConfigSection = Script . GatherTextStep ( 0 ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GenerateTextLocalizationReport " ) ) ;
2015-03-09 15:38:32 -04:00
const FString SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
2015-03-09 15:38:32 -04:00
const FString DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-27 16:31:40 -05:00
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
2015-03-09 15:38:32 -04:00
ConfigSection . Add ( TEXT ( " ManifestName " ) , FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " manifest " ) ) ) ;
2015-01-27 16:31:40 -05:00
2015-03-09 15:38:32 -04:00
for ( const FCultureStatistics & CultureStatistics : Target - > Settings . SupportedCulturesStatistics )
2015-01-27 16:31:40 -05:00
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureStatistics . CultureName ) ;
}
ConfigSection . Add ( TEXT ( " bWordCountReport " ) , TEXT ( " true " ) ) ;
ConfigSection . Add ( TEXT ( " WordCountReportName " ) , FPaths : : GetCleanFilename ( GetWordCountCSVPath ( Target ) ) ) ;
}
Script . Dirty = true ;
return Script ;
}
2015-03-18 19:14:43 -04:00
FString GetWordCountReportScriptPath ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
return GetScriptDirectory ( Target ) / FString : : Printf ( TEXT ( " %s_GenerateReports.%s " ) , * ( Target - > Settings . Name ) , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FLocalizationConfigurationScript GenerateCompileScript ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-01-30 17:29:25 -05:00
FLocalizationConfigurationScript Script ;
2015-03-12 19:41:56 -04:00
const FString ContentDirRelativeToGameDir = MakePathRelativeForCommandletProcess ( GetContentDir ( Target ) , ! Target - > IsMemberOfEngineTargetSet ( ) ) ;
2015-01-30 17:29:25 -05:00
// GatherTextStep0 - GenerateTextLocalizationResource
{
FConfigSection & ConfigSection = Script . GatherTextStep ( 0 ) ;
// CommandletClass
ConfigSection . Add ( TEXT ( " CommandletClass " ) , TEXT ( " GenerateTextLocalizationResource " ) ) ;
2015-03-09 15:38:32 -04:00
const FString SourcePath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-30 17:29:25 -05:00
ConfigSection . Add ( TEXT ( " SourcePath " ) , SourcePath ) ;
2015-03-09 15:38:32 -04:00
const FString DestinationPath = ContentDirRelativeToGameDir / TEXT ( " Localization " ) / Target - > Settings . Name ;
2015-01-30 17:29:25 -05:00
ConfigSection . Add ( TEXT ( " DestinationPath " ) , DestinationPath ) ;
2015-03-09 15:38:32 -04:00
ConfigSection . Add ( TEXT ( " ManifestName " ) , FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " manifest " ) ) ) ;
ConfigSection . Add ( TEXT ( " ResourceName " ) , FString : : Printf ( TEXT ( " %s.%s " ) , * Target - > Settings . Name , TEXT ( " locres " ) ) ) ;
2015-01-30 17:29:25 -05:00
TArray < const FCultureStatistics * > AllCultureStatistics ;
2015-03-09 15:38:32 -04:00
AllCultureStatistics . Add ( & Target - > Settings . NativeCultureStatistics ) ;
for ( const FCultureStatistics & SupportedCultureStatistics : Target - > Settings . SupportedCulturesStatistics )
2015-01-30 17:29:25 -05:00
{
AllCultureStatistics . Add ( & SupportedCultureStatistics ) ;
}
for ( const FCultureStatistics * CultureStatistics : AllCultureStatistics )
{
ConfigSection . Add ( TEXT ( " CulturesToGenerate " ) , CultureStatistics - > CultureName ) ;
}
}
Script . Dirty = true ;
return Script ;
2015-01-27 16:31:40 -05:00
}
2015-03-09 15:38:32 -04:00
FString GetCompileScriptPath ( const ULocalizationTarget * const Target )
2015-01-27 16:31:40 -05:00
{
2015-03-09 18:56:46 -04:00
return GetScriptDirectory ( Target ) / FString : : Printf ( TEXT ( " %s_Compile.%s " ) , * ( Target - > Settings . Name ) , TEXT ( " ini " ) ) ;
2015-01-27 16:31:40 -05:00
}
}