| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TranslationCatalogBuilder.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Collections.Immutable; |
| | | 10 | | using System.Resources; |
| | | 11 | | |
| | | 12 | | namespace MyNet.Globalization.Localization.Translation.Catalog; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Builder for constructing an immutable translation catalog by registering translation resources. |
| | | 16 | | /// </summary> |
| | | 17 | | internal sealed class TranslationCatalogBuilder : ITranslationResourceRegistry |
| | | 18 | | { |
| | 11 | 19 | | private readonly Dictionary<string, ResourceManager> _resources = new(StringComparer.Ordinal); |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | | 22 | | public void Register(string resourceKey, ResourceManager resourceManager) |
| | | 23 | | { |
| | 27 | 24 | | ArgumentException.ThrowIfNullOrWhiteSpace(resourceKey); |
| | 27 | 25 | | ArgumentNullException.ThrowIfNull(resourceManager); |
| | | 26 | | |
| | 27 | 27 | | _resources[resourceKey] = resourceManager; |
| | 27 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Builds the immutable translation catalog. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <returns>The built catalog.</returns> |
| | 11 | 34 | | public ITranslationCatalog Build() => new TranslationCatalog(_resources.ToImmutableDictionary(StringComparer.Ordinal |
| | | 35 | | } |
| | | 36 | | |