<commit_before>﻿/*********************************************************************************
 * LocalizedString.cs
 * 
 * Copyright (c) 2004-2018 <NAME>
 * 
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 * 
 *********************************************************************************/
using System;
using System.Diagnostics;

namespace Sandra.UI.WF
{
    /// <summary>
    /// Represents an immutable identifier for a <see cref="LocalizedString"/>.
    /// </summary>
    [DebuggerDisplay("{Key}")]
    public sealed class LocalizedStringKey : IEquatable<LocalizedStringKey>
    {
        /// <summary>
        /// Creates a <see cref="LocalizedStringKey"/> that serves as a placeholder key for strings that cannot be localized.
        /// </summary>
        public static LocalizedStringKey Unlocalizable(string displayText) => new LocalizedStringKey(null, displayText);

        /// <summary>
        /// Gets the string representation of this <see cref="LocalizedStringKey"/>. 
        /// </summary>
        internal readonly string Key;

        /// <summary>
        /// For untranslatable keys, returns the display text.
        /// </summary>
        internal readonly string DisplayText;

        private LocalizedStringKey(string key, string displayText)
        {
            if (displayText == null) throw new ArgumentNullException(nameof(displayText));
            Key = key;
            DisplayText = displayText;
        }

        /// <summary>
        /// Constructs a new instance of <see cref="LocalizedStringKey"/>.
        /// </summary>
        public LocalizedStringKey(string key)
        {
            if (key == null) throw new ArgumentNullException(nameof(key));
            Key = key;
        }

        public bool Equals(LocalizedStringKey other) => other != null
                                                     && Key == other.Key
                                                     && DisplayText == other.DisplayText;

        public override bool Equals(object obj) => Equals(obj as LocalizedStringKey);

        public override int GetHashCode() => Key != null ? Key.GetHashCode() : DisplayText.GetHashCode();

        public static bool operator ==(LocalizedStringKey first, LocalizedStringKey second)
        {
            if (ReferenceEquals(null, first)) return ReferenceEquals(null, second);
            if (ReferenceEquals(null, second)) return false;
            return first.Key == second.Key && first.DisplayText == second.DisplayText;
        }

        public static bool operator !=(LocalizedStringKey first, LocalizedStringKey second)
        {
            if (ReferenceEquals(null, first)) return !ReferenceEquals(null, second);
            if (ReferenceEquals(null, second)) return true;
            return first.Key != second.Key || first.DisplayText != second.DisplayText;
        }
    }
}
<commit_msg>Added LocalizedString class, to wrap localized strings which are updated on a language change.<commit_after>﻿/*********************************************************************************
 * LocalizedString.cs
 * 
 * Copyright (c) 2004-2018 <NAME>
 * 
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 * 
 *********************************************************************************/
using System;
using System.Diagnostics;

namespace Sandra.UI.WF
{
    /// <summary>
    /// Represents an immutable identifier for a <see cref="LocalizedString"/>.
    /// </summary>
    [DebuggerDisplay("{Key}")]
    public sealed class LocalizedStringKey : IEquatable<LocalizedStringKey>
    {
        /// <summary>
        /// Creates a <see cref="LocalizedStringKey"/> that serves as a placeholder key for strings that cannot be localized.
        /// </summary>
        public static LocalizedStringKey Unlocalizable(string displayText) => new LocalizedStringKey(null, displayText);

        /// <summary>
        /// Gets the string representation of this <see cref="LocalizedStringKey"/>. 
        /// </summary>
        internal readonly string Key;

        /// <summary>
        /// For untranslatable keys, returns the display text.
        /// </summary>
        internal readonly string DisplayText;

        private LocalizedStringKey(string key, string displayText)
        {
            if (displayText == null) throw new ArgumentNullException(nameof(displayText));
            Key = key;
            DisplayText = displayText;
        }

        /// <summary>
        /// Constructs a new instance of <see cref="LocalizedStringKey"/>.
        /// </summary>
        public LocalizedStringKey(string key)
        {
            if (key == null) throw new ArgumentNullException(nameof(key));
            Key = key;
        }

        public bool Equals(LocalizedStringKey other) => other != null
                                                     && Key == other.Key
                                                     && DisplayText == other.DisplayText;

        public override bool Equals(object obj) => Equals(obj as LocalizedStringKey);

        public override int GetHashCode() => Key != null ? Key.GetHashCode() : DisplayText.GetHashCode();

        public static bool operator ==(LocalizedStringKey first, LocalizedStringKey second)
        {
            if (ReferenceEquals(null, first)) return ReferenceEquals(null, second);
            if (ReferenceEquals(null, second)) return false;
            return first.Key == second.Key && first.DisplayText == second.DisplayText;
        }

        public static bool operator !=(LocalizedStringKey first, LocalizedStringKey second)
        {
            if (ReferenceEquals(null, first)) return !ReferenceEquals(null, second);
            if (ReferenceEquals(null, second)) return true;
            return first.Key != second.Key || first.DisplayText != second.DisplayText;
        }
    }

    /// <summary>
    /// Represents a localized string, which is updated on a change to <see cref="Localizer.Current"/>.
    /// </summary>
    public sealed class LocalizedString
    {
        /// <summary>
        /// Gets the key for this <see cref="LocalizedString"/>.
        /// </summary>
        public readonly LocalizedStringKey Key;

        /// <summary>
        /// Gets the current localized display text.
        /// </summary>
        public string DisplayText { get; private set; }

        public LocalizedString(LocalizedStringKey key)
        {
            if (key == null) throw new ArgumentNullException(nameof(key));

            Key = key;
            DisplayText = Localizer.Current.Localize(key);
        }
    }
}

{'fraction_non_alphanumeric': 0.13798064347371175, 'fraction_numerical': 0.0031388961548522104, 'mean_word_length': 2.362796833773087, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2640373', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1779, 'n_words': 610}