From 9c4396ef492b3a54bcf849da1db25ef3925ed6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sat, 29 Jan 2022 19:05:12 +0100 Subject: [PATCH] feat(data): add translatable string --- .../Language/ILanguageService.cs | 10 +++++- .../Language/TranslatableString.cs | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs diff --git a/Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs b/Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs index 1afc2b3..f97e27c 100644 --- a/Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs +++ b/Data/NosSmooth.Data.Abstractions/Language/ILanguageService.cs @@ -25,5 +25,13 @@ public interface ILanguageService /// The key to translate. /// The language, will be used if null. /// The translated string or an error. - public Result GetTranslation(TranslationRoot root, LanguageKey key, Language? language = default); + public Result GetTranslation(TranslationRoot root, string key, Language? language = default); + + /// + /// Gets the translation of the given key. + /// + /// The translatable string containing . + /// The language, will be used if null. + /// The translated string or an error. + public Result GetTranslation(TranslatableString translatableString, Language? language = default); } \ No newline at end of file diff --git a/Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs b/Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs new file mode 100644 index 0000000..51bb4b9 --- /dev/null +++ b/Data/NosSmooth.Data.Abstractions/Language/TranslatableString.cs @@ -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; + +/// +/// Represents a string that may be translated. +/// +/// The root key of the translations. +/// The key of the string translation. +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Standard.")] +public record struct TranslatableString(TranslationRoot Root, string Key) +{ + /// + /// Gets the translated string, if available. + /// If not available, the key will be returned. + /// + public string Translated { get; private set; } = Key; + + /// + /// Fill this translatable string with a translation. + /// + /// The translation to fill. + public void Fill(string translation) + { + Translated = translation; + } +} \ No newline at end of file -- 2.49.0