• 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

    Localization Diagnostics

    This article gives tips for diagnosing localization issues.

    .AddErrorHandler(func) adds a handler that handles localization file parse errors.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Add parse error printer
    localization.AddErrorHandler((ILocalizationError e) => Console.WriteLine(e));
    

    text.Errors is a property that contains text specific parse errors.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Try get text
    if (localization.LocalizedTextCached.TryGetValue(("", "Namespace.Apples"), out ILocalizedText text))
    {
        // Print any parse errors
        foreach (ILocalizationError error in text.Errors) WriteLine(error);
    }
    

    .FileQuery and .FileQueryCached can be queried for all the files that are visible to query mechanism.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Print files that are visible to localization
    if (localization.FileQueryCached.TryGetValue((null, null), out IEnumerable<ILocalizationFile> files))
        foreach (ILocalizationFile file in files)
            WriteLine(file.Key);
    

    .Files.FileProviders and .Files.FileProvidersCached can be inspected for files that are accessible to them.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Try each file provider
    foreach (var fp in localization.Files.FileProvidersCached)
    {
        // Try query files
        if (!fp.TryGetValue((null, null), out IEnumerable<ILocalizationFile> files)) continue;
        // Print file provider composition
        WriteLine(fp);
        // Print files
        foreach (ILocalizationFile file in files) WriteLine(file.Key);
    }
    

    Each assigned localization file system can be browsed for the resources that are visible to them. Note that embedded resources are typically added as file provider (see above), not as filesystem.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Print files that are visible to each file system
    foreach (ILocalizationFileSystem fs in localization.Files.FileSystems)
    {
        // Visit tree
        foreach (var file in fs.VisitTree(""))
        {
            // Print text
            string print = file.Path == "" ? fs.ToString()! : file.ToString(LocalizationFileSystemPrintTreeExtensions.PrintFormat.DefaultLong);
            // Write to console
            WriteLine(print);
        }
    }
    

    .LineQuery and .LineQueryCached can be queried for all the lines that are visible to the line query mechanism.

    // Get localization context
    ILocalization localization = Localization.Default;
    // Print lines that are visible to localization
    if (localization.LineQueryCached.TryGetValue((null, null), out IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines))
        foreach (var line in lines)
            WriteLine(string.Join(", ", line.Select(a => $"{a.Key}={a.Value.AsString}")));
    

    See Cache article for information about caches.

    Full Example

    Full example
    using Avalanche.Localization;
    using Avalanche.Utilities;
    using static System.Console;
    
    class diagnostics
    {
        public static void Run()
        {
            {
                // <01>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Add parse error printer
                localization.AddErrorHandler((ILocalizationError e) => Console.WriteLine(e));
                // </01>
            }
            {
                // <02>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Try get text
                if (localization.LocalizedTextCached.TryGetValue(("", "Namespace.Apples"), out ILocalizedText text))
                {
                    // Print any parse errors
                    foreach (ILocalizationError error in text.Errors) WriteLine(error);
                }
                // </02>
            }
            {
                // <03>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Print files that are visible to localization
                if (localization.FileQueryCached.TryGetValue((null, null), out IEnumerable<ILocalizationFile> files))
                    foreach (ILocalizationFile file in files)
                        WriteLine(file.Key);
                // </03>
            }
            {
                // <03B>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Try each file provider
                foreach (var fp in localization.Files.FileProvidersCached)
                {
                    // Try query files
                    if (!fp.TryGetValue((null, null), out IEnumerable<ILocalizationFile> files)) continue;
                    // Print file provider composition
                    WriteLine(fp);
                    // Print files
                    foreach (ILocalizationFile file in files) WriteLine(file.Key);
                }
                // </03B>
            }
            {
                // <04>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Print files that are visible to each file system
                foreach (ILocalizationFileSystem fs in localization.Files.FileSystems)
                {
                    // Visit tree
                    foreach (var file in fs.VisitTree(""))
                    {
                        // Print text
                        string print = file.Path == "" ? fs.ToString()! : file.ToString(LocalizationFileSystemPrintTreeExtensions.PrintFormat.DefaultLong);
                        // Write to console
                        WriteLine(print);
                    }
                }
                // </04>
            }
            {
                // <05>
                // Get localization context
                ILocalization localization = Localization.Default;
                // Print lines that are visible to localization
                if (localization.LineQueryCached.TryGetValue((null, null), out IEnumerable<IEnumerable<KeyValuePair<string, MarkedText>>> lines))
                    foreach (var line in lines)
                        WriteLine(string.Join(", ", line.Select(a => $"{a.Key}={a.Value.AsString}")));
                // </05>
            }
        }
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen