• Avalanche
  • Avalanche.Core
  • Lexical

    Show / Hide Table of Contents
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
        • AspNetCore
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR41
        • Unicode.CLDR40
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Logging
      • Validation
      • Localization
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • ItfMessages
        • Win32Messages
        • ClrMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Service
      • Introduction
      • Service
        • IService
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Cast
        • Scope
        • Dispose
      • Handler
        • Introduction
        • IHandler
        • Cancel
        • Recursion
        • Cyclicity
        • Delegates
        • Casting
        • Invokable
        • Handlers
      • Request
        • Introduction
        • IRequest
        • [Request]
        • [ContextParameter]
        • Print Tree
      • Dependency Injection
        • Introduction
        • ServiceRequest<T>
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
      • Examples
        • Expression Example
        • Mapper Example
      • ServiceMessages
    • Avalanche.Writer
      • Introduction
      • Writer
      • Referer
      • TypeCast
      • DefaultConstructor
      • DelegateWriter
      • WriterPipe
      • ConstantWriter
      • PassthroughWriter
      • Context
      • WriterMessages
    • Avalanche.Accessor
      • Introduction
      • AccessorServices
      • List
        • ListAccessor
        • ListConstructor
        • ListDeconstructor
        • ListDefaultConstructor
        • ListGet
        • ListSet
        • ListAdd
        • ListInsert
        • ListClear
        • ListCount
        • ListIndexOf
        • ListRemoveAt
        • ListReferer
      • Map
        • MapAccessor
        • MapConstructor
        • MapDeconstructor
        • MapDefaultConstructor
        • MapSet
        • MapGet
        • MapRemove
        • MapClear
        • MapCount
        • MapReferer
      • Record
        • RecordAccessor
        • RecordConstructor
        • RecordDeconstructor
        • RecordDefaultConstructor
      • Field
        • FieldAccessor
        • FieldReader
        • FieldWriter
        • FieldReferer
      • Dependency Injection
        • Introduction
      • AccessorMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.DataType
      • Introduction
      • IDataTypeBase
      • IDataType
      • IRecordType
      • IFieldType
      • IUnionType
      • IListType
      • IMapType
      • IValueType
      • IEnumerationType
      • IIntegerType
      • IRealType
      • IStringType
      • IAnyType
      • DataTypeRequest
      • PrintTree
      • DataTypeMessages
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • EnumerableCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Concatenation
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • String
        • IEscaper
        • UnicodeString
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • Void
    • Avalanche.Core
      • License
      • Order

    ILocalizationLines

    ILocalizationLines contains table for localization line settings and providers.

    /// <summary>Record of line query settings and providers</summary>
    public interface ILocalizationLines
    {
        /// <summary>The provider that converts <see cref="ILocalizationFile"/> into lines.</summary>
        IProvider<ILocalizationFile, IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> FileReader { get; set; }
        /// <summary>The provider that converts <see cref="ILocalizationFile"/> into lines and caches.</summary>
        IProvider<ILocalizationFile, IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> FileReaderCached { get; set; }
    
        /// <summary>Queriers that return files that contain localization lines (Have format that implements <see cref="ILocalizationLineFileFormat"/>). Typically <see cref="ILocalizationFiles.Query"/></summary>
        IList<IProvider<(string? culture, string? @namespace), IEnumerable<ILocalizationFile>>> FileProviders { get; set; }
        /// <summary>Queriers that return files that contain localization lines (Have format that implements <see cref="ILocalizationLineFileFormat"/>). Typically <see cref="ILocalizationFiles.QueryCached"/></summary>
        IList<IProvider<(string? culture, string? @namespace), IEnumerable<ILocalizationFile>>> FileProvidersCached { get; set; }
    
        /// <summary>Explictly added lines</summary>
        IList<IEnumerable<KeyValuePair<string, MarkedText>>> Lines { get; set; }
        /// <summary>Line query providers.</summary>
        IList<IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>>> LineProviders { get; set; }
        /// <summary>Line query providers.</summary>
        IList<IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>>> LineProvidersCached { get; set; }
    
        /// <summary>Line query provider. Culture and Key are constraints, if null then less is filtered and more is passed.</summary>
        IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> Query { get; set; }
        /// <summary>Line query provider. Culture and Key are constraints, if null then less is filtered and more is passed.</summary>
        IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> QueryCached { get; set; }
    }
    

    ILocalizationLines is a property of ILocalization.

    ILocalization localization = new Localization();
    ILocalizationLines localizationLines = localization.Lines;
    

    Lines is a list where explicit lines are managed.

    ILocalization localization = new Localization();
    var line = new Dictionary<string, MarkedText> { { "TemplateFormat", "BraceNumeric" }, { "Culture", "" }, { "Key", "Namespace.Apples" }, { "Text", "You've got {0} apple(s)." } };
    localization.Lines.AddLine(line);
    

    .AddLine(culture, key, templateFormat, text, pluralRules?, plurals?) adds a line explicitly.

    ILocalization localization = new Localization();
    localization.Lines.AddLine(culture: "", key: "Namespace.Apples", templateFormat: "BraceNumeric", text: "You've got {0} apple(s).");
    

    LineProviders and LineProvidersCached are lists where queryable line providers are managed. A cached and non-cached version of line provider must be added to both lists.

    // Create localization
    ILocalization localization = new Localization();
    // Create provider
    IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> provider =
        new ResourceManagerLineProvider(docs.Resources.Resource1.ResourceManager);
    // Add provider (both are required)
    localization.Lines.LineProviders.Add(provider);
    localization.Lines.LineProvidersCached.Add(provider.ValueResultCaptured().Cached().ValueResultOpened());
    // Get text
    ILocalizedText? text = localization.LocalizableTextCached["docs.Resources.Resource1.Apples"];
    // Print text
    WriteLine(text.Print(CultureInfo.InvariantCulture, new object[] { 1 }));
    

    Query is concatenation of all the providers in the LineProviders property. This provider caches nothing and reads everything fresh from sources.

    ILocalization localization = Localization.Default;
    IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines = localization.Lines.QueryCached[("fi", "Namespace.Apples")];
    

    QueryCached is concatenation of all the providers in the LineProvidersCache property. This provider caches the results and the source files.

    ILocalization localization = Localization.Default;
    IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines = localization.Lines.QueryCached[("fi", "Namespace.Apples")];
    

    Full Example

    Full example
    using System.Globalization;
    using Avalanche.Localization;
    using Avalanche.Utilities;
    using Avalanche.Utilities.Provider;
    using static System.Console;
    
    class localizationlines
    {
        public static void Run()
        {
            {
                // <01>
                ILocalization localization = new Localization();
                ILocalizationLines localizationLines = localization.Lines;
                // </01>
            }
    
            {
                // <02>
                ILocalization localization = new Localization();
                var line = new Dictionary<string, MarkedText> { { "TemplateFormat", "BraceNumeric" }, { "Culture", "" }, { "Key", "Namespace.Apples" }, { "Text", "You've got {0} apple(s)." } };
                localization.Lines.AddLine(line);
                // </02>
            }
            {
                // <03>
                ILocalization localization = new Localization();
                localization.Lines.AddLine(culture: "", key: "Namespace.Apples", templateFormat: "BraceNumeric", text: "You've got {0} apple(s).");
                // </03>
            }
            {
                // <04>
                // Create localization
                ILocalization localization = new Localization();
                // Create provider
                IProvider<(string? culture, string? key), IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>>> provider =
                    new ResourceManagerLineProvider(docs.Resources.Resource1.ResourceManager);
                // Add provider (both are required)
                localization.Lines.LineProviders.Add(provider);
                localization.Lines.LineProvidersCached.Add(provider.ValueResultCaptured().Cached().ValueResultOpened());
                // Get text
                ILocalizedText? text = localization.LocalizableTextCached["docs.Resources.Resource1.Apples"];
                // Print text
                WriteLine(text.Print(CultureInfo.InvariantCulture, new object[] { 1 }));
                // </04>
            }
            {
                // <05>
                ILocalization localization = Localization.Default;
                IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines = localization.Lines.QueryCached[("fi", "Namespace.Apples")];
                // </05>
            }
            {
                // <06>
                ILocalization localization = Localization.Default;
                IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines = localization.Lines.QueryCached[("fi", "Namespace.Apples")];
                // </06>
            }
        }
    }
    
    Back to top Copyright © 2022 Toni Kalajainen, contact@avalanche.fi