| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ITranslationKeyResolver.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using System.Globalization; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Globalization.Localization.Translation.KeyResolving; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Resolves candidate translation keys based on translation options. |
| | | 14 | | /// </summary> |
| | | 15 | | public interface ITranslationKeyResolver |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Resolves a list of candidate translation keys based on the base key, translation options, and culture. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="baseKey">The base translation key.</param> |
| | | 21 | | /// <param name="options">Translation options.</param> |
| | | 22 | | /// <param name="culture">Culture used for pluralization rules.</param> |
| | | 23 | | /// <returns>A collection of <see cref="TranslationKeyCandidate"/> representing the resolved keys and inflection fal |
| | | 24 | | IReadOnlyCollection<TranslationKeyCandidate> Resolve(string baseKey, TranslationOptions options, CultureInfo culture |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Resolves a pluralized translation key based on the count and culture. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="baseKey">The base translation key.</param> |
| | | 30 | | /// <param name="count">The count used for pluralization.</param> |
| | | 31 | | /// <param name="culture">The culture used for pluralization rules.</param> |
| | | 32 | | /// <returns>The pluralized translation key.</returns> |
| | | 33 | | string ResolvePluralizedKey(string baseKey, decimal count, CultureInfo culture); |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Resolves a styled translation key based on the display style. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <param name="baseKey">The base translation key.</param> |
| | | 39 | | /// <param name="style">The display style.</param> |
| | | 40 | | /// <param name="culture">The culture used for pluralization rules.</param> |
| | | 41 | | /// <returns>The styled translation key.</returns> |
| | | 42 | | string ResolveStyledKey(string baseKey, DisplayStyle style, CultureInfo culture); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Represents a candidate translation key along with its associated fallback policy. This record encapsulates the trans |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="Key">The translation key.</param> |
| | | 49 | | /// <param name="Policy">The fallback policy associated with the translation key.</param> |
| | | 50 | | public sealed record TranslationKeyCandidate(string Key, TranslationFallbackPolicy Policy); |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Represents the policy for translation fallback, specifically whether inflection fallback is allowed when resolving t |
| | | 54 | | /// </summary> |
| | | 55 | | public sealed record TranslationFallbackPolicy |
| | | 56 | | { |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets a value indicating whether to allow inflection fallback when resolving translation keys. If true, inflectio |
| | | 59 | | /// </summary> |
| | | 60 | | public bool AllowInflectionFallback { get; init; } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Gets a translation fallback policy that does not allow inflection fallback. When this policy is used, the transl |
| | | 64 | | /// </summary> |
| | 519 | 65 | | public static TranslationFallbackPolicy Strict => new() { AllowInflectionFallback = false }; |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Gets a translation fallback policy that allows inflection fallback. When this policy is used, the translation ke |
| | | 69 | | /// </summary> |
| | 8190 | 70 | | public static TranslationFallbackPolicy Flexible => new() { AllowInflectionFallback = true }; |
| | | 71 | | } |
| | | 72 | | |