<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNet.Http;
using Newtonsoft.Json;
using CodeComb.AspNet.Localization;

namespace Microsoft.AspNet.Builder
{
    public static class LocalizationScriptMiddleware
    {
        public static IApplicationBuilder UseCodeCombLocalization(this IApplicationBuilder self, string scriptUrl = "/scripts/localization.js")
        {
            var SR = self.ApplicationServices.GetService<ILocalizationStringCollection>();
            var CultureProvider = self.ApplicationServices.GetService<IRequestCultureProvider>();
            var culture = SR.Collection.Where(x => x.Cultures.Contains(SR.SingleCulture(CultureProvider.DetermineRequestCulture()))).First();
            var json = JsonConvert.SerializeObject(culture.LocalizedStrings);
            return self.Map(scriptUrl, config => 
            {
                var js = new StringBuilder("var __dictionary = {};");
                config.Run(async context => 
                {
                    js.AppendLine("__dictionary = " + json + ";");
                    js.AppendLine(@"
var __ = {};
__.c = __c;

function __replaceAll(str0, str1, str2)
{
	return str0.replace(new RegExp(str1, 'gm'), str2);
}

function __c(key, params)
{
	if (!params)
		return __dictionary[key] || key;
	else
	{
		var ret = __dictionary[key] || key;
		for (var i = 0; i < params.length; i++)
			ret = __replaceAll(ret, '\\{' + i + '\\}', params[i]);<commit_msg>rename<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNet.Http;
using Newtonsoft.Json;
using CodeComb.AspNet.Localization;

namespace Microsoft.AspNet.Builder
{
    public static class LocalizationScriptMiddleware
    {
        public static IApplicationBuilder UseJavascriptLocalization(this IApplicationBuilder self, string scriptUrl = "/scripts/localization.js")
        {
            var SR = self.ApplicationServices.GetService<ILocalizationStringCollection>();
            var CultureProvider = self.ApplicationServices.GetService<IRequestCultureProvider>();
            var culture = SR.Collection.Where(x => x.Cultures.Contains(SR.SingleCulture(CultureProvider.DetermineRequestCulture()))).First();
            var json = JsonConvert.SerializeObject(culture.LocalizedStrings);
            return self.Map(scriptUrl, config => 
            {
                var js = new StringBuilder("var __dictionary = {};");
                config.Run(async context => 
                {
                    js.AppendLine("__dictionary = " + json + ";");
                    js.AppendLine(@"
function __replaceAll(str0, str1, str2)
{
	return str0.replace(new RegExp(str1, 'gm'), str2);
}

function SR(key, params)
{
	if (!params)
		return __dictionary[key] || key;
	else
	{
		var ret = __dictionary[key] || key;
		for (var i = 0; i < params.length; i++)
			ret = __replaceAll(ret, '\\{' + i + '\\}', params[i]);
{'fraction_non_alphanumeric': 0.11935073201782304, 'fraction_numerical': 0.004455760661998727, 'mean_word_length': 3.21313672922252, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3230690', 'n_tokens_mistral': 884, 'n_tokens_neox': 857, 'n_words': 186}