<commit_before>using System;
using System.Globalization;
using System.Linq;
using System.Web;
using Orchard.Localization.Services;
using Orchard.Logging;

namespace Orchard.Localization {
    public class Text : IText {
        private readonly string _scope;
        private readonly ICultureManager _cultureManager;
        private readonly IResourceManager _resourceManager;

        public Text(string scope, ICultureManager cultureManager, IResourceManager resourceManager) {
            _scope = scope;
            _cultureManager = cultureManager;
            _resourceManager = resourceManager;
            Logger = NullLogger.Instance;
        }

        public ILogger Logger { get; set; }

        public LocalizedString Get(string textHint, params object[] args) {
            Logger.Debug("{0} localizing '{1}'", _scope, textHint);

            string currentCulture = _cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current));
            var localizedFormat = _resourceManager.GetLocalizedString(_scope, textHint, currentCulture);

            return args.Length == 0 
                ? new LocalizedString(localizedFormat, _scope, textHint, args)
                : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), _scope, textHint, args);
        }

        private static IFormatProvider GetFormatProvider(string currentCulture) {
            try {
                return CultureInfo.GetCultureInfoByIetfLanguageTag(currentCulture);
            }
            catch {
                return null;
            }
        }

        static object Encode(object arg) {
            if (arg is IFormattable || arg is IHtmlString) {<commit_msg>Corrected Localization bug in Commands<commit_after>using System;
using System.Globalization;
using System.Linq;
using System.Web;
using Orchard.Localization.Services;
using Orchard.Logging;

namespace Orchard.Localization {
    public class Text : IText {
        private readonly string _scope;
        private readonly ICultureManager _cultureManager;
        private readonly IResourceManager _resourceManager;

        public Text(string scope, ICultureManager cultureManager, IResourceManager resourceManager) {
            _scope = scope;
            _cultureManager = cultureManager;
            _resourceManager = resourceManager;
            Logger = NullLogger.Instance;
        }

        public ILogger Logger { get; set; }

        public LocalizedString Get(string textHint, params object[] args) {
            Logger.Debug("{0} localizing '{1}'", _scope, textHint);

            string currentCulture = HttpContext.Current == null ? _cultureManager.GetSiteCulture() : _cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current));
            var localizedFormat = _resourceManager.GetLocalizedString(_scope, textHint, currentCulture);

            return args.Length == 0 
                ? new LocalizedString(localizedFormat, _scope, textHint, args)
                : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), _scope, textHint, args);
        }

        private static IFormatProvider GetFormatProvider(string currentCulture) {
            try {
                return CultureInfo.GetCultureInfoByIetfLanguageTag(currentCulture);
            }
            catch {
                return null;
            }
        }

        static object Encode(object arg) {
            if (arg is IFormattable || arg is IHtmlString) {
{'fraction_non_alphanumeric': 0.0732662192393736, 'fraction_numerical': 0.0016778523489932886, 'mean_word_length': 2.7377220480668756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6697469', 'n_tokens_mistral': 884, 'n_tokens_neox': 843, 'n_words': 223}