mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-11 10:47:21 +00:00
Added the informal address to the BeyondFacts Lab (#1176)
This commit is contained in:
1 parent
b6c3fbb5db
commit
e77645f44c
48 files changed
+1254
-160
No files matched your search
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
public class I18N : ILang
|
||||
@@ -28,12 +30,51 @@ public class I18N : ILang
|
||||
/// </remarks>
|
||||
public CultureInfo Culture { get; private set; } = CultureInfo.InvariantCulture;
|
||||
|
||||
/// <summary>
|
||||
/// Asks where the form of address comes from, see AddressForm.
|
||||
/// </summary>
|
||||
private Func<AddressForm> addressFormSource = () => AddressForm.FORMAL;
|
||||
|
||||
/// <summary>
|
||||
/// How the texts of TA() address the person, in languages which tell a formal address from an informal one.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Like the language, it holds for every text, so that a static class, such as one with the labels of an enum,
|
||||
/// addresses the person the same way as a component does. Only texts of TA() have an informal variant; all
|
||||
/// other texts stay formal. Program.cs decides where the choice comes from, see UseAddressFormOf.
|
||||
/// </remarks>
|
||||
public AddressForm AddressForm => this.addressFormSource();
|
||||
|
||||
public static void Init(ILanguagePlugin language)
|
||||
{
|
||||
I.language = language;
|
||||
I.Culture = CommonTools.DeriveActiveCultureOrInvariant(language.IETFTag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets where the form of address comes from.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The source is asked for every text, so a changed setting shows as soon as a component renders again.
|
||||
/// </remarks>
|
||||
/// <param name="source">Gets the form of address the person chose.</param>
|
||||
public static void UseAddressFormOf(Func<AddressForm> source) => I.addressFormSource = source;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text which addresses the reader, in the form of address the person chose; see AddressForm.
|
||||
/// </summary>
|
||||
/// <param name="fallbackEN">The text in English (US).</param>
|
||||
/// <param name="typeNamespace">The namespace of the type requesting the text, used as part of the key.</param>
|
||||
/// <param name="typeName">The name of the type requesting the text, used as part of the key.</param>
|
||||
/// <returns>The text from the language plugin or the English text.</returns>
|
||||
public string TA(string fallbackEN, string? typeNamespace, string? typeName)
|
||||
{
|
||||
if(this.language is not null)
|
||||
return this.GetText(this.language, fallbackEN, typeNamespace, typeName, this.AddressForm);
|
||||
|
||||
return fallbackEN;
|
||||
}
|
||||
|
||||
#region Implementation of ILang
|
||||
|
||||
public string T(string fallbackEN)
|
||||
|
||||
Reference in new issue
Block a user