2015-01-27 16:31:40 -05:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "LocalizationDashboardPrivatePCH.h"
# include "LocalizationCommandletTasks.h"
# include "LocalizationCommandletExecution.h"
# include "LocalizationConfigurationScript.h"
2015-01-27 18:24:26 -05:00
# define LOCTEXT_NAMESPACE "LocalizationCommandletTasks"
2015-01-27 16:31:40 -05:00
bool LocalizationCommandletTasks : : GatherTargets ( const TSharedRef < SWindow > & ParentWindow , const TArray < FLocalizationTargetSettings * > & TargetsSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
for ( FLocalizationTargetSettings * TargetSettings : TargetsSettings )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings - > Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText GatherTaskName = FText : : Format ( LOCTEXT ( " GatherTaskNameFormat " , " Gather Text for {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
const FString GatherScriptPath = LocalizationConfigurationScript : : GetGatherScriptPath ( * TargetSettings ) ;
LocalizationConfigurationScript : : GenerateGatherScript ( * TargetSettings ) . Write ( GatherScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( GatherTaskName , GatherScriptPath ) ) ;
2015-01-27 18:24:26 -05:00
const FText ReportTaskName = FText : : Format ( LOCTEXT ( " ReportTaskNameFormat " , " Generate Reports for {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( * TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( * TargetSettings ) . Write ( ReportScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( ReportTaskName , ReportScriptPath ) ) ;
}
2015-01-27 18:24:26 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , LOCTEXT ( " GatherAllTargetsWindowTitle " , " Gather Text for All Targets " ) , Tasks ) ;
2015-01-27 16:31:40 -05:00
}
bool LocalizationCommandletTasks : : GatherTarget ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
const FString GatherScriptPath = LocalizationConfigurationScript : : GetGatherScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateGatherScript ( TargetSettings ) . Write ( GatherScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " GatherTaskName " , " Gather Text " ) , GatherScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( TargetSettings ) . Write ( ReportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ReportTaskName " , " Generate Reports " ) , ReportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " GatherTargetWindowTitle " , " Gather Text for Target {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ImportTargets ( const TSharedRef < SWindow > & ParentWindow , const TArray < FLocalizationTargetSettings * > & TargetsSettings , const TOptional < FString > DirectoryPath )
2015-01-27 16:31:40 -05:00
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
for ( FLocalizationTargetSettings * TargetSettings : TargetsSettings )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings - > Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText ImportTaskName = FText : : Format ( LOCTEXT ( " ImportTaskNameFormat " , " Import Translations for {TargetName} " ) , Arguments ) ;
2015-01-30 16:29:01 -05:00
const FString ImportScriptPath = LocalizationConfigurationScript : : GetImportScriptPath ( * TargetSettings , TOptional < FString > ( ) ) ;
const TOptional < FString > DirectoryPathForTarget = DirectoryPath . IsSet ( ) ? DirectoryPath . GetValue ( ) / TargetSettings - > Name : TOptional < FString > ( ) ;
LocalizationConfigurationScript : : GenerateImportScript ( * TargetSettings , TOptional < FString > ( ) , DirectoryPathForTarget ) . Write ( ImportScriptPath ) ;
2015-01-27 16:31:40 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( ImportTaskName , ImportScriptPath ) ) ;
2015-01-27 18:24:26 -05:00
const FText ReportTaskName = FText : : Format ( LOCTEXT ( " ReportTaskNameFormat " , " Generate Reports for {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( * TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( * TargetSettings ) . Write ( ReportScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( ReportTaskName , ReportScriptPath ) ) ;
}
2015-01-27 18:24:26 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , LOCTEXT ( " ImportForAllTargetsWindowTitle " , " Import Translations for All Targets " ) , Tasks ) ;
2015-01-27 16:31:40 -05:00
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ImportTarget ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings , const TOptional < FString > DirectoryPath )
2015-01-27 16:31:40 -05:00
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
2015-01-30 16:29:01 -05:00
const FString ImportScriptPath = LocalizationConfigurationScript : : GetImportScriptPath ( TargetSettings , TOptional < FString > ( ) ) ;
LocalizationConfigurationScript : : GenerateImportScript ( TargetSettings , TOptional < FString > ( ) , DirectoryPath ) . Write ( ImportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ImportTaskName " , " Import Translations " ) , ImportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( TargetSettings ) . Write ( ReportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ReportTaskName " , " Generate Reports " ) , ReportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " ImportForTargetWindowTitle " , " Import Translations for Target {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ImportCulture ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings , const FString & CultureName , const TOptional < FString > FilePath )
2015-01-27 16:31:40 -05:00
{
FCulturePtr Culture = FInternationalization : : Get ( ) . GetCulture ( CultureName ) ;
if ( ! Culture . IsValid ( ) )
{
return false ;
}
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
2015-01-30 16:29:01 -05:00
const FString DefaultImportScriptPath = LocalizationConfigurationScript : : GetImportScriptPath ( TargetSettings , TOptional < FString > ( CultureName ) ) ;
const FString ImportScriptPath = FPaths : : CreateTempFilename ( * FPaths : : GetPath ( DefaultImportScriptPath ) , * FPaths : : GetBaseFilename ( DefaultImportScriptPath ) , * FPaths : : GetExtension ( DefaultImportScriptPath , true ) ) ;
LocalizationConfigurationScript : : GenerateImportScript ( TargetSettings , TOptional < FString > ( CultureName ) , FilePath ) . Write ( ImportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ImportTaskName " , " Import Translations " ) , ImportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( TargetSettings ) . Write ( ReportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ReportTaskName " , " Generate Reports " ) , ReportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " CultureName " ) , FText : : FromString ( Culture - > GetDisplayName ( ) ) ) ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " ImportCultureForTargetWindowTitle " , " Import {CultureName} Translations for Target {TargetName} " ) , Arguments ) ;
2015-01-30 16:29:01 -05:00
bool HasSucceeeded = LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
IFileManager : : Get ( ) . Delete ( * ImportScriptPath ) ; // Don't clutter up the loc config directory with scripts for individual cultures.
return HasSucceeeded ;
2015-01-27 16:31:40 -05:00
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ExportTargets ( const TSharedRef < SWindow > & ParentWindow , const TArray < FLocalizationTargetSettings * > & TargetsSettings , const TOptional < FString > DirectoryPath )
2015-01-27 16:31:40 -05:00
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
for ( FLocalizationTargetSettings * TargetSettings : TargetsSettings )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings - > Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText ExportTaskName = FText : : Format ( LOCTEXT ( " ExportTaskNameFormat " , " Export Translations for {TargetName} " ) , Arguments ) ;
2015-01-30 16:29:01 -05:00
const FString ExportScriptPath = LocalizationConfigurationScript : : GetExportScriptPath ( * TargetSettings , TOptional < FString > ( ) ) ;
const TOptional < FString > DirectoryPathForTarget = DirectoryPath . IsSet ( ) ? DirectoryPath . GetValue ( ) / TargetSettings - > Name : TOptional < FString > ( ) ;
LocalizationConfigurationScript : : GenerateExportScript ( * TargetSettings , TOptional < FString > ( ) , DirectoryPathForTarget ) . Write ( ExportScriptPath ) ;
2015-01-27 16:31:40 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( ExportTaskName , ExportScriptPath ) ) ;
}
2015-01-27 18:24:26 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , LOCTEXT ( " ExportForAllTargetsWindowTitle " , " Export Translations for All Targets " ) , Tasks ) ;
2015-01-27 16:31:40 -05:00
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ExportTarget ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings , const TOptional < FString > DirectoryPath )
2015-01-27 16:31:40 -05:00
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
2015-01-30 16:29:01 -05:00
const FString ExportScriptPath = LocalizationConfigurationScript : : GetExportScriptPath ( TargetSettings , TOptional < FString > ( ) ) ;
LocalizationConfigurationScript : : GenerateExportScript ( TargetSettings , TOptional < FString > ( ) , DirectoryPath ) . Write ( ExportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ExportTaskName " , " Export Translations " ) , ExportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " ExportForTargetWindowTitle " , " Export Translations for Target {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
}
2015-01-30 16:29:01 -05:00
bool LocalizationCommandletTasks : : ExportCulture ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings , const FString & CultureName , const TOptional < FString > FilePath )
2015-01-27 16:31:40 -05:00
{
FCulturePtr Culture = FInternationalization : : Get ( ) . GetCulture ( CultureName ) ;
if ( ! Culture . IsValid ( ) )
{
return false ;
}
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
2015-01-30 16:29:01 -05:00
const FString DefaultExportScriptPath = LocalizationConfigurationScript : : GetExportScriptPath ( TargetSettings , TOptional < FString > ( CultureName ) ) ;
const FString ExportScriptPath = FPaths : : CreateTempFilename ( * FPaths : : GetPath ( DefaultExportScriptPath ) , * FPaths : : GetBaseFilename ( DefaultExportScriptPath ) , * FPaths : : GetExtension ( DefaultExportScriptPath , true ) ) ;
LocalizationConfigurationScript : : GenerateExportScript ( TargetSettings , TOptional < FString > ( CultureName ) , FilePath ) . Write ( ExportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ExportTaskName " , " Export Translations " ) , ExportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " CultureName " ) , FText : : FromString ( Culture - > GetDisplayName ( ) ) ) ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " ExportCultureForTargetWindowTitle " , " Export {CultureName} Translations for Target {TargetName} " ) , Arguments ) ;
2015-01-30 16:29:01 -05:00
bool HasSucceeeded = LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
IFileManager : : Get ( ) . Delete ( * ExportScriptPath ) ; // Don't clutter up the loc config directory with scripts for individual cultures.
return HasSucceeeded ;
2015-01-27 16:31:40 -05:00
}
bool LocalizationCommandletTasks : : GenerateReportsForTargets ( const TSharedRef < SWindow > & ParentWindow , const TArray < FLocalizationTargetSettings * > & TargetsSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
for ( FLocalizationTargetSettings * TargetSettings : TargetsSettings )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings - > Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText ReportTaskName = FText : : Format ( LOCTEXT ( " ReportTaskNameFormat " , " Generate Reports for {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( * TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( * TargetSettings ) . Write ( ReportScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( ReportTaskName , ReportScriptPath ) ) ;
}
2015-01-27 18:24:26 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , LOCTEXT ( " GenerateReportsForAllTargetsWindowTitle " , " Generate Reports for All Targets " ) , Tasks ) ;
2015-01-27 16:31:40 -05:00
}
bool LocalizationCommandletTasks : : GenerateReportsForTarget ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
const FString ReportScriptPath = LocalizationConfigurationScript : : GetReportScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateReportScript ( TargetSettings ) . Write ( ReportScriptPath ) ;
2015-01-27 18:24:26 -05:00
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " ReportTaskName " , " Generate Reports " ) , ReportScriptPath ) ) ;
2015-01-27 16:31:40 -05:00
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
2015-01-27 18:24:26 -05:00
const FText WindowTitle = FText : : Format ( LOCTEXT ( " GenerateReportsForTargetWindowTitle " , " Generate Reports for Target {TargetName} " ) , Arguments ) ;
2015-01-27 16:31:40 -05:00
return LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
2015-01-27 18:24:26 -05:00
}
2015-01-30 17:29:25 -05:00
bool LocalizationCommandletTasks : : CompileTargets ( const TSharedRef < SWindow > & ParentWindow , const TArray < FLocalizationTargetSettings * > & TargetsSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
for ( FLocalizationTargetSettings * TargetSettings : TargetsSettings )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings - > Name ) ) ;
const FText CompileTaskName = FText : : Format ( LOCTEXT ( " CompileTaskNameFormat " , " Compile Translations for {TargetName} " ) , Arguments ) ;
const FString CompileScriptPath = LocalizationConfigurationScript : : GetCompileScriptPath ( * TargetSettings ) ;
LocalizationConfigurationScript : : GenerateCompileScript ( * TargetSettings ) . Write ( CompileScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( CompileTaskName , CompileScriptPath ) ) ;
}
return LocalizationCommandletExecution : : Execute ( ParentWindow , LOCTEXT ( " GenerateLocResForAllTargetsWindowTitle " , " Compile Translations for All Targets " ) , Tasks ) ;
}
bool LocalizationCommandletTasks : : CompileTarget ( const TSharedRef < SWindow > & ParentWindow , FLocalizationTargetSettings & TargetSettings )
{
TArray < LocalizationCommandletExecution : : FTask > Tasks ;
const FString CompileScriptPath = LocalizationConfigurationScript : : GetCompileScriptPath ( TargetSettings ) ;
LocalizationConfigurationScript : : GenerateCompileScript ( TargetSettings ) . Write ( CompileScriptPath ) ;
Tasks . Add ( LocalizationCommandletExecution : : FTask ( LOCTEXT ( " CompileTaskName " , " Compile Translations " ) , CompileScriptPath ) ) ;
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " TargetName " ) , FText : : FromString ( TargetSettings . Name ) ) ;
const FText WindowTitle = FText : : Format ( LOCTEXT ( " GenerateLocResForTargetWindowTitle " , " Compile Translations for Target {TargetName} " ) , Arguments ) ;
return LocalizationCommandletExecution : : Execute ( ParentWindow , WindowTitle , Tasks ) ;
}
2015-01-27 18:24:26 -05:00
# undef LOCTEXT_NAMESPACE