本文整理汇总了C++中TSharedRef::FindEntryBySource方法的典型用法代码示例。如果您正苦于以下问题:C++ TSharedRef::FindEntryBySource方法的具体用法?C++ TSharedRef::FindEntryBySource怎么用?C++ TSharedRef::FindEntryBySource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSharedRef
的用法示例。
在下文中一共展示了TSharedRef::FindEntryBySource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Generate
//.........这里部分代码省略.........
// Generate text localization resource from manifest and archive entries.
for(TManifestEntryByContextIdContainer::TConstIterator i = InternationalizationManifest->GetEntriesByContextIdIterator(); i; ++i)
{
// Gather relevant info from manifest entry.
const TSharedRef<FManifestEntry>& ManifestEntry = i.Value();
const FString& Namespace = ManifestEntry->Namespace;
const FLocItem& Source = ManifestEntry->Source;
const FString& SourceString = Source.Text;
const FString UnescapedSourceString = SourceString;
const uint32 SourceStringHash = FCrc::StrCrc32(*UnescapedSourceString);
FLocalizationEntryTracker::FKeyTable& KeyTable = LocalizationEntryTracker.Namespaces.FindOrAdd(*Namespace);
// Keeps track of the key strings of non-optional manifest entries that are missing a corresponding archive entry.
FString MissingArchiveEntryKeyStrings;
// Keeps track of the key strings of non-optional manifest entries that are missing a translation
FString MissingArchiveTranslationKeyStrings;
// Create a localization entry for each namespace and key combination.
for(auto ContextIt = ManifestEntry->Contexts.CreateConstIterator(); ContextIt; ++ContextIt)
{
const FString& Key = ContextIt->Key;
// Get proper source string to use - if the native source is different than the native translation, the native translation becomes the source.
FLocItem SourceToUse = Source;
if (CultureToGenerate != NativeCulture)
{
for (const auto& NativeArchive : NativeArchives)
{
if (NativeArchive.IsValid())
{
const TSharedPtr<FArchiveEntry> NativeArchiveEntry = NativeArchive->FindEntryBySource(Namespace, Source, ContextIt->KeyMetadataObj);
if (NativeArchiveEntry.IsValid() && !NativeArchiveEntry->Source.IsExactMatch(NativeArchiveEntry->Translation))
{
SourceToUse = NativeArchiveEntry->Translation;
break;
}
}
}
}
// Find matching archive entry.
TSharedPtr<FArchiveEntry> ArchiveEntry = InternationalizationArchive->FindEntryBySource(Namespace, SourceToUse, ContextIt->KeyMetadataObj);
if(ContextIt->bIsOptional && (!ArchiveEntry.IsValid() || (ArchiveEntry.IsValid() && ArchiveEntry->Translation.Text.IsEmpty())))
{
// Skip any optional manifest entries that do not have a matching archive entry or if the matching archive entry does not have a translation
continue;
}
FString UnescapedTranslatedString;
if( ArchiveEntry.IsValid() )
{
UnescapedTranslatedString = ArchiveEntry->Translation.Text;
if(UnescapedTranslatedString.IsEmpty())
{
if ( !MissingArchiveTranslationKeyStrings.IsEmpty() )
{
MissingArchiveTranslationKeyStrings += TEXT(", ");
}
MissingArchiveTranslationKeyStrings += Key;
}
}
else
示例2: DoImport
//.........这里部分代码省略.........
if( !FPaths::FileExists(ManifestFileName) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to find manifest %s."), *ManifestFileName);
continue;
}
const FString DestinationCulturePath = DestinationPath / CultureName;
const FString ArchiveFileName = DestinationCulturePath / ArchiveName;
if( !FPaths::FileExists(ArchiveFileName) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to find destination archive %s."), *ArchiveFileName);
continue;
}
TSharedPtr< FJsonObject > ArchiveJsonObject = NULL;
ArchiveJsonObject = ReadJSONTextFile( ArchiveFileName );
FJsonInternationalizationArchiveSerializer ArchiveSerializer;
TSharedRef< FInternationalizationArchive > InternationalizationArchive = MakeShareable( new FInternationalizationArchive );
ArchiveSerializer.DeserializeArchive( ArchiveJsonObject.ToSharedRef(), InternationalizationArchive );
bool bModifiedArchive = false;
{
for( auto EntryIter = PortableObject.GetEntriesIterator(); EntryIter; ++EntryIter )
{
auto POEntry = *EntryIter;
if( POEntry->MsgId.IsEmpty() || POEntry->MsgStr.Num() == 0 || POEntry->MsgStr[0].Trim().IsEmpty() )
{
// We ignore the header entry or entries with no translation.
continue;
}
// Some warning messages for data we don't process at the moment
if( !POEntry->MsgIdPlural.IsEmpty() || POEntry->MsgStr.Num() > 1 )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Portable Object entry has plural form we did not process. File: %s MsgCtxt: %s MsgId: %s"), *POFilePath, *POEntry->MsgCtxt, *POEntry->MsgId );
}
FString Key;
FString Namespace;
ParsePOMsgCtxtForIdentity(POEntry->MsgCtxt, Namespace, Key);
const FString& SourceText = ConditionPoStringForArchive(POEntry->MsgId);
const FString& Translation = ConditionPoStringForArchive(POEntry->MsgStr[0]);
TSharedPtr<FLocMetadataObject> KeyMetaDataObject;
// Get key metadata from the manifest, using the namespace and key.
if (!Key.IsEmpty())
{
// Find manifest entry by namespace
for (auto ManifestEntryIterator = InternationalizationManifest->GetEntriesByContextIdIterator(); ManifestEntryIterator; ++ManifestEntryIterator)
{
const FString& ManifestEntryNamespace = ManifestEntryIterator->Key;
const TSharedRef<FManifestEntry>& ManifestEntry = ManifestEntryIterator->Value;
if (ManifestEntry->Namespace == Namespace)
{
FContext* const MatchingContext = ManifestEntry->Contexts.FindByPredicate([&](FContext& Context) -> bool
{
return Context.Key == Key;
});
if (MatchingContext)
{
KeyMetaDataObject = MatchingContext->KeyMetadataObj;
}
}
}
}
//@TODO: Take into account optional entries and entries that differ by keymetadata. Ex. Each optional entry needs a unique msgCtxt
const TSharedPtr< FArchiveEntry > FoundEntry = InternationalizationArchive->FindEntryBySource( Namespace, SourceText, KeyMetaDataObject );
if( !FoundEntry.IsValid() )
{
UE_LOG(LogInternationalizationExportCommandlet, Warning, TEXT("Could not find corresponding archive entry for PO entry. File: %s MsgCtxt: %s MsgId: %s"), *POFilePath, *POEntry->MsgCtxt, *POEntry->MsgId );
continue;
}
if( FoundEntry->Translation != Translation )
{
FoundEntry->Translation = Translation;
bModifiedArchive = true;
}
}
}
if( bModifiedArchive )
{
TSharedRef<FJsonObject> FinalArchiveJsonObj = MakeShareable( new FJsonObject );
ArchiveSerializer.SerializeArchive( InternationalizationArchive, FinalArchiveJsonObj );
if( !WriteJSONToTextFile(FinalArchiveJsonObj, ArchiveFileName, SourceControlInfo ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to write archive to %s."), *ArchiveFileName );
return false;
}
}
}
return true;
}
示例3: DoExport
//.........这里部分代码省略.........
FJsonInternationalizationArchiveSerializer ArchiveSerializer;
TSharedRef< FInternationalizationArchive > InternationalizationArchive = MakeShareable( new FInternationalizationArchive );
ArchiveSerializer.DeserializeArchive( ArchiveJsonObject.ToSharedRef(), InternationalizationArchive );
{
FPortableObjectFormatDOM NewPortableObject;
FString LocLang;
if( !NewPortableObject.SetLanguage( CultureName ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Skipping export of loc language %s because it is not recognized."), *LocLang );
continue;
}
NewPortableObject.SetProjectName( FPaths::GetBaseFilename( ManifestName ) );
NewPortableObject.CreateNewHeader();
{
for(TManifestEntryBySourceTextContainer::TConstIterator ManifestIter = InternationalizationManifest->GetEntriesBySourceTextIterator(); ManifestIter; ++ManifestIter)
{
// Gather relevant info from manifest entry.
const TSharedRef<FManifestEntry>& ManifestEntry = ManifestIter.Value();
const FString& Namespace = ManifestEntry->Namespace;
const FLocItem& Source = ManifestEntry->Source;
// For each context, we may need to create a different or even multiple PO entries.
for( auto ContextIter = ManifestEntry->Contexts.CreateConstIterator(); ContextIter; ++ContextIter )
{
const FContext& Context = *ContextIter;
// Create the typical PO entry from the archive entry which matches the exact same namespace, source, and key metadata, if it exists.
{
const TSharedPtr<FArchiveEntry> ArchiveEntry = InternationalizationArchive->FindEntryBySource( Namespace, Source, Context.KeyMetadataObj );
if( ArchiveEntry.IsValid() )
{
const FString ConditionedArchiveSource = ConditionArchiveStrForPo(ArchiveEntry->Source.Text);
const FString ConditionedArchiveTranslation = ConditionArchiveStrForPo(ArchiveEntry->Translation.Text);
TSharedRef<FPortableObjectEntry> PoEntry = MakeShareable( new FPortableObjectEntry );
//@TODO: We support additional metadata entries that can be translated. How do those fit in the PO file format? Ex: isMature
PoEntry->MsgId = ConditionedArchiveSource;
PoEntry->MsgCtxt = ConditionIdentityForPOMsgCtxt(Namespace, Context.Key, Context.KeyMetadataObj);
PoEntry->MsgStr.Add( ConditionedArchiveTranslation );
const FString PORefString = ConvertSrcLocationToPORef( Context.SourceLocation );
PoEntry->AddReference(PORefString); // Source location.
PoEntry->AddExtractedComment( GetConditionedKeyForExtractedComment(Context.Key) ); // "Notes from Programmer" in the form of the Key.
if (ShouldAddSourceLocationsAsComments)
{
PoEntry->AddExtractedComment(GetConditionedReferenceForExtractedComment(PORefString)); // "Notes from Programmer" in the form of the Source Location, since this comes in handy too and OneSky doesn't properly show references, only comments.
}
TArray<FString> InfoMetaDataStrings;
if (Context.InfoMetadataObj.IsValid())
{
for (auto InfoMetaDataPair : Context.InfoMetadataObj->Values)
{
const FString KeyName = InfoMetaDataPair.Key;
const TSharedPtr<FLocMetadataValue> Value = InfoMetaDataPair.Value;
InfoMetaDataStrings.Add(GetConditionedInfoMetaDataForExtractedComment(KeyName, Value->AsString()));
}
}
if (InfoMetaDataStrings.Num())
示例4: DoImport
//.........这里部分代码省略.........
}
else
{
POFilePath = SourcePath / Filename;
}
if( !FPaths::FileExists(POFilePath) )
{
UE_LOG( LogInternationalizationExportCommandlet, Warning, TEXT("Could not find file %s"), *POFilePath );
continue;
}
FString POFileContents;
if ( !FFileHelper::LoadFileToString( POFileContents, *POFilePath ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to load file %s."), *POFilePath);
continue;
}
FPortableObjectFormatDOM PortableObject;
if( !PortableObject.FromString( POFileContents ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to parse Portable Object file %s."), *POFilePath);
continue;
}
if( PortableObject.GetProjectName() != ManifestName.Replace(TEXT(".manifest"), TEXT("")) )
{
UE_LOG( LogInternationalizationExportCommandlet, Warning, TEXT("The project name (%s) in the file (%s) did not match the target manifest project (%s)."), *POFilePath, *PortableObject.GetProjectName(), *ManifestName.Replace(TEXT(".manifest"), TEXT("")));
}
const FString DestinationCulturePath = DestinationPath / CultureName;
FString ArchiveFileName = DestinationCulturePath / ArchiveName;
if( !FPaths::FileExists(ArchiveFileName) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to find destination archive %s."), *ArchiveFileName);
continue;
}
TSharedPtr< FJsonObject > ArchiveJsonObject = NULL;
ArchiveJsonObject = ReadJSONTextFile( ArchiveFileName );
FJsonInternationalizationArchiveSerializer ArchiveSerializer;
TSharedRef< FInternationalizationArchive > InternationalizationArchive = MakeShareable( new FInternationalizationArchive );
ArchiveSerializer.DeserializeArchive( ArchiveJsonObject.ToSharedRef(), InternationalizationArchive );
bool bModifiedArchive = false;
{
for( auto EntryIter = PortableObject.GetEntriesIterator(); EntryIter; ++EntryIter )
{
auto POEntry = *EntryIter;
if( POEntry->MsgId.IsEmpty() || POEntry->MsgStr.Num() == 0 || POEntry->MsgStr[0].Trim().IsEmpty() )
{
// We ignore the header entry or entries with no translation.
continue;
}
// Some warning messages for data we don't process at the moment
if( !POEntry->MsgIdPlural.IsEmpty() || POEntry->MsgStr.Num() > 1 )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Portable Object entry has plural form we did not process. File: %s MsgCtxt: %s MsgId: %s"), *POFilePath, *POEntry->MsgCtxt, *POEntry->MsgId );
}
const FString& Namespace = POEntry->MsgCtxt;
const FString& SourceText = ConditionPoStringForArchive(POEntry->MsgId);
const FString& Translation = ConditionPoStringForArchive(POEntry->MsgStr[0]);
//@TODO: Take into account optional entries and entries that differ by keymetadata. Ex. Each optional entry needs a unique msgCtxt
TSharedPtr< FArchiveEntry > FoundEntry = InternationalizationArchive->FindEntryBySource( Namespace, SourceText, NULL );
if( !FoundEntry.IsValid() )
{
UE_LOG(LogInternationalizationExportCommandlet, Warning, TEXT("Could not find corresponding archive entry for PO entry. File: %s MsgCtxt: %s MsgId: %s"), *POFilePath, *POEntry->MsgCtxt, *POEntry->MsgId );
continue;
}
if( FoundEntry->Translation != Translation )
{
FoundEntry->Translation = Translation;
bModifiedArchive = true;
}
}
}
if( bModifiedArchive )
{
TSharedRef<FJsonObject> FinalArchiveJsonObj = MakeShareable( new FJsonObject );
ArchiveSerializer.SerializeArchive( InternationalizationArchive, FinalArchiveJsonObj );
if( !WriteJSONToTextFile(FinalArchiveJsonObj, ArchiveFileName, SourceControlInfo ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Failed to write archive to %s."), *ArchiveFileName );
return false;
}
}
}
return true;
}
示例5: DoExport
//.........这里部分代码省略.........
if( FPaths::FileExists(ArchiveFileName) )
{
ArchiveJsonObject = ReadJSONTextFile( ArchiveFileName );
FJsonInternationalizationArchiveSerializer ArchiveSerializer;
TSharedRef< FInternationalizationArchive > InternationalizationArchive = MakeShareable( new FInternationalizationArchive );
ArchiveSerializer.DeserializeArchive( ArchiveJsonObject.ToSharedRef(), InternationalizationArchive );
{
FPortableObjectFormatDOM PortableObj;
FString LocLang;
if( !PortableObj.SetLanguage( CultureName ) )
{
UE_LOG( LogInternationalizationExportCommandlet, Error, TEXT("Skipping export of loc language %s because it is not recognized."), *LocLang );
continue;
}
PortableObj.SetProjectName( FPaths::GetBaseFilename( ManifestName ) );
PortableObj.CreateNewHeader();
{
for(TManifestEntryBySourceTextContainer::TConstIterator ManifestIter = InternationalizationManifest->GetEntriesBySourceTextIterator(); ManifestIter; ++ManifestIter)
{
// Gather relevant info from manifest entry.
const TSharedRef<FManifestEntry>& ManifestEntry = ManifestIter.Value();
const FString& Namespace = ManifestEntry->Namespace;
const FLocItem& Source = ManifestEntry->Source;
for( auto ContextIter = ManifestEntry->Contexts.CreateConstIterator(); ContextIter; ++ContextIter )
{
{
const TSharedPtr<FArchiveEntry> ArchiveEntry = InternationalizationArchive->FindEntryBySource( Namespace, Source, ContextIter->KeyMetadataObj );
if( ArchiveEntry.IsValid() )
{
const FString ConditionedArchiveSource = ConditionArchiveStrForPo(ArchiveEntry->Source.Text);
const FString ConditionedArchiveTranslation = ConditionArchiveStrForPo(ArchiveEntry->Translation.Text);
TSharedRef<FPortableObjectEntry> PoEntry = MakeShareable( new FPortableObjectEntry );
//@TODO: We support additional metadata entries that can be translated. How do those fit in the PO file format? Ex: isMature
PoEntry->MsgId = ConditionedArchiveSource;
//@TODO: Take into account optional entries and entries that differ by keymetadata. Ex. Each optional entry needs a unique msgCtxt
PoEntry->MsgCtxt = Namespace;
PoEntry->MsgStr.Add( ConditionedArchiveTranslation );
FString PORefString = ConvertSrcLocationToPORef( ContextIter->SourceLocation );
PoEntry->AddReference( PORefString ); // Source location.
PoEntry->AddExtractedComment( ContextIter->Key ); // "Notes from Programmer" in the form of the Key.
PoEntry->AddExtractedComment( PORefString ); // "Notes from Programmer" in the form of the Source Location, since this comes in handy too and OneSky doesn't properly show references, only comments.
PortableObj.AddEntry( PoEntry );
}
}
if (CultureName != NativeCultureName)
{
TSharedPtr<FArchiveEntry> NativeArchiveEntry;
for (const auto& NativeArchive : NativeArchives)
{
const TSharedPtr<FArchiveEntry> PotentialNativeArchiveEntry = NativeArchive->FindEntryBySource( Namespace, Source, ContextIter->KeyMetadataObj );
if (PotentialNativeArchiveEntry.IsValid())
{
NativeArchiveEntry = PotentialNativeArchiveEntry;
break;
}
}
示例6: ProcessArchive
bool UInternationalizationConditioningCommandlet::ProcessArchive( const FString& PrimaryLangExt, const FString& SourcePath, const FString& DestinationPath )
{
FString ArchiveName = TEXT("Archive.txt");
TArray<FString> LanguagesToProcess;
TArray<FString> TargetCultures;
bool bAppendToExistingArchive = true;
GetConfigString( *SectionName, TEXT("ArchiveName"), ArchiveName, GatherTextConfigPath );
GetConfigArray( *SectionName, TEXT("ProcessLanguage"), LanguagesToProcess, GatherTextConfigPath );
GetConfigArray( *SectionName, TEXT("TargetCulture"), TargetCultures, GatherTextConfigPath );
GetConfigBool( *SectionName, TEXT("bAppendToExistingArchive"), bAppendToExistingArchive, GatherTextConfigPath );
// Build info about the primary language
TArray<FString> PrimaryFilenames;
TArray<FString> PathPrimaryFilenames;
FString PrimaryLocDirectory = SourcePath / PrimaryLangExt + TEXT("/");
FString PrimaryWildcardName = PrimaryLocDirectory + TEXT("*.") + PrimaryLangExt;
// Grab the list of primary language loc files
IFileManager::Get().FindFiles(PathPrimaryFilenames, *PrimaryWildcardName, true, false);
for ( int32 FileIndex = 0; FileIndex < PathPrimaryFilenames.Num(); FileIndex++ )
{
FString* CompleteFilename = new(PrimaryFilenames) FString(PrimaryLocDirectory + PathPrimaryFilenames[FileIndex]);
}
if ( PrimaryFilenames.Num() == 0 )
{
UE_LOG(LogInternationalizationConditioningCommandlet, Warning, TEXT("No primary language(%s) loc files found!"), *PrimaryLangExt);
return false;
}
for( int32 LanguageIndex = 0; LanguageIndex < LanguagesToProcess.Num(); LanguageIndex++ )
{
FString ForeignLangExt = LanguagesToProcess[LanguageIndex];
TArray<FString> ForeignFilenames;
TArray<FString> PathForeignFilenames;
FString ForeignLocDirectory = SourcePath / ForeignLangExt + TEXT("/");
FString ForeignWildcardName = ForeignLocDirectory + TEXT("*.") + ForeignLangExt;
FString TargetSubfolder = TargetCultures.Num() > LanguageIndex ? TargetCultures[LanguageIndex] : ForeignLangExt;
// Get a list of foreign loc files
IFileManager::Get().FindFiles(PathForeignFilenames, *ForeignWildcardName, true, false);
for ( int32 FileIndex = 0; FileIndex < PathForeignFilenames.Num(); FileIndex++ )
{
FString* CompleteFilename = new(ForeignFilenames) FString(ForeignLocDirectory + PathForeignFilenames[FileIndex]);
}
if ( ForeignFilenames.Num() == 0 )
{
UE_LOG(LogInternationalizationConditioningCommandlet, Warning, TEXT("No foreign loc files found using language extension '%s'"), *ForeignLangExt);
continue;
}
ReadLocFiles(PrimaryFilenames, ForeignFilenames);
TArray<FLocalizationFileEntry> ArchiveProperties;
// FSor each file in the list,
for ( int32 i = 0; i < LocPairs.Num(); i++ )
{
FLocalizationFilePair& Pair = LocPairs[i];
Pair.CompareFiles();
Pair.GetTranslatedProperties( ArchiveProperties );
Pair.GetIdenticalProperties( ArchiveProperties );
}
TSharedRef< FInternationalizationArchive > InternationalizationArchive = MakeShareable( new FInternationalizationArchive );
FInternationalizationArchiveJsonSerializer ArchiveSerializer;
const FString DestinationArchiveFileName = DestinationPath / TargetSubfolder / ArchiveName;
// If we want to append to an existing archive, we first read it into our data structure
if( bAppendToExistingArchive )
{
FString ExistingArchiveFileName = DestinationArchiveFileName;
if( FPaths::FileExists(ExistingArchiveFileName) )
{
TSharedPtr< FJsonObject > ExistingArchiveJsonObject = ReadJSONTextFile( ExistingArchiveFileName );
if( ExistingArchiveJsonObject.IsValid() )
{
ArchiveSerializer.DeserializeArchive( ExistingArchiveJsonObject.ToSharedRef(), InternationalizationArchive );
}
}
}
for( int PropIndex = 0; PropIndex < ArchiveProperties.Num(); PropIndex++ )
{
FLocalizationFileEntry& Prop = ArchiveProperties[PropIndex];
FString NewNamespace = Prop.Namespace;
FLocItem Source( Prop.SourceText );
FLocItem Translation( Prop.TranslatedText );
if( !InternationalizationArchive->AddEntry( NewNamespace, Source, Translation, NULL, false ) )
{
TSharedPtr<FArchiveEntry> ExistingConflictEntry = InternationalizationArchive->FindEntryBySource( NewNamespace, Source, NULL );
//.........这里部分代码省略.........