• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • 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.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • 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
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • 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
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • 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.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    Parameter emplacement

    .Place(parameterName, localizableText, ...) embeds a localizble text into placeholder.

    // Create localization
    ILocalization localization = Localization.CreateDefault();
    // Get texts
    ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
    ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
    ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
    
    // "{0_count} cats and {1_count} dogs"
    ILocalizableText catAndDog = (ILocalizableText) and.Place("0", cat, "1", dog);
    
    // Print "en"
    CultureInfo en = CultureInfo.GetCultureInfo("en");
    foreach (int catCount in new int[] { 0, 1, 2 })
        foreach(int dogCount in new int[] { 0, 1, 2 })
            WriteLine(catAndDog.Print(en, new object[] { catCount, dogCount }));
    WriteLine();
    
    // Print "fi"
    CultureInfo fi = CultureInfo.GetCultureInfo("fi");
    foreach (int catCount in new int[] { 0, 1, 2 })
        foreach(int dogCount in new int[] { 0, 1, 2 })
            WriteLine(catAndDog.Print(fi, new object[] { catCount, dogCount })); 
    
    no cats and no dogs
    no cats and a dog
    no cats and 2 dogs
    a cat and no dogs
    a cat and a dog
    a cat and 2 dogs
    2 cats and no dogs
    2 cats and a dog
    2 cats and 2 dogs
    
    0 kissaa ja 0 koiraa
    0 kissaa ja koira
    0 kissaa ja 2 koiraa
    kissa ja 0 koiraa
    kissa ja koira
    kissa ja 2 koiraa
    2 kissaa ja 0 koiraa
    2 kissaa ja koira
    2 kissaa ja 2 koiraa
    

    docs/emplacement/index.l.yaml:

    TemplateFormat: BraceAlphaNumeric
    PluralRules: Unicode.CLDR41
    
    Invariant:
    - Culture: ""
      Items:
      - Key: docs.emplacement.index.and
        Text: "{0} and {1}"
      - Key: docs.emplacement.index.cat
        Cases:
        - Text: "no cats"
          Plurals: "count:cardinal:zero:en"
        - Text: "a cat"
          Plurals: "count:cardinal:one:en"
        - Text: "{count} cats"
          Plurals: "count:cardinal:other:en" 
      - Key: docs.emplacement.index.dog
        Cases:
        - Text: "no dogs"
          Plurals: "count:cardinal:zero:en"
        - Text: "a dog"
          Plurals: "count:cardinal:one:en"
        - Text: "{count} dogs"
          Plurals: "count:cardinal:other:en" 
      - Key: docs.emplacement.index.pony
        Text: "a pony"
    
    Finnish:
    - Culture: fi
      Items:
      - Key: docs.emplacement.index.and
        Text: "{0} ja {1}"
      - Key: docs.emplacement.index.cat
        Cases:
        - Text: "kissa"
          Plurals: "count:cardinal:one"
        - Text: "{count} kissaa"
          Plurals: "count:cardinal:other" 
      - Key: docs.emplacement.index.dog
        Cases:
        - Text: "koira"
          Plurals: "count:cardinal:one"
        - Text: "{count} koiraa"
          Plurals: "count:cardinal:other" 
      - Key: docs.emplacement.index.pony
        Text: "poni"
    

    Parameter signature is modified by the parameters in the emplacements.

    // Create localization
    ILocalization localization = Localization.CreateDefault();
    // Get texts
    ILocalizableText and  = localization.LocalizableTextCached["docs.emplacement.index.and"];   // "{0} and {1}"
    ILocalizableText cat  = localization.LocalizableTextCached["docs.emplacement.index.cat"];   // "{count} cats"
    ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"];  // "a pony"
    
    // "{0_count} cats and a pony"
    ILocalizableText catAndPony = (ILocalizableText) and.Place("0", cat, "1", pony);
    
    // Print "en"
    CultureInfo en = CultureInfo.GetCultureInfo("en");
    foreach (int catCount in new int[] { 0, 1, 2 })
        WriteLine(catAndPony.Print(en, new object[] { catCount }));
    WriteLine();
    
    // Print "fi"
    CultureInfo fi = CultureInfo.GetCultureInfo("fi");
    foreach (int catCount in new int[] { 0, 1, 2 })
        WriteLine(catAndPony.Print(fi, new object[] { catCount }));
    
    no cats and a pony
    a cat and a pony
    2 cats and a pony
    
    0 kissaa ja poni
    kissa ja poni
    2 kissaa ja poni
    

    ILocalizableText can be used as argument as is. It localized to the requested language.

    // Create localization
    ILocalization localization = Localization.CreateDefault();
    // Get texts
    ILocalizableText and  = localization.LocalizableTextCached["docs.emplacement.index.and"];   // "{0} and {1}"
    ILocalizableText cat  = localization.LocalizableTextCached["docs.emplacement.index.cat"];   // "{count} cats"
    ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"];  // "a pony"
    
    // "{0_count} cats and {1}"
    ILocalizableText catAnd = (ILocalizableText) and.Place("0", cat);
    
    // Print "en"
    CultureInfo en = CultureInfo.GetCultureInfo("en");
    foreach (int catCount in new int[] { 0, 1, 2 })
        WriteLine(catAnd.Print(en, new object[] { catCount, pony }));
    WriteLine();
    
    // Print "fi"
    CultureInfo fi = CultureInfo.GetCultureInfo("fi");
    foreach (int catCount in new int[] { 0, 1, 2 })
        WriteLine(catAnd.Print(fi, new object[] { catCount, pony }));
    
    no cats and a pony
    a cat and a pony
    2 cats and a pony
    
    0 kissaa ja poni
    kissa ja poni
    2 kissaa ja poni
    

    ParameterlessText can be used for emplacing an argument permanently. Localizable text localizes to the requested culture when used as argument.

    // Create localization
    ILocalization localization = Localization.CreateDefault();
    // Get texts
    ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
    ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
    ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
    
    // Create localizable "2 cats", "3 dogs"
    ILocalizableText cats2 = (ILocalizableText)cat.Place("count", new ParameterlessText("2"));
    ILocalizableText dogs3 = (ILocalizableText)dog.Place("count", new ParameterlessText("3"));
    
    // Print "{0} and {1}"
    WriteLine(and.Print(null, new object[] { cats2, dogs3 })); // "2 cats and 3 dogs"
    CultureInfo fi = CultureInfo.GetCultureInfo("fi");
    WriteLine(and.Print(fi, new object[] { cats2, dogs3 }));   // "2 kissaa ja 3 koiraa"
    

    Read more about template emplacement.

    Full Example

    Full example
    using System.Globalization;
    using Avalanche.Localization;
    using Avalanche.Template;
    using static System.Console;
    
    class emplacement  // emplacement
    {
        public static void Run()
        {
            {
                // <01>
                // Create localization
                ILocalization localization = Localization.CreateDefault();
                // Get texts
                ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
                ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
                ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
    
                // "{0_count} cats and {1_count} dogs"
                ILocalizableText catAndDog = (ILocalizableText) and.Place("0", cat, "1", dog);
    
                // Print "en"
                CultureInfo en = CultureInfo.GetCultureInfo("en");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    foreach(int dogCount in new int[] { 0, 1, 2 })
                        WriteLine(catAndDog.Print(en, new object[] { catCount, dogCount }));
                WriteLine();
    
                // Print "fi"
                CultureInfo fi = CultureInfo.GetCultureInfo("fi");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    foreach(int dogCount in new int[] { 0, 1, 2 })
                        WriteLine(catAndDog.Print(fi, new object[] { catCount, dogCount })); 
                // </01>
            }
            {
                // <02>
                // Create localization
                ILocalization localization = Localization.CreateDefault();
                // Get texts
                ILocalizableText and  = localization.LocalizableTextCached["docs.emplacement.index.and"];   // "{0} and {1}"
                ILocalizableText cat  = localization.LocalizableTextCached["docs.emplacement.index.cat"];   // "{count} cats"
                ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"];  // "a pony"
    
                // "{0_count} cats and a pony"
                ILocalizableText catAndPony = (ILocalizableText) and.Place("0", cat, "1", pony);
    
                // Print "en"
                CultureInfo en = CultureInfo.GetCultureInfo("en");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    WriteLine(catAndPony.Print(en, new object[] { catCount }));
                WriteLine();
    
                // Print "fi"
                CultureInfo fi = CultureInfo.GetCultureInfo("fi");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    WriteLine(catAndPony.Print(fi, new object[] { catCount }));
                // </02>
            }
            {
                // <03>
                // Create localization
                ILocalization localization = Localization.CreateDefault();
                // Get texts
                ILocalizableText and  = localization.LocalizableTextCached["docs.emplacement.index.and"];   // "{0} and {1}"
                ILocalizableText cat  = localization.LocalizableTextCached["docs.emplacement.index.cat"];   // "{count} cats"
                ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"];  // "a pony"
    
                // "{0_count} cats and {1}"
                ILocalizableText catAnd = (ILocalizableText) and.Place("0", cat);
    
                // Print "en"
                CultureInfo en = CultureInfo.GetCultureInfo("en");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    WriteLine(catAnd.Print(en, new object[] { catCount, pony }));
                WriteLine();
    
                // Print "fi"
                CultureInfo fi = CultureInfo.GetCultureInfo("fi");
                foreach (int catCount in new int[] { 0, 1, 2 })
                    WriteLine(catAnd.Print(fi, new object[] { catCount, pony }));
                // </03>
            }
            {
                // <04>
                // Create localization
                ILocalization localization = Localization.CreateDefault();
                // Get texts
                ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
                ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
                ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
    
                // Create localizable "2 cats", "3 dogs"
                ILocalizableText cats2 = (ILocalizableText)cat.Place("count", new ParameterlessText("2"));
                ILocalizableText dogs3 = (ILocalizableText)dog.Place("count", new ParameterlessText("3"));
    
                // Print "{0} and {1}"
                WriteLine(and.Print(null, new object[] { cats2, dogs3 })); // "2 cats and 3 dogs"
                CultureInfo fi = CultureInfo.GetCultureInfo("fi");
                WriteLine(and.Print(fi, new object[] { cats2, dogs3 }));   // "2 kissaa ja 3 koiraa"
                // </04>
            }
        }
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen