You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ============================ MAJOR FEATURES & CHANGES ============================ Change 3363699 by Mike.Fricker VR Editor: Improved extensibility (for mesh editor) - This was merged from CL 3352612 and re-opened for edit before commit - All mesh editor changes were stripped before merging Change 3499858 by Matt.Kuhlenschmidt PR #3673: Fixed UE-36416 (Contributed by DarkSlot) Change 3499872 by Matt.Kuhlenschmidt PR #3682: Details view - matrix button visibility toggle and crash fix (Contributed by kamrann) Change 3499873 by Matt.Kuhlenschmidt Hide property matrix button from settings editor. For the combined settings objects view this produces nonsensical results and the property matrix is for bulk editing which settings are not designed for. Change 3501154 by Arciel.Rekman Fix incorrect RPATH. - Fixed LinuxToolChain to use FileItem instead of strings. - Fixed string-based Utils.MakePathRelativeTo - workaround for an old Mono bug was causing invalid "correction" of the relative path, triggered by the fact that path "Foo/Bar/../Baz" was not considered equal to "Foo/Baz". Instead of removing the workaround altogether, added a better comparison. Change 3501337 by Arciel.Rekman Better fix for RPATH. - Ben Marsh's suggestion. Change 3502572 by Matt.Kuhlenschmidt PR #3693: Because "becuase" is spelled because (Contributed by getnamo) Change 3502731 by Matt.Kuhlenschmidt Guard against empty warning toasts #jira UE-46285 Change 3502788 by Matt.Kuhlenschmidt Avoid shutting down the editor during loads and slow tasks if a windows close message comes in during this time Change 3503027 by Michael.Dupuis Optimized UpdateLayerUsageInformation Change 3503299 by Michael.Dupuis Fixed crash when having no layer info object Change 3504529 by Yannick.Lange Use UWorld instead of FWorldContext for EditorWorldExtensions, since we don't use it. Change 3504550 by Jamie.Dale Fixed/Improved DnD validation between Content Browsers Dragging assets between Content Browsers now goes through the same common DnD code (DragDropHandler) as dragging assets between the SPathView and SAssetView, and between items within an SAssetView. This also improves the validation of asset/file drops to prevent you dropping assets/files into class paths. #jira UE-45857 Change 3505369 by Alexis.Matte Make sure undo/redo transactions works for all fbx dialog options. #jira UE-43465 #jira UE-43569 Change 3505500 by Matt.Kuhlenschmidt Fix child usd meshes not importing properly. Change 3505645 by Arciel.Rekman Add USD support on Linux (UE-45383). #jira UE-45383 Change 3505658 by Arciel.Rekman USD: add CMake toolchain file I missed. Change 3506796 by Yannick.Lange Fix EditorWorldExtensionCollection using TWeakObjectPtr for UWorlds instead of UPROPERTY Change 3508082 by Alexis.Matte Make sure the fbx re-import editor preference "show option dialog at reimport" is working when re-importing an animation sequence. Change 3508855 by Max.Chen Add CanFindInContentBrowser to AssetEditorToolkit. False for LevelSequenceEditorToolkit so that sequencer doesn't take over Find In Content Browser and show only the sequencer asset. #jira UE-46241 Change 3509282 by Bradut.Palas #jira UE-45337 Removed check for Actor->GetWorld() against GWorld because the latter would switch between editor world and PIE world during a tick, causing the widget to not update properly. Since the Actor would always point to the PIE world, the check was no longer needed. Change 3509298 by Nick.Darnell Slate - Now has better support for analog navigation, the NavigationConfig is now created per user, and has the ability to deal with repeats and can handle navigation better by waiting until the user has moved enough to intend a direction to move. Change 3509313 by Bradut.Palas #jira UE-44630 As the bug description says, the Undo History was not refreshing correctly because an undo coupled with an action would result in the same number of transactions as the previous tick. Now we also check the variation of undo actions count in order to refresh the list. Change 3509318 by Bradut.Palas #jira UE-1406 To fix the issue we simply close the Consolidate window if ListViewItems is empty. Change 3509402 by Nick.Darnell PR #3703: UE-46362: Fixing typo in EUMGSequencePlayMode.PingPong comment (Contributed by gsfreema) Change 3510447 by Arciel.Rekman ReplayProxy: changed protected to private. Change3510467by Max.Chen Property Editor: Disable color widget when editing is disabled. #jira UE-46331 Change 3511249 by Matt.Kuhlenschmidt PR #3715: Turn off the automatic expiration of the restore assets notification (Contributed by IHappyDayI) Change 3511286 by Matt.Kuhlenschmidt Added ability to set properties from USD attributes when using scene import to import USD files. See UsdPropTestScene.usda for an example file of how this works Change 3511528 by Cody.Albert Updated FMoviePlayerWidgetRenderer to use Slate time instea of application time Change 3512149 by Matt.Kuhlenschmidt Dont save non-dirty built data when playing PIE in a standalone process #jira UE-46422 Change 3512259 by Matt.Kuhlenschmidt Fix static analysis Change 3512291 by Matt.Kuhlenschmidt PR #3719: Updating UEditorEngine::ReplaceActors to not copy array of actors (Contributed by gsfreema) Change 3512911 by Matt.Kuhlenschmidt Fixed USD property setting crashing if the usd file contained an array with 0 elements. Fixed USD property setting creating invalid tmaps if the usd file contained a key that already existed Change 3513725 by Matt.Kuhlenschmidt PR #3726: Copy/paste fix for SAdvancedDropdownRow::Construct() (Contributed by jovisgCL) Change 3514453 by Jamie.Dale Added a way to set the UEnum used by a UEnumProperty after using the default constructor This will assert if called on an instance that has already been initialized Change 3514858 by Alexis.Matte Fix crash when importing animation and choosing a different value for option "Import Meshes In Bone Hierarchy" then the value use to import the skeletal mesh. In some case there is no skinned mesh. Change 3514875 by Matt.Kuhlenschmidt PR #3721: Fixed. Screen Message was showed always when screenshot is captured(F9) (Contributed by shuaiharry) Change 3515859 by Bradut.Palas #jira UE-46516 The RenameTextBox didn't handle the OnTextCommitted event (which can be triggered when pressing Enter in the box). Now it does. Change 3515998 by Jamie.Dale Adding missing ) to some log messages Change 3517681 by Matt.Kuhlenschmidt Fix automated import not applying any texure settings to imported textures Change 3517703 by Nick.Darnell Slate - Marking SWidget's destructor as virtual (it always has been because of the parent), but this makes it more obvious. Change 3517737 by Nick.Darnell Slate - The retainer widget now only knows how to store the images in gamma space, rather than rendering in linear and storing using sRGB writes. If you do it that way - you end up in a state of having premultiplied linear space stored in sRGB, and getting that back into a state that looks correct when you finally render it with the rest of Slate becomes very difficult, so to make things simpler Change 3517758 by Nick.Darnell UMG - Updating the retainer box categories and visibility. Change 3517795 by Nick.Darnell Slate - We now don't do inherited volatility if we're also caching. Change 3517861 by Matt.Kuhlenschmidt Update windows USD to .75 Change 3517867 by Matt.Kuhlenschmidt Delete OpenEXR from USD dependencies. It is no longer used Change 3517873 by Matt.Kuhlenschmidt Updated USD windows binaries Change 3517896 by Max.Chen Sequencer: Call SkyLightComponent's SetLightColor() directly, similar to LightComponent #jira UE-46669 Change 3518240 by Max.Chen Sequencer: Set needs update when binding. #jira UE-46619 Change 3518492 by Max.Chen Sequencer: If already at the correct play position, don't jump to it. This fixes a bug where if you play to a position and pause, resuming play will playforward and not keep pausing. #jira UE-45996, UE-45997 Change 3518997 by Max.Chen Fbx: Fix aperture width, height, focal length and field of view calculations. #jira UE-46754 Change 3520190 by Jamie.Dale Cleaned up SCC log spam when finding out-of-date dependencies Change 3520237 by Yannick.Lange VR Editor: cleanup auto entry. Removed TimeSinceHMDChecked and added extra check for if there is currently a vr mode active. Change 3520923 by Max.Chen Sequencer: Refactor displaying sequencer settings in editor so that they're always available and not only when the sequencer type is instantiated. #jira UE-46301 Change 3521212 by Matt.Kuhlenschmidt PR #3757: MAX_NAME_LENGHT -> MAX_NAME_LENGTH (Contributed by Josef-CL) #jira UE-46821 Change 3521216 by Matt.Kuhlenschmidt PR #3751: Spelling fix for ESlateVisibility comment (Contributed by Triplelexx) #jira UE-46810 Change 3521221 by Matt.Kuhlenschmidt PR #3733: UE-46683: Don't increment MovieIndex when playing next movie (Contributed by projectgheist) #jira UE-46683,UE-46714 Change 3521344 by Yannick.Lange Fix selection tools in the Levels editor window. After selecting all levels SWorldHierarchyImpl::OnUpdateSelection used GetSelectedTreeItems(). At that point the tree items were not updated yet and it would return the 'previous' items. Making it look like nothing happened. Instead WorldModel->GetSelectedLevels() had to be used to get the new list of selected levels (this was used in 4.16) and then convert the list of FLevelModel to the new system that uses WorldHierarchy::FWorldTreeItemID. #jira UE-46741 Change 3521825 by Joe.Graf #Xb1 Added missing VectorSetFloat1 by copying the one in UnrealMathSSE.h #CodeReview: ben.woodhouse Change 3522114 by Joe.Graf #Xb1 Changed the missing VectorSetFloat1 to use MakeRegisterVector to be more consistent with other Xbox defines per Ben's code review #CodeReview: ben.woodhouse Change 3524202 by Matt.Kuhlenschmidt Prevent resizing when a context menu is open. This prevents a number of rare crashes when a window is resized when a child menu is open causing the child to lose connection to the parent (happens when the parent widgets are clipped and no longer processed). This is consistent with behavior on windows and mac. #jira UE-46653 Change 3524263 by Bradut.Palas #jira UE-46671 The issue happened because a parent callback of OnAssetRenameCommitted would allow an implicit sync and it would reset the search. Solved by blocking the parent callback if the user is searching. Change 3524265 by Bradut.Palas #jira UE-46261 Console command was doing something illegal. Opening a map from editor when multiprocess and client mode were enabled is prohibited by code in Playlevel.cpp (( !CanRunUnderOneProcess && PlayNetMode == EPlayNetMode::PIE_Client )) Solved by banning that specific use of the command. Change 3524266 by Bradut.Palas #jira UE-45592 The bug was caused by an iteration in EndPlayMap() that re-selected all previous actors but without the notify flag (hence, not triggering the code that validated showing the transform widget). Fixed by notifying just once per group, for performance reasons. Change 3524585 by Bradut.Palas Back out changelist 3524265 until I can figure out why the build system doesn't like it. Change 3525921 by Bradut.Palas Resubmitting revision 3524265 with properly guarded editor code (#if WITH_EDITOR) Change 3526124 by Matt.Kuhlenschmidt Remvoe debug canvas proxy Change 3526139 by Matt.Kuhlenschmidt Force low quality fallback mode on ES2 devices for slate blur widgets. This feature does not work on es2 Change 3526663 by Cody.Albert Fixed sequencer bindings to correctly work on streamed level in standalone preview mode Change 3527028 by Cody.Albert Back out changelist 3526663 Change 3527241 by Cody.Albert Fixed sequencer bindings to correctly work on streamed level in standalone preview mode Change 3527829 by Max.Chen Fbx: Add static transform values to curve data import. #jira UE-46888 Change 3527830 by Max.Chen Sequencer: Import static/default transforms and camera focal lengths from fbx. #jira UE-46888 Change 3528768 by Matt.Kuhlenschmidt Refactor of GetDetailsView method on IDetalLayoutBuilder for some upcoming changes. There is no longer a guarantee that a physical details panel is present wwhen customizing a property so GetDetailsView now returns a pointer and will be null if no details view exists. This refactor is necessary for a change to allow us to make loose property widgets for use outside of a details view. Change 3528776 by Yannick.Lange Allow thumbnails to be captured from a viewport always. #jira UE-45392 Change 3530675 by Michael.Dupuis #jira UE-46913 : Added extra validation to prevent possible crash Change 3530991 by Matt.Kuhlenschmidt Added ability for users to specifiy usd plugins for the USD importer Change 3531110 by Matt.Kuhlenschmidt Added automated import support for USD. Automated import now also supports loading a level per import group so that factories may spawn actors and manipulate the level Change 3531119 by Matt.Kuhlenschmidt USD Scene import now uses actor factories to determine the correct actor type to spawn for an asset specified in USD Change 3531220 by Jamie.Dale Fixed some places that were iterating over sets/maps using their element indices as if they were the sparse indices Change 3531831 by Cody.Albert BP nodes can no longer be renamed on read-only graphs. Change 3531938 by Yannick.Lange Enable setting justification at runtime for multi-line text boxes. #jira UE-44801 Change 3533011 by Matt.Kuhlenschmidt Exporting render targets now chooses PNG if the render target format is an LDR format Change 3533370 by Arciel.Rekman Fix comparison of the RT format. Change 3533717 by Nick.Darnell Slate - Adding justification to SEditableText and SpinBox, also adding the field for UMG. Change 3534756 by Arciel.Rekman Linux: add path to bundled GL headers. - Seems like we have been implicitly relying on it being added someplace else or simply present in the system. - Change by Cengiz.Terzibas Change 3535421 by Arciel.Rekman Reduce SCW logspam on Linux (UE-46634) #jira UE-46634 Change 3537520 by Matt.Kuhlenschmidt PR #3780: Fix typo steam to stream (Contributed by YuchenMei) Change 3537539 by Nick.Darnell UMG - Fixing a bug with aspect ratio locking cameras when in HDPI mode, the spaces were slightly different. Moving over the code that calculates the offsets to function in normalized space, so that it's trivial to combine with the existing normalized viewport dimensions and offset information, without space confusion. Change 3537542 by Nick.Darnell UMG - Fixing some bugs with the retainer widget which was not properly resetting or registering the hit testing information when rendered every frame. This should fix some issues that have been seen with clicks locking the viewport rendering, or not being clickable. Change 3537596 by Alexis.Matte Fbx SDK 2018.1.1 Integration #jira UE-45070 Change 3537672 by Matt.Kuhlenschmidt Simple fix for seconds of time being spent refreshing the settings editor if commands are registered while it is open. The request to refresh is deferred until next tick, meaning that each command list registered in a frame is not refreshing the details panel. Change 3537796 by Alexis.Matte Make sure all general settings are persist when we re-import a staticmesh from fbx file. #jira UE-46829 Change 3537961 by Michael.Dupuis #jira UE-47222: Prevent possible crash in some bad drag & drop case Change 3538149 by Alexis.Matte Make sure we export NTB information instead of just the normal when exporting to fbx #jira UE-46785 Change 3538237 by Alexis.Matte Fix import of large fbx scene (over 2 Gb) pr #3784 #jira UE-47124 Change 3538270 by Lauren.Ridge Epic Friday: Preview scenes in material editors Change 3539707 by Yannick.Lange Optimize viewport interactor hitresult for laser. Store the first hitresult and use that when calling UViewportInteractor::GetHitResultFromLaserPointer multiple times a frame. Change 3539964 by Lauren.Ridge Fix for cubemap not persisting between loads Change 3540321 by Arciel.Rekman Linux: CEF rebuilt with fewer dependencies (UE-46433). - Removed source-only binary to save size (we can link to the runtime one, this also allows RPATH to be generated automatically). - Change by Cengiz.Terzibas, polished by RCL. Change 3540458 by Alexis.Matte Fix the HDR pixel inspector. The HDR value is now RGBA in editor viewport and RGB in Game mode. #jira UE-47199 Change 3540681 by Arciel.Rekman Linux: fix flickering (UE-46351) - redoing fix from 4.17 - Slate rendering policy can set a scissor rect equal to a (smaller) window, which would get inherited by the scene renderer later. #jira UE-46351 (Redoing the fix from CL 3538578 in 4.17). Change 3540838 by Matt.Kuhlenschmidt Fix locked actors still being moved by piloting them Change 3542212 by Nick.Darnell Slate - Fixing a crash with per character wrapping. When used in rich text fields, it can cause a crash due to negative lengths for measurements, due to the way we calculate start and end indexes. New code now ensures the End is always >= to the Start. Change 3544033 by Arciel.Rekman Drop and deprecate /-prefixed commandline switches. - Dropped on all platforms except Windows, where it will produce a warning. Complete drop is expected in 4.19. Change 3544213 by Nick.Darnell Slate - Fixing another potential crash with the slate loading thread. The default movie player was listening for map load finishing using the AddSP callaback, which means the weakptr would be accessed, switching these over to AddRaws to be safer. Change 3546113 by Nick.Darnell Slate - Resurecting the slate visualizer support in the slate renderer for batch visualization, and overdraw. Change 3547129 by Michael.Trepka Few small changes that make UnrealBuildTool faster when running on Mono Change 3547454 by Jamie.Dale Added search to editable texts Change 3547460 by Jamie.Dale The output log now applies a search to its editable text when filtering This highlights the term matches on each line Change 3548177 by Jamie.Dale Optimized PO entry look-up Change 3548287 by Matt.Kuhlenschmidt Fix one off speedtree crash #jira UE-47538 Change 3548377 by Lauren.Ridge Checking that the Environment Map Path is set before trying to load it. #jira UE-47365 Change 3548628 by Matt.Kuhlenschmidt Fix focus graphic for tabs not pointing to the correct image Change 3549289 by Max.Chen Movie Scene Capture: Move window to within the desktop bounds when resizing. #jira UE-37330 Change 3549290 by Arciel.Rekman Fix hlslcc not working properly with newer clangs. - Both the clang 3.8+ problem and UB reported by UBSan. Change3550573by Max.Chen Sequencer: Track drag drop. Implement drag and drop onto a camera track, subscene track, and cinematic shot track. #jira UE-45773 #jira UE-45387 Change 3550729 by Max.Chen Sequence Recorder: Add interpolation and tangent settings for animation recording keys #jira UE-46146 Change 3551558 by Nick.Darnell UMG - Tweaking some designer elements, playing around with a 'real-time' mode. Also fixing a bug with decendant widgets in named slots not triggering design effects like updating the widget switcher. #jira UE-39404 Change 3551671 by Joe.Graf Merged over the change to expose more of dormancy to Blueprints (UE-46240) Change 3551684 by Cody.Albert Removing some unused code from map check Change 3552673 by Yannick.Lange Fix crash select all levels with folders in the treewidget. Change 3552960 by Yannick.Lange Frontend filter for files referenced by any level in the project and a filter for not referenced by any level. #jira UE-22153 Change 3553727 by Max.Chen Sequencer: Capture thumbnail before pre save so that the thumbnail isn't captured with the evaluation in a reset state. #jira UE-47693 Change 3553778 by Arciel.Rekman Cache check for compiler availability (UE-47699). - Fixes performance drop in the blueprint editor. Better than caching in a particular source accessors because affects all accessors (incl. Mac which isn't cached either) and reduces calls. Change 3554128 by Matt.Kuhlenschmidt Null out GEditor after it has been destoyed. Any modules that access GEditor can now properly check for a null geditor instead of blindly accessing it Change 3554266 by Max.Chen Movie Scene Capture: Override cinematic mode in the movie scene capture. #jira UE-33473 Change 3555563 by Alexis.Matte Fix static mesh screensize lost when converting from an old version. The conversion require valid extended bounds which was converted after the LOD screensize. #jira UE-47697 Change 3555755 by Yannick.Lange VR Editor: Add exit button inside new menu called "system" on radial menu. Still needs correct icons. Change 3556334 by Matt.Kuhlenschmidt Added a new type of property editor called a property row generator. This is essentially a details panel that can generate each unique row but adds no visual styling around the property editors and does not generate a master tree widget for the properties. This is useful for creating proper widgets for properties and displaying them in a UI that is not the details panel Change 3558100 by Matt.Kuhlenschmidt PR #3823: Incorrect comment syntax in ini files (Contributed by projectgheist) Change 3558240 by Lauren.Ridge Move floor in material editor preview scene based on preview mesh Change 3558242 by Matt.Kuhlenschmidt Fix console variables help page showing only rendering cvars by default Change 3558243 by Matt.Kuhlenschmidt Fix static analysis Change 3558342 by Alexis.Matte Make the code to find the best sample rate to import fbx animation more simple and more robust. The code need to be able to support all the possible case. Add a lot of animation sample rate automation tests #jira UE-47342 Change 3558515 by Yannick.Lange VR Editor: Changed icon for system and exit button on radial menu. Change 3558973 by Matt.Kuhlenschmidt Fix camera placement of the default map Change 3559230 by Arciel.Rekman Do not link CEF3 for servers (UE-47721). Change 3559572 by Arciel.Rekman Linux: make sure the engine is rebuilt during the updates. Change 3560197 by Arciel.Rekman Linux: cosmetic cleanup of an old code. Change 3560904 by Max.Chen Movie Scene Capture: Expose "Open Folder" hyperlink while capturing. Change 3561213 by Matt.Kuhlenschmidt Enable USD by default in QA game for testing Change 3561928 by Matt.Kuhlenschmidt Fix green glowing in the mateiral editor #jira UE-47826 Change 3562259 by Arciel.Rekman Made FPlatformMisc::DebugBreak() not inlined on Linux. - Saves a great deal of binary size without really impacting a performance. Change3562630by Arciel.Rekman Make Linux editor compilable with clang 5.0-rc1. Change 3563564 by Yannick.Lange Fix Cube Static Mesh Thumbnail renders black. Cleared out the thumbnail, causing it to create the correct new one. #jira UE-47777 Change 3564529 by Jamie.Dale Const-correct UScriptStruct::ExportText Change 3564972 by Alexis.Matte Fix staticmesh merge applying build scale multiple time Git PR #3807 #jira UE-47645 Change 3565253 by Arciel.Rekman Fix "Anim to Play" being inaccessible after import (UE-47885). - The variable was not initialized and could remain false on Linux. #jira UE-47885 Change 3565293 by Jamie.Dale Merged "Categories" into the main Output Log filter list Change 3565939 by Alexis.Matte Back out revision 3 from //UE4/Dev-Editor/Engine/Source/Developer/MeshMergeUtilities/Private/MeshMergeHelpers.cpp Change 3566081 by Alexis.Matte Fix staticmesh merge applying scale twice PR #3807 #jira UE-47645 Change 3566232 by Matt.Kuhlenschmidt Fix edit inline properties not clipping properly #jira UE-47775 [CL 3567077 by Matt Kuhlenschmidt in Main branch]
773 lines
28 KiB
C++
773 lines
28 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "PortableObjectPipeline.h"
|
|
#include "Misc/FileHelper.h"
|
|
#include "Misc/Paths.h"
|
|
#include "Internationalization/InternationalizationMetadata.h"
|
|
#include "Serialization/JsonInternationalizationMetadataSerializer.h"
|
|
#include "PortableObjectFormatDOM.h"
|
|
#include "TextNamespaceUtil.h"
|
|
#include "LocTextHelper.h"
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogPortableObjectPipeline, Log, All);
|
|
|
|
namespace
|
|
{
|
|
static const TCHAR* NewLineDelimiter = TEXT("\n");
|
|
|
|
struct FPortableObjectEntryIdentity
|
|
{
|
|
FString MsgCtxt;
|
|
FString MsgId;
|
|
FString MsgIdPlural;
|
|
};
|
|
|
|
bool operator==(const FPortableObjectEntryIdentity& LHS, const FPortableObjectEntryIdentity& RHS)
|
|
{
|
|
return LHS.MsgCtxt == RHS.MsgCtxt && LHS.MsgId == RHS.MsgId && LHS.MsgIdPlural == RHS.MsgIdPlural;
|
|
}
|
|
|
|
uint32 GetTypeHash(const FPortableObjectEntryIdentity& ID)
|
|
{
|
|
const uint32 HashA = HashCombine(GetTypeHash(ID.MsgCtxt), GetTypeHash(ID.MsgId));
|
|
const uint32 HashB = GetTypeHash(ID.MsgIdPlural);
|
|
return HashCombine(HashA, HashB);
|
|
}
|
|
|
|
struct FCaseSensitiveStringPair
|
|
{
|
|
public:
|
|
FCaseSensitiveStringPair(FString InFirst, FString InSecond)
|
|
: First(MoveTemp(InFirst))
|
|
, Second(MoveTemp(InSecond))
|
|
{
|
|
}
|
|
|
|
FORCEINLINE bool operator==(const FCaseSensitiveStringPair& Other) const
|
|
{
|
|
return First.Equals(Other.First, ESearchCase::CaseSensitive)
|
|
&& Second.Equals(Other.Second, ESearchCase::CaseSensitive);
|
|
}
|
|
|
|
FORCEINLINE bool operator!=(const FCaseSensitiveStringPair& Other) const
|
|
{
|
|
return !First.Equals(Other.First, ESearchCase::CaseSensitive)
|
|
|| !Second.Equals(Other.Second, ESearchCase::CaseSensitive);
|
|
}
|
|
|
|
friend inline uint32 GetTypeHash(const FCaseSensitiveStringPair& Id)
|
|
{
|
|
uint32 Hash = 0;
|
|
Hash = FCrc::StrCrc32(*Id.First, Hash);
|
|
Hash = FCrc::StrCrc32(*Id.Second, Hash);
|
|
return Hash;
|
|
}
|
|
|
|
FString First;
|
|
FString Second;
|
|
};
|
|
typedef TMultiMap<FCaseSensitiveStringPair, FCaseSensitiveStringPair> FCaseSensitiveStringPairMultiMap;
|
|
|
|
struct FCollapsedData
|
|
{
|
|
/** Mapping between a collapsed namespace (First) and key (Second), to an expanded namespace (First) and key (Second) */
|
|
FCaseSensitiveStringPairMultiMap CollapsedNSKeyToExpandedNSKey;
|
|
|
|
/** Mapping between a collapsed namespace (First) and source string/native translation (Second), to an expanded namespace (First) and key (Second) */
|
|
FCaseSensitiveStringPairMultiMap CollapsedNSSourceStringToExpandedNSKey;
|
|
};
|
|
|
|
/**
|
|
* Declarations
|
|
*/
|
|
FString ConditionIdentityForPOMsgCtxt(const FString& Namespace, const FString& Key, const TSharedPtr<FLocMetadataObject>& KeyMetaData, const ELocalizedTextCollapseMode InTextCollapseMode);
|
|
void ParsePOMsgCtxtForIdentity(const FString& MsgCtxt, FString& OutNamespace, FString& OutKey);
|
|
FString ConditionArchiveStrForPo(const FString& InStr);
|
|
FString ConditionPoStringForArchive(const FString& InStr);
|
|
FString ConvertSrcLocationToPORef(const FString& InSrcLocation);
|
|
FString GetConditionedKeyForExtractedComment(const FString& Key);
|
|
FString GetConditionedReferenceForExtractedComment(const FString& PORefString);
|
|
FString GetConditionedInfoMetaDataForExtractedComment(const FString& KeyName, const FString& ValueString);
|
|
TSharedRef<FInternationalizationManifest> BuildCollapsedManifest(FLocTextHelper& InLocTextHelper, const ELocalizedTextCollapseMode InTextCollapseMode, FCollapsedData& OutCollapsedData);
|
|
|
|
/**
|
|
* Definitions
|
|
*/
|
|
FString ConditionIdentityForPOMsgCtxt(const FString& Namespace, const FString& Key, const TSharedPtr<FLocMetadataObject>& KeyMetaData, const ELocalizedTextCollapseMode InTextCollapseMode)
|
|
{
|
|
const auto& EscapeMsgCtxtParticle = [](const FString& InStr) -> FString
|
|
{
|
|
FString Result;
|
|
for (const TCHAR C : InStr)
|
|
{
|
|
switch (C)
|
|
{
|
|
case TEXT(','): Result += TEXT("\\,"); break;
|
|
default: Result += C; break;
|
|
}
|
|
}
|
|
return Result;
|
|
};
|
|
|
|
const FString EscapedNamespace = EscapeMsgCtxtParticle(Namespace);
|
|
const FString EscapedKey = EscapeMsgCtxtParticle(Key);
|
|
|
|
const bool bAppendKey = InTextCollapseMode != ELocalizedTextCollapseMode::IdenticalNamespaceAndSource || KeyMetaData.IsValid();
|
|
const FString MsgCtxt = bAppendKey ? FString::Printf(TEXT("%s,%s"), *EscapedNamespace, *EscapedKey) : EscapedNamespace;
|
|
return ConditionArchiveStrForPo(MsgCtxt);
|
|
}
|
|
|
|
void ParsePOMsgCtxtForIdentity(const FString& MsgCtxt, FString& OutNamespace, FString& OutKey)
|
|
{
|
|
const FString ConditionedMsgCtxt = ConditionPoStringForArchive(MsgCtxt);
|
|
|
|
static const int32 OutputBufferCount = 2;
|
|
FString* OutputBuffers[OutputBufferCount] = { &OutNamespace, &OutKey };
|
|
int32 OutputBufferIndex = 0;
|
|
|
|
FString EscapeSequenceBuffer;
|
|
|
|
auto HandleEscapeSequenceBuffer = [&]()
|
|
{
|
|
// Insert unescaped sequence if needed.
|
|
if (!EscapeSequenceBuffer.IsEmpty())
|
|
{
|
|
bool EscapeSequenceIdentified = true;
|
|
|
|
// Identify escape sequence
|
|
TCHAR UnescapedCharacter = 0;
|
|
if (EscapeSequenceBuffer == TEXT("\\,"))
|
|
{
|
|
UnescapedCharacter = ',';
|
|
}
|
|
else
|
|
{
|
|
EscapeSequenceIdentified = false;
|
|
}
|
|
|
|
// If identified, append the processed sequence as the unescaped character.
|
|
if (EscapeSequenceIdentified)
|
|
{
|
|
*OutputBuffers[OutputBufferIndex] += UnescapedCharacter;
|
|
}
|
|
// If it was not identified, preserve the escape sequence and append it.
|
|
else
|
|
{
|
|
*OutputBuffers[OutputBufferIndex] += EscapeSequenceBuffer;
|
|
}
|
|
// Either way, we've appended something based on the buffer and it should be reset.
|
|
EscapeSequenceBuffer.Empty();
|
|
}
|
|
};
|
|
|
|
for (const TCHAR C : ConditionedMsgCtxt)
|
|
{
|
|
// If we're out of buffers, break out. The particle list is longer than expected.
|
|
if (OutputBufferIndex >= OutputBufferCount)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Warning, TEXT("msgctxt found in PO has too many parts: %s"), *ConditionedMsgCtxt);
|
|
break;
|
|
}
|
|
|
|
// Not in an escape sequence.
|
|
if (EscapeSequenceBuffer.IsEmpty())
|
|
{
|
|
// Comma marks the delimiter between namespace and key, if present.
|
|
if(C == TEXT(','))
|
|
{
|
|
++OutputBufferIndex;
|
|
}
|
|
// Regular character, just copy over.
|
|
else if (C != TEXT('\\'))
|
|
{
|
|
*OutputBuffers[OutputBufferIndex] += C;
|
|
}
|
|
// Start of an escape sequence, put in escape sequence buffer.
|
|
else
|
|
{
|
|
EscapeSequenceBuffer += C;
|
|
}
|
|
}
|
|
// If already in an escape sequence.
|
|
else
|
|
{
|
|
// Append to escape sequence buffer.
|
|
EscapeSequenceBuffer += C;
|
|
|
|
HandleEscapeSequenceBuffer();
|
|
}
|
|
}
|
|
// Catch any trailing backslashes.
|
|
HandleEscapeSequenceBuffer();
|
|
}
|
|
|
|
FString ConditionArchiveStrForPo(const FString& InStr)
|
|
{
|
|
FString Result;
|
|
for (const TCHAR C : InStr)
|
|
{
|
|
switch (C)
|
|
{
|
|
case TEXT('\\'): Result += TEXT("\\\\"); break;
|
|
case TEXT('"'): Result += TEXT("\\\""); break;
|
|
case TEXT('\r'): Result += TEXT("\\r"); break;
|
|
case TEXT('\n'): Result += TEXT("\\n"); break;
|
|
case TEXT('\t'): Result += TEXT("\\t"); break;
|
|
default: Result += C; break;
|
|
}
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
FString ConditionPoStringForArchive(const FString& InStr)
|
|
{
|
|
FString Result;
|
|
FString EscapeSequenceBuffer;
|
|
|
|
auto HandleEscapeSequenceBuffer = [&]()
|
|
{
|
|
// Insert unescaped sequence if needed.
|
|
if (!EscapeSequenceBuffer.IsEmpty())
|
|
{
|
|
bool EscapeSequenceIdentified = true;
|
|
|
|
// Identify escape sequence
|
|
TCHAR UnescapedCharacter = 0;
|
|
if (EscapeSequenceBuffer == TEXT("\\\\"))
|
|
{
|
|
UnescapedCharacter = '\\';
|
|
}
|
|
else if (EscapeSequenceBuffer == TEXT("\\\""))
|
|
{
|
|
UnescapedCharacter = '"';
|
|
}
|
|
else if (EscapeSequenceBuffer == TEXT("\\r"))
|
|
{
|
|
UnescapedCharacter = '\r';
|
|
}
|
|
else if (EscapeSequenceBuffer == TEXT("\\n"))
|
|
{
|
|
UnescapedCharacter = '\n';
|
|
}
|
|
else if (EscapeSequenceBuffer == TEXT("\\t"))
|
|
{
|
|
UnescapedCharacter = '\t';
|
|
}
|
|
else
|
|
{
|
|
EscapeSequenceIdentified = false;
|
|
}
|
|
|
|
// If identified, append the processed sequence as the unescaped character.
|
|
if (EscapeSequenceIdentified)
|
|
{
|
|
Result += UnescapedCharacter;
|
|
}
|
|
// If it was not identified, preserve the escape sequence and append it.
|
|
else
|
|
{
|
|
Result += EscapeSequenceBuffer;
|
|
}
|
|
// Either way, we've appended something based on the buffer and it should be reset.
|
|
EscapeSequenceBuffer.Empty();
|
|
}
|
|
};
|
|
|
|
for (const TCHAR C : InStr)
|
|
{
|
|
// Not in an escape sequence.
|
|
if (EscapeSequenceBuffer.IsEmpty())
|
|
{
|
|
// Regular character, just copy over.
|
|
if (C != TEXT('\\'))
|
|
{
|
|
Result += C;
|
|
}
|
|
// Start of an escape sequence, put in escape sequence buffer.
|
|
else
|
|
{
|
|
EscapeSequenceBuffer += C;
|
|
}
|
|
}
|
|
// If already in an escape sequence.
|
|
else
|
|
{
|
|
// Append to escape sequence buffer.
|
|
EscapeSequenceBuffer += C;
|
|
|
|
HandleEscapeSequenceBuffer();
|
|
}
|
|
}
|
|
// Catch any trailing backslashes.
|
|
HandleEscapeSequenceBuffer();
|
|
return Result;
|
|
}
|
|
|
|
FString ConvertSrcLocationToPORef(const FString& InSrcLocation)
|
|
{
|
|
// Source location format: /Path1/Path2/file.cpp - line 123
|
|
// PO Reference format: /Path1/Path2/file.cpp:123
|
|
// @TODO: Note, we assume the source location format here but it could be arbitrary.
|
|
return InSrcLocation.Replace(TEXT(" - line "), TEXT(":"));
|
|
}
|
|
|
|
FString GetConditionedKeyForExtractedComment(const FString& Key)
|
|
{
|
|
return FString::Printf(TEXT("Key:\t%s"), *Key);
|
|
}
|
|
|
|
FString GetConditionedReferenceForExtractedComment(const FString& PORefString)
|
|
{
|
|
return FString::Printf(TEXT("SourceLocation:\t%s"), *PORefString);
|
|
}
|
|
|
|
FString GetConditionedInfoMetaDataForExtractedComment(const FString& KeyName, const FString& ValueString)
|
|
{
|
|
return FString::Printf(TEXT("InfoMetaData:\t\"%s\" : \"%s\""), *KeyName, *ValueString);
|
|
}
|
|
|
|
TSharedRef<FInternationalizationManifest> BuildCollapsedManifest(FLocTextHelper& InLocTextHelper, const ELocalizedTextCollapseMode InTextCollapseMode, FCollapsedData& OutCollapsedData)
|
|
{
|
|
TSharedRef<FInternationalizationManifest> CollapsedManifest = MakeShared<FInternationalizationManifest>();
|
|
|
|
InLocTextHelper.EnumerateSourceTexts([&](TSharedRef<FManifestEntry> InManifestEntry) -> bool
|
|
{
|
|
const FString CollapsedNamespace = InTextCollapseMode == ELocalizedTextCollapseMode::IdenticalPackageIdTextIdAndSource ? InManifestEntry->Namespace : TextNamespaceUtil::StripPackageNamespace(InManifestEntry->Namespace);
|
|
|
|
for (const FManifestContext& Context : InManifestEntry->Contexts)
|
|
{
|
|
bool bAddedContext = false;
|
|
|
|
// Check if the entry already exists in the manifest
|
|
TSharedPtr<FManifestEntry> ExistingEntry = CollapsedManifest->FindEntryByContext(CollapsedNamespace, Context);
|
|
if (ExistingEntry.IsValid())
|
|
{
|
|
if (InManifestEntry->Source.IsExactMatch(ExistingEntry->Source))
|
|
{
|
|
bAddedContext = true;
|
|
}
|
|
else
|
|
{
|
|
// Grab the source location of the conflicting context
|
|
const FManifestContext* ConflictingContext = ExistingEntry->FindContext(Context.Key, Context.KeyMetadataObj);
|
|
|
|
const FString Message = FLocTextHelper::SanitizeLogOutput(
|
|
FString::Printf(TEXT("Found previously entered localized string: %s [%s] %s %s=\"%s\" %s. It was previously \"%s\" %s in %s."),
|
|
*Context.SourceLocation,
|
|
*CollapsedNamespace,
|
|
*Context.Key,
|
|
*FJsonInternationalizationMetaDataSerializer::MetadataToString(Context.KeyMetadataObj),
|
|
*InManifestEntry->Source.Text,
|
|
*FJsonInternationalizationMetaDataSerializer::MetadataToString(InManifestEntry->Source.MetadataObj),
|
|
*ExistingEntry->Source.Text,
|
|
*FJsonInternationalizationMetaDataSerializer::MetadataToString(ExistingEntry->Source.MetadataObj),
|
|
*ConflictingContext->SourceLocation
|
|
)
|
|
);
|
|
UE_LOG(LogPortableObjectPipeline, Warning, TEXT("%s"), *Message);
|
|
|
|
InLocTextHelper.AddConflict(CollapsedNamespace, Context.Key, Context.KeyMetadataObj, InManifestEntry->Source, Context.SourceLocation);
|
|
InLocTextHelper.AddConflict(CollapsedNamespace, Context.Key, Context.KeyMetadataObj, ExistingEntry->Source, ConflictingContext->SourceLocation);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CollapsedManifest->AddSource(CollapsedNamespace, InManifestEntry->Source, Context))
|
|
{
|
|
bAddedContext = true;
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("Could not process localized string: %s [%s] %s=\"%s\" %s."),
|
|
*Context.SourceLocation,
|
|
*CollapsedNamespace,
|
|
*Context.Key,
|
|
*InManifestEntry->Source.Text,
|
|
*FJsonInternationalizationMetaDataSerializer::MetadataToString(InManifestEntry->Source.MetadataObj)
|
|
);
|
|
}
|
|
}
|
|
|
|
if (bAddedContext)
|
|
{
|
|
// Add this collapsed namespace/key pair to our mapping so we can expand it again during import
|
|
OutCollapsedData.CollapsedNSKeyToExpandedNSKey.AddUnique(FCaseSensitiveStringPair(CollapsedNamespace, Context.Key), FCaseSensitiveStringPair(InManifestEntry->Namespace, Context.Key));
|
|
|
|
// Add this collapsed namespace/source string pair to our mapping so we expand it again during import (also map it against any native "translation" as that's what foreign imports will use as their source for translations)
|
|
if (!Context.KeyMetadataObj.IsValid())
|
|
{
|
|
OutCollapsedData.CollapsedNSSourceStringToExpandedNSKey.AddUnique(FCaseSensitiveStringPair(CollapsedNamespace, InManifestEntry->Source.Text), FCaseSensitiveStringPair(InManifestEntry->Namespace, Context.Key));
|
|
|
|
if (InLocTextHelper.HasNativeArchive())
|
|
{
|
|
TSharedPtr<FArchiveEntry> NativeTranslation = InLocTextHelper.FindTranslation(InLocTextHelper.GetNativeCulture(), InManifestEntry->Namespace, Context.Key, nullptr);
|
|
if (NativeTranslation.IsValid() && !NativeTranslation->Translation.Text.Equals(InManifestEntry->Source.Text))
|
|
{
|
|
OutCollapsedData.CollapsedNSSourceStringToExpandedNSKey.AddUnique(FCaseSensitiveStringPair(CollapsedNamespace, NativeTranslation->Translation.Text), FCaseSensitiveStringPair(InManifestEntry->Namespace, Context.Key));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true; // continue enumeration
|
|
}, true);
|
|
|
|
return CollapsedManifest;
|
|
}
|
|
|
|
TMap<FPortableObjectEntryIdentity, TArray<FString>> ExtractPreservedPOComments(const FPortableObjectFormatDOM& InPortableObject)
|
|
{
|
|
TMap<FPortableObjectEntryIdentity, TArray<FString>> POEntryToCommentMap;
|
|
for (auto EntryPairIterator = InPortableObject.GetEntriesIterator(); EntryPairIterator; ++EntryPairIterator)
|
|
{
|
|
const TSharedPtr< FPortableObjectEntry >& Entry = EntryPairIterator->Value;
|
|
|
|
// Preserve only non-procedurally generated extracted comments.
|
|
const TArray<FString> CommentsToPreserve = Entry->ExtractedComments.FilterByPredicate([](const FString& ExtractedComment) -> bool
|
|
{
|
|
return !ExtractedComment.StartsWith("Key:") && !ExtractedComment.StartsWith("SourceLocation:") && !ExtractedComment.StartsWith("InfoMetaData:");
|
|
});
|
|
|
|
if (CommentsToPreserve.Num())
|
|
{
|
|
POEntryToCommentMap.Add(FPortableObjectEntryIdentity{ Entry->MsgCtxt, Entry->MsgId, Entry->MsgIdPlural }, CommentsToPreserve);
|
|
}
|
|
}
|
|
return POEntryToCommentMap;
|
|
}
|
|
|
|
bool LoadPOFile(const FString& POFilePath, FPortableObjectFormatDOM& OutPortableObject)
|
|
{
|
|
if (!FPaths::FileExists(POFilePath))
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Log, TEXT("Could not find file %s"), *POFilePath);
|
|
return false;
|
|
}
|
|
|
|
FString POFileContents;
|
|
if (!FFileHelper::LoadFileToString(POFileContents, *POFilePath))
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("Failed to load file %s."), *POFilePath);
|
|
return false;
|
|
}
|
|
|
|
if (!OutPortableObject.FromString(POFileContents))
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("Failed to parse Portable Object file %s."), *POFilePath);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ImportPortableObject(FLocTextHelper& InLocTextHelper, const FString& InCulture, const FString& InPOFilePath, const FCollapsedData& InCollapsedData)
|
|
{
|
|
FPortableObjectFormatDOM PortableObject;
|
|
if (!LoadPOFile(InPOFilePath, PortableObject))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool bModifiedArchive = false;
|
|
{
|
|
for (auto EntryPairIter = PortableObject.GetEntriesIterator(); EntryPairIter; ++EntryPairIter)
|
|
{
|
|
auto POEntry = EntryPairIter->Value;
|
|
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(LogPortableObjectPipeline, Error, TEXT("Portable Object entry has plural form we did not process. File: %s MsgCtxt: %s MsgId: %s"), *InPOFilePath, *POEntry->MsgCtxt, *POEntry->MsgId);
|
|
}
|
|
|
|
const FString SourceText = ConditionPoStringForArchive(POEntry->MsgId);
|
|
const FString Translation = ConditionPoStringForArchive(POEntry->MsgStr[0]);
|
|
|
|
TArray<FCaseSensitiveStringPair> NamespacesAndKeys; // Namespace (First) and Key (Second)
|
|
{
|
|
FString ParsedNamespace;
|
|
FString ParsedKey;
|
|
ParsePOMsgCtxtForIdentity(POEntry->MsgCtxt, ParsedNamespace, ParsedKey);
|
|
|
|
if (ParsedKey.IsEmpty())
|
|
{
|
|
// Legacy non-keyed PO entry - need to look-up the expanded namespace key/pairs via the namespace and source string
|
|
InCollapsedData.CollapsedNSSourceStringToExpandedNSKey.MultiFind(FCaseSensitiveStringPair(ParsedNamespace, SourceText), NamespacesAndKeys);
|
|
}
|
|
else
|
|
{
|
|
// Keyed PO entry - need to look-up the expanded namespace/key pairs via the namespace and key
|
|
InCollapsedData.CollapsedNSKeyToExpandedNSKey.MultiFind(FCaseSensitiveStringPair(ParsedNamespace, ParsedKey), NamespacesAndKeys);
|
|
}
|
|
}
|
|
|
|
if (NamespacesAndKeys.Num() == 0)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Log, TEXT("Could not import PO entry as it did not map to any known entries in the collapsed manifest data. File: %s MsgCtxt: %s MsgId: %s"), *InPOFilePath, *POEntry->MsgCtxt, *POEntry->MsgId);
|
|
continue;
|
|
}
|
|
|
|
for (const FCaseSensitiveStringPair& NamespaceAndKey : NamespacesAndKeys)
|
|
{
|
|
// Alias for convenience of reading
|
|
const FString& Namespace = NamespaceAndKey.First;
|
|
const FString& Key = NamespaceAndKey.Second;
|
|
|
|
// Get key metadata from the manifest, using the namespace and key.
|
|
const FManifestContext* ItemContext = nullptr;
|
|
{
|
|
// Find manifest entry by namespace and key
|
|
TSharedPtr<FManifestEntry> ManifestEntry = InLocTextHelper.FindSourceText(Namespace, Key);
|
|
if (ManifestEntry.IsValid())
|
|
{
|
|
ItemContext = ManifestEntry->FindContextByKey(Key);
|
|
}
|
|
}
|
|
|
|
//@TODO: Take into account optional entries and entries that differ by keymetadata. Ex. Each optional entry needs a unique msgCtxt
|
|
|
|
// Attempt to import the new text (if required)
|
|
const TSharedPtr<FArchiveEntry> FoundEntry = InLocTextHelper.FindTranslation(InCulture, Namespace, Key, ItemContext ? ItemContext->KeyMetadataObj : nullptr);
|
|
if (!FoundEntry.IsValid() || !FoundEntry->Source.Text.Equals(SourceText, ESearchCase::CaseSensitive) || !FoundEntry->Translation.Text.Equals(Translation, ESearchCase::CaseSensitive))
|
|
{
|
|
if (InLocTextHelper.ImportTranslation(InCulture, Namespace, Key, ItemContext ? ItemContext->KeyMetadataObj : nullptr, FLocItem(SourceText), FLocItem(Translation), ItemContext && ItemContext->bIsOptional))
|
|
{
|
|
bModifiedArchive = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bModifiedArchive)
|
|
{
|
|
// Trim any dead entries out of the archive
|
|
InLocTextHelper.TrimArchive(InCulture);
|
|
|
|
FText SaveError;
|
|
if (!InLocTextHelper.SaveArchive(InCulture, &SaveError))
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("%s"), *SaveError.ToString());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ExportPortableObject(FLocTextHelper& InLocTextHelper, const FString& InCulture, const FString& InPOFilePath, const ELocalizedTextCollapseMode InTextCollapseMode, TSharedRef<FInternationalizationManifest> InCollapsedManifest, const FCollapsedData& InCollapsedData, const bool bShouldPersistComments)
|
|
{
|
|
FPortableObjectFormatDOM NewPortableObject;
|
|
|
|
FString LocLang;
|
|
if (!NewPortableObject.SetLanguage(InCulture))
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("Skipping export of culture %s because it is not recognized PO language."), *InCulture);
|
|
return false;
|
|
}
|
|
|
|
NewPortableObject.SetProjectName(FPaths::GetBaseFilename(InPOFilePath));
|
|
NewPortableObject.CreateNewHeader();
|
|
|
|
// Add each manifest entry to the PO file
|
|
for (FManifestEntryByStringContainer::TConstIterator ManifestIterator = InCollapsedManifest->GetEntriesByKeyIterator(); ManifestIterator; ++ManifestIterator)
|
|
{
|
|
const TSharedRef<FManifestEntry> ManifestEntry = ManifestIterator.Value();
|
|
|
|
// For each context, we may need to create a different or even multiple PO entries.
|
|
for (const FManifestContext& Context : ManifestEntry->Contexts)
|
|
{
|
|
TSharedRef<FPortableObjectEntry> PoEntry = MakeShareable(new FPortableObjectEntry());
|
|
|
|
// For export we just use the first expanded namespace/key pair to find the current translation (they should all be identical due to how the import works)
|
|
const FCaseSensitiveStringPair& ExportNamespaceKeyPair = InCollapsedData.CollapsedNSKeyToExpandedNSKey.FindChecked(FCaseSensitiveStringPair(ManifestEntry->Namespace, Context.Key));
|
|
|
|
// Find the correct translation based upon the native source text
|
|
FLocItem ExportedSource;
|
|
FLocItem ExportedTranslation;
|
|
InLocTextHelper.GetExportText(InCulture, ExportNamespaceKeyPair.First, ExportNamespaceKeyPair.Second, Context.KeyMetadataObj, ELocTextExportSourceMethod::NativeText, ManifestEntry->Source, ExportedSource, ExportedTranslation);
|
|
|
|
PoEntry->MsgId = ConditionArchiveStrForPo(ExportedSource.Text);
|
|
PoEntry->MsgCtxt = ConditionIdentityForPOMsgCtxt(ManifestEntry->Namespace, Context.Key, Context.KeyMetadataObj, InTextCollapseMode);
|
|
PoEntry->MsgStr.Add(ConditionArchiveStrForPo(ExportedTranslation.Text));
|
|
|
|
//@TODO: We support additional metadata entries that can be translated. How do those fit in the PO file format? Ex: isMature
|
|
const FString PORefString = ConvertSrcLocationToPORef(Context.SourceLocation);
|
|
PoEntry->AddReference(PORefString); // Source location.
|
|
|
|
PoEntry->AddExtractedComment(FString::Printf(TEXT("Key:\t%s"), *Context.Key)); // "Notes from Programmer" in the form of the Key.
|
|
PoEntry->AddExtractedComment(FString::Printf(TEXT("SourceLocation:\t%s"), *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(FString::Printf(TEXT("InfoMetaData:\t\"%s\" : \"%s\""), *KeyName, *Value->ToString()));
|
|
}
|
|
}
|
|
if (InfoMetaDataStrings.Num())
|
|
{
|
|
PoEntry->AddExtractedComments(InfoMetaDataStrings);
|
|
}
|
|
|
|
NewPortableObject.AddEntry(PoEntry);
|
|
}
|
|
}
|
|
|
|
// Persist comments if requested.
|
|
if (bShouldPersistComments)
|
|
{
|
|
// Preserve comments from the specified file now
|
|
TMap<FPortableObjectEntryIdentity, TArray<FString>> POEntryToCommentMap;
|
|
{
|
|
FPortableObjectFormatDOM ExistingPortableObject;
|
|
if (LoadPOFile(InPOFilePath, ExistingPortableObject))
|
|
{
|
|
POEntryToCommentMap = ExtractPreservedPOComments(ExistingPortableObject);
|
|
}
|
|
}
|
|
|
|
// Persist the comments into the new portable object we're going to be saving.
|
|
for (const auto& Pair : POEntryToCommentMap)
|
|
{
|
|
const TSharedPtr<FPortableObjectEntry> FoundEntry = NewPortableObject.FindEntry(Pair.Key.MsgId, Pair.Key.MsgIdPlural, Pair.Key.MsgCtxt);
|
|
if (FoundEntry.IsValid())
|
|
{
|
|
FoundEntry->AddExtractedComments(Pair.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
NewPortableObject.SortEntries();
|
|
|
|
bool bPOFileSaved = false;
|
|
{
|
|
TSharedPtr<ILocFileNotifies> LocFileNotifies = InLocTextHelper.GetLocFileNotifies();
|
|
|
|
if (LocFileNotifies.IsValid())
|
|
{
|
|
LocFileNotifies->PreFileWrite(InPOFilePath);
|
|
}
|
|
|
|
//@TODO We force UTF8 at the moment but we want this to be based on the format found in the header info.
|
|
const FString OutputString = NewPortableObject.ToString();
|
|
bPOFileSaved = FFileHelper::SaveStringToFile(OutputString, *InPOFilePath, FFileHelper::EEncodingOptions::ForceUTF8);
|
|
|
|
if (LocFileNotifies.IsValid())
|
|
{
|
|
LocFileNotifies->PostFileWrite(InPOFilePath);
|
|
}
|
|
}
|
|
|
|
if (!bPOFileSaved)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("Could not write file %s"), *InPOFilePath);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
bool PortableObjectPipeline::Import(FLocTextHelper& InLocTextHelper, const FString& InCulture, const FString& InPOFilePath, const ELocalizedTextCollapseMode InTextCollapseMode)
|
|
{
|
|
// Build the collapsed manifest data needed to import
|
|
FCollapsedData CollapsedData;
|
|
TSharedRef<FInternationalizationManifest> CollapsedManifest = BuildCollapsedManifest(InLocTextHelper, InTextCollapseMode, CollapsedData);
|
|
|
|
return ImportPortableObject(InLocTextHelper, InCulture, InPOFilePath, CollapsedData);
|
|
}
|
|
|
|
bool PortableObjectPipeline::ImportAll(FLocTextHelper& InLocTextHelper, const FString& InPOCultureRootPath, const FString& InPOFilename, const ELocalizedTextCollapseMode InTextCollapseMode, const bool bUseCultureDirectory)
|
|
{
|
|
// We may only have a single culture if using this setting
|
|
if (!bUseCultureDirectory && InLocTextHelper.GetAllCultures().Num() > 1)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("bUseCultureDirectory may only be used with a single culture."));
|
|
return false;
|
|
}
|
|
|
|
// Build the collapsed manifest data needed to import
|
|
FCollapsedData CollapsedData;
|
|
TSharedRef<FInternationalizationManifest> CollapsedManifest = BuildCollapsedManifest(InLocTextHelper, InTextCollapseMode, CollapsedData);
|
|
|
|
// Process the desired cultures
|
|
bool bSuccess = true;
|
|
for (const FString& CultureName : InLocTextHelper.GetAllCultures())
|
|
{
|
|
// Which path should we use for the PO?
|
|
FString POFilePath;
|
|
if (bUseCultureDirectory)
|
|
{
|
|
POFilePath = InPOCultureRootPath / CultureName / InPOFilename;
|
|
}
|
|
else
|
|
{
|
|
POFilePath = InPOCultureRootPath / InPOFilename;
|
|
}
|
|
|
|
bSuccess &= ImportPortableObject(InLocTextHelper, CultureName, POFilePath, CollapsedData);
|
|
}
|
|
|
|
return bSuccess;
|
|
}
|
|
|
|
bool PortableObjectPipeline::Export(FLocTextHelper& InLocTextHelper, const FString& InCulture, const FString& InPOFilePath, const ELocalizedTextCollapseMode InTextCollapseMode, const bool bShouldPersistComments)
|
|
{
|
|
// Build the collapsed manifest data needed to export
|
|
FCollapsedData CollapsedData;
|
|
TSharedRef<FInternationalizationManifest> CollapsedManifest = BuildCollapsedManifest(InLocTextHelper, InTextCollapseMode, CollapsedData);
|
|
|
|
return ExportPortableObject(InLocTextHelper, InCulture, InPOFilePath, InTextCollapseMode, CollapsedManifest, CollapsedData, bShouldPersistComments);
|
|
}
|
|
|
|
bool PortableObjectPipeline::ExportAll(FLocTextHelper& InLocTextHelper, const FString& InPOCultureRootPath, const FString& InPOFilename, const ELocalizedTextCollapseMode InTextCollapseMode, const bool bShouldPersistComments, const bool bUseCultureDirectory)
|
|
{
|
|
// We may only have a single culture if using this setting
|
|
if (!bUseCultureDirectory && InLocTextHelper.GetAllCultures().Num() > 1)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("bUseCultureDirectory may only be used with a single culture."));
|
|
return false;
|
|
}
|
|
|
|
// The 4.14 export mode was removed in 4.17
|
|
if (InTextCollapseMode == ELocalizedTextCollapseMode::IdenticalPackageIdTextIdAndSource)
|
|
{
|
|
UE_LOG(LogPortableObjectPipeline, Error, TEXT("The export mode 'ELocalizedTextCollapseMode::IdenticalPackageIdTextIdAndSource' is no longer supported (it was deprecated in 4.15 and removed in 4.17). Please use 'ELocalizedTextCollapseMode::IdenticalTextIdAndSource' instead."));
|
|
return false;
|
|
}
|
|
|
|
// Build the collapsed manifest data to export
|
|
FCollapsedData CollapsedData;
|
|
TSharedRef<FInternationalizationManifest> CollapsedManifest = BuildCollapsedManifest(InLocTextHelper, InTextCollapseMode, CollapsedData);
|
|
|
|
// Process the desired cultures
|
|
bool bSuccess = true;
|
|
for (const FString& CultureName : InLocTextHelper.GetAllCultures())
|
|
{
|
|
// Which path should we use for the PO?
|
|
FString POFilePath;
|
|
if (bUseCultureDirectory)
|
|
{
|
|
POFilePath = InPOCultureRootPath / CultureName / InPOFilename;
|
|
}
|
|
else
|
|
{
|
|
POFilePath = InPOCultureRootPath / InPOFilename;
|
|
}
|
|
|
|
bSuccess &= ExportPortableObject(InLocTextHelper, CultureName, POFilePath, InTextCollapseMode, CollapsedManifest, CollapsedData, bShouldPersistComments);
|
|
}
|
|
|
|
return bSuccess;
|
|
}
|