diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-30 17:09:15 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-30 17:09:15 -0800 |
| commit | c5190ae74ab8fe13609362efce88fa4b8cc24f34 (patch) | |
| tree | e7762224afad491c37b70bab13756552c72fdd26 /src/WixToolset.Core/Link/CollateLocalizationsCommand.cs | |
| parent | d4f73e72985dc2f36e4228358f4dc9b6114414ab (diff) | |
| download | wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.tar.gz wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.tar.bz2 wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.zip | |
Fix resolution of localizations that are embedded in intermediates
Diffstat (limited to 'src/WixToolset.Core/Link/CollateLocalizationsCommand.cs')
| -rw-r--r-- | src/WixToolset.Core/Link/CollateLocalizationsCommand.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Link/CollateLocalizationsCommand.cs b/src/WixToolset.Core/Link/CollateLocalizationsCommand.cs new file mode 100644 index 00000000..ffa66210 --- /dev/null +++ b/src/WixToolset.Core/Link/CollateLocalizationsCommand.cs | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.Link | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Linq; | ||
| 8 | using WixToolset.Data; | ||
| 9 | using WixToolset.Extensibility.Services; | ||
| 10 | |||
| 11 | internal class CollateLocalizationsCommand | ||
| 12 | { | ||
| 13 | public CollateLocalizationsCommand(IMessaging messaging, IEnumerable<Localization> localizations) | ||
| 14 | { | ||
| 15 | this.Messaging = messaging; | ||
| 16 | this.Localizations = localizations; | ||
| 17 | } | ||
| 18 | |||
| 19 | private IMessaging Messaging { get; } | ||
| 20 | |||
| 21 | private IEnumerable<Localization> Localizations { get; } | ||
| 22 | |||
| 23 | public Dictionary<string, Localization> Execute() | ||
| 24 | { | ||
| 25 | var localizationsByCulture = new Dictionary<string, Localization>(StringComparer.OrdinalIgnoreCase); | ||
| 26 | |||
| 27 | foreach (var localization in this.Localizations) | ||
| 28 | { | ||
| 29 | if (localizationsByCulture.TryGetValue(localization.Culture, out var existingCulture)) | ||
| 30 | { | ||
| 31 | var merged = this.Merge(existingCulture, localization); | ||
| 32 | localizationsByCulture[localization.Culture] = merged; | ||
| 33 | } | ||
| 34 | else | ||
| 35 | { | ||
| 36 | localizationsByCulture.Add(localization.Culture, localization); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | return localizationsByCulture; | ||
| 41 | } | ||
| 42 | |||
| 43 | private Localization Merge(Localization existingLocalization, Localization localization) | ||
| 44 | { | ||
| 45 | var variables = existingLocalization.Variables.ToDictionary(v => v.Id); | ||
| 46 | var controls = existingLocalization.LocalizedControls.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); | ||
| 47 | |||
| 48 | foreach (var newVariable in localization.Variables) | ||
| 49 | { | ||
| 50 | if (!variables.TryGetValue(newVariable.Id, out var existingVariable) || (existingVariable.Overridable && !newVariable.Overridable)) | ||
| 51 | { | ||
| 52 | variables[newVariable.Id] = newVariable; | ||
| 53 | } | ||
| 54 | else if (!newVariable.Overridable) | ||
| 55 | { | ||
| 56 | this.Messaging.Write(ErrorMessages.DuplicateLocalizationIdentifier(newVariable.SourceLineNumbers, newVariable.Id)); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | foreach (var localizedControl in localization.LocalizedControls) | ||
| 61 | { | ||
| 62 | if (!controls.ContainsKey(localizedControl.Key)) | ||
| 63 | { | ||
| 64 | controls.Add(localizedControl.Key, localizedControl.Value); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | return new Localization(existingLocalization.Codepage, existingLocalization.Culture, variables, controls); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
