本文整理汇总了C++中TSharedRef::GetEntriesByContextIdIterator方法的典型用法代码示例。如果您正苦于以下问题:C++ TSharedRef::GetEntriesByContextIdIterator方法的具体用法?C++ TSharedRef::GetEntriesByContextIdIterator怎么用?C++ TSharedRef::GetEntriesByContextIdIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSharedRef
的用法示例。
在下文中一共展示了TSharedRef::GetEntriesByContextIdIterator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildArchiveFromManifest
void UGenerateGatherArchiveCommandlet::BuildArchiveFromManifest( TSharedRef< const FInternationalizationManifest > InManifest, TSharedRef< FInternationalizationArchive > Archive, const FString& SourceCulture, const FString& TargetCulture )
{
for(TManifestEntryByContextIdContainer::TConstIterator It( InManifest->GetEntriesByContextIdIterator() ); It; ++It)
{
const TSharedRef<FManifestEntry> UnstructuredManifestEntry = It.Value();
const FString& Namespace = UnstructuredManifestEntry->Namespace;
const FLocItem& Source = UnstructuredManifestEntry->Source;
for( auto ContextIter = UnstructuredManifestEntry->Contexts.CreateConstIterator(); ContextIter; ++ContextIter )
{
const FContext& Context = *ContextIter;
// We only add the non-optional entries
if( !Context.bIsOptional )
{
FLocItem Translation = Source;
if( SourceCulture != TargetCulture)
{
// We want to process the translation before adding it to the archive
ConditionTranslation( Translation );
}
// We also condition the source object
FLocItem ConditionedSource = Source;
ConditionSource( ConditionedSource );
Archive->AddEntry(Namespace, ConditionedSource, Translation, Context.KeyMetadataObj, Context.bIsOptional );
}
}
}
}
示例2: GenerateStructuredData
void FInternationalizationManifestJsonSerializer::GenerateStructuredData( TSharedRef< const FInternationalizationManifest > InManifest, TSharedPtr< FStructuredEntry > RootElement )
{
//Loop through all the unstructured manifest entries and build up our structured hierarchy
for( TManifestEntryByContextIdContainer::TConstIterator It( InManifest->GetEntriesByContextIdIterator() ); It; ++It )
{
const TSharedRef< FManifestEntry > UnstructuredManifestEntry = It.Value();
TArray< FString > NamespaceTokens;
// Tokenize the namespace by using '.' as a delimiter
int32 NamespaceTokenCount = UnstructuredManifestEntry->Namespace.ParseIntoArray( &NamespaceTokens, *NAMESPACE_DELIMITER, true );
TSharedPtr< FStructuredEntry > StructuredManifestEntry = RootElement;
//Loop through all the namespace tokens and find the appropriate structured entry, if it does not exist add it. At the end StructuredManifestEntry
// will point to the correct hierarchy entry for a given namespace
for( int32 TokenIndex = 0; TokenIndex < NamespaceTokenCount; ++TokenIndex )
{
TSharedPtr< FStructuredEntry > FoundNamespaceEntry;
for( int SubNamespaceIndex = 0; SubNamespaceIndex < StructuredManifestEntry->SubNamespaces.Num(); SubNamespaceIndex++ )
{
if( StructuredManifestEntry->SubNamespaces[SubNamespaceIndex]->Namespace == NamespaceTokens[TokenIndex] )
{
FoundNamespaceEntry = StructuredManifestEntry->SubNamespaces[SubNamespaceIndex];
break;
}
}
if( !FoundNamespaceEntry.IsValid() )
{
int32 index = StructuredManifestEntry->SubNamespaces.Add( MakeShareable( new FStructuredEntry( NamespaceTokens[TokenIndex] ) ) );
FoundNamespaceEntry = StructuredManifestEntry->SubNamespaces[index];
}
StructuredManifestEntry = FoundNamespaceEntry;
}
// We add the unstructured manifest entry to the hierarchy
StructuredManifestEntry->ManifestEntries.AddUnique( UnstructuredManifestEntry );
}
}
示例3: Generate
bool FTextLocalizationResourceGenerator::Generate(const FString& SourcePath, const TSharedRef<FInternationalizationManifest>& InternationalizationManifest, const FString& NativeCulture, const FString& CultureToGenerate, FArchive* const DestinationArchive, IInternationalizationArchiveSerializer& ArchiveSerializer)
{
FLocalizationEntryTracker LocalizationEntryTracker;
// Find archives in the native culture-specific folder.
const FString NativeCulturePath = SourcePath / *(NativeCulture);
TArray<FString> NativeArchiveFileNames;
IFileManager::Get().FindFiles(NativeArchiveFileNames, *(NativeCulturePath / TEXT("*.archive")), true, false);
// Find archives in the culture-specific folder.
const FString CulturePath = SourcePath / *(CultureToGenerate);
TArray<FString> ArchiveFileNames;
IFileManager::Get().FindFiles(ArchiveFileNames, *(CulturePath / TEXT("*.archive")), true, false);
if(NativeArchiveFileNames.Num() == 0)
{
FString Message = FString::Printf(TEXT("No archives were found for native culture %s."), *(CultureToGenerate));
UE_LOG(LogTextLocalizationResourceGenerator, Warning, TEXT("%s"), *Message);
}
if(ArchiveFileNames.Num() == 0)
{
FString Message = FString::Printf(TEXT("No archives were found for culture %s."), *(CultureToGenerate));
UE_LOG(LogTextLocalizationResourceGenerator, Warning, TEXT("%s"), *Message);
}
TArray< TSharedPtr<FInternationalizationArchive> > NativeArchives;
for (const FString& NativeArchiveFileName : NativeArchiveFileNames)
{
// Read each archive file from the culture-named directory in the source path.
FString ArchiveFilePath = NativeCulturePath / NativeArchiveFileName;
ArchiveFilePath = FPaths::ConvertRelativePathToFull(ArchiveFilePath);
TSharedRef<FInternationalizationArchive> InternationalizationArchive = MakeShareable(new FInternationalizationArchive);
#if 0 // @todo Json: Serializing from FArchive is currently broken
FArchive* ArchiveFile = IFileManager::Get().CreateFileReader(*ArchiveFilePath);
if (ArchiveFile == nullptr)
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("No archive found at %s."), *ArchiveFilePath);
continue;
}
ArchiveSerializer.DeserializeArchive(*ArchiveFile, InternationalizationArchive);
#else
FString ArchiveContent;
if (!FFileHelper::LoadFileToString(ArchiveContent, *ArchiveFilePath))
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("Failed to load file %s."), *ArchiveFilePath);
continue;
}
if (!ArchiveSerializer.DeserializeArchive(ArchiveContent, InternationalizationArchive))
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("Failed to serialize archive from file %s."), *ArchiveFilePath);
continue;
}
#endif
NativeArchives.Add(InternationalizationArchive);
}
// For each archive:
for (const FString& ArchiveFileName : ArchiveFileNames)
{
// Read each archive file from the culture-named directory in the source path.
FString ArchiveFilePath = CulturePath / ArchiveFileName;
ArchiveFilePath = FPaths::ConvertRelativePathToFull(ArchiveFilePath);
TSharedRef<FInternationalizationArchive> InternationalizationArchive = MakeShareable(new FInternationalizationArchive);
#if 0 // @todo Json: Serializing from FArchive is currently broken
FArchive* ArchiveFile = IFileManager::Get().CreateFileReader(*ArchiveFilePath);
if (ArchiveFile == nullptr)
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("No archive found at %s."), *ArchiveFilePath);
continue;
}
ArchiveSerializer.DeserializeArchive(*ArchiveFile, InternationalizationArchive);
#else
FString ArchiveContent;
if (!FFileHelper::LoadFileToString(ArchiveContent, *ArchiveFilePath))
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("Failed to load file %s."), *ArchiveFilePath);
continue;
}
if (!ArchiveSerializer.DeserializeArchive(ArchiveContent, InternationalizationArchive))
{
UE_LOG(LogTextLocalizationResourceGenerator, Error, TEXT("Failed to serialize archive from file %s."), *ArchiveFilePath);
continue;
}
#endif
// Generate text localization resource from manifest and archive entries.
for(TManifestEntryByContextIdContainer::TConstIterator i = InternationalizationManifest->GetEntriesByContextIdIterator(); i; ++i)
{
// Gather relevant info from manifest entry.
//.........这里部分代码省略.........
示例4: 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;
}