~ruther/NosSmooth

9c4396ef492b3a54bcf849da1db25ef3925ed6fd — František Boháček 3 years ago f40377a
feat(data): add translatable string
M Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs => Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs +9 -1
@@ 25,5 25,13 @@ public interface ILanguageService
    /// <param name="key">The key to translate.</param>
    /// <param name="language">The language, <see cref="CurrentLanguage"/> will be used if null.</param>
    /// <returns>The translated string or an error.</returns>
    public Result<string> GetTranslation(TranslationRoot root, LanguageKey key, Language? language = default);
    public Result<string> GetTranslation(TranslationRoot root, string key, Language? language = default);

    /// <summary>
    /// Gets the translation of the given key.
    /// </summary>
    /// <param name="translatableString">The translatable string containing .</param>
    /// <param name="language">The language, <see cref="CurrentLanguage"/> will be used if null.</param>
    /// <returns>The translated string or an error.</returns>
    public Result<string> GetTranslation(TranslatableString translatableString, Language? language = default);
}
\ No newline at end of file

A Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs => Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs +33 -0
@@ 0,0 1,33 @@
//
//  TranslatableString.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

namespace NosSmooth.Data.Abstractions.Language;

/// <summary>
/// Represents a string that may be translated.
/// </summary>
/// <param name="Root">The root key of the translations.</param>
/// <param name="Key">The key of the string translation.</param>
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Standard.")]
public record struct TranslatableString(TranslationRoot Root, string Key)
{
    /// <summary>
    /// Gets the translated string, if available.
    /// If not available, the key will be returned.
    /// </summary>
    public string Translated { get; private set; } = Key;

    /// <summary>
    /// Fill this translatable string with a translation.
    /// </summary>
    /// <param name="translation">The translation to fill.</param>
    public void Fill(string translation)
    {
        Translated = translation;
    }
}
\ No newline at end of file

Do not follow this link