Exemplo n.º 1
0
        private static void WriteCulture(string outputdir, string fileName, string extend, string global, CultureInfo culture, StringBuilder aggregateScript)
        {
            var globInfo = GlobalizationInfo.GetGlobInfo(culture);
            var diff     = (String.IsNullOrEmpty(extend) || culture == CultureInfo.InvariantCulture || culture.Name.Equals("en")) ? globInfo.ToDictionary(false) : GlobalizationInfo.DiffGlobInfos(GlobalizationInfo.BasisGlobInfo, globInfo.ToDictionary(true));
            var script   = GlobalizationInfo.GenerateJavaScript(extend, global, culture, culture.Name, diff, aggregateScript);
            var filePath = Path.Combine(outputdir, String.Format(fileName, (String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.Name)));

            File.WriteAllText(filePath, script);
            Console.WriteLine(filePath);
            // minimize
            var    minScript = minifier.MinifyJavaScript(script, codeSettings);
            string minPath   = Path.ChangeExtension(filePath, "min.js");

            File.WriteAllText(minPath, minScript);
            Console.WriteLine(minPath);
        }
Exemplo n.º 2
0
        private static void WriteCulture(string outputdir, string fileName, string extend, string global, CultureInfo culture, StringBuilder aggregateScript)
        {
            var globInfo = GlobalizationInfo.GetGlobInfo(culture);
            var diff     = (String.IsNullOrEmpty(extend) || culture == CultureInfo.InvariantCulture || culture.Name.Equals("en")) ? globInfo.ToDictionary(false) : GlobalizationInfo.DiffGlobInfos(GlobalizationInfo.BasisGlobInfo, globInfo.ToDictionary(true));

            // Fix for Issue #31 - en-US 'englishName' is wrong
            // Special case diff of englishName for en-US. The generator diff seemingly finds both "en" and "en-US" to
            // have englishName "English (United States)" but globalize.js (correctly) has the neutral "English" for "en"/"default"
            if (culture.Name.Equals("en-US"))
            {
                diff.Add("name", globInfo.name);
                diff.Add("englishName", globInfo.englishName);
            }

            var script   = GlobalizationInfo.GenerateJavaScript(extend, global, culture, culture.Name, diff, aggregateScript);
            var filePath = Path.Combine(outputdir, String.Format(fileName, (String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.Name)));

            File.WriteAllText(filePath, script);
            Console.WriteLine(filePath);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string outputdir         = "lib\\cultures";
            string extend            = "extend";
            string global            = "Globalization";
            string fileName          = "globalize.culture.{0}.js";
            string aggregateFileName = "globalize.cultures.js";

            foreach (string param in string.Join(" ", args).SplitCommandLine())
            {
                if (param.StartsWith("/o:"))
                {
                    outputdir = param.Substring("/o:".Length);
                }
                else if (param == "/?")
                {
                    Console.Write(@"
Usage:glob-generator [<options>]

options:

    /o: The directory to put the culture scripts into. The directory will be
        created if it does not exist. Existing scripts there will be
        overwritten if necessary.
        default: ""lib\cultures""

");
                    return;
                }
            }
            Directory.CreateDirectory(outputdir);
            GlobalizationInfo.BasisGlobInfo = GlobalizationInfo.GetGlobInfo(CultureInfo.CreateSpecificCulture("en")).ToDictionary(false);

            StringBuilder aggregateScript = new StringBuilder();

/*
 *
 * Globalize.addCultureInfo( ""{0}"", ""default"", {{
 * {1}
 * }});
 *
 * }}( this ));
 * "
 */

            aggregateScript.Append(
                @"/*
 * Globalize Cultures
 *
 * http://github.com/jquery/globalize
 *
 * Copyright Software Freedom Conservancy, Inc.
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * This file was generated by the Globalize Culture Generator
 * Translation: bugs found in this file need to be fixed in the generator
 */

(function( window, undefined ) {

var Globalize;

if ( typeof require !== ""undefined""
	&& typeof exports !== ""undefined""
	&& typeof module !== ""undefined"" ) {
	// Assume CommonJS
	Globalize = require( ""globalize"" );
} else {
	// Global variable
	Globalize = window.Globalize;
}
");

            int count = 0;

            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                if (!String.IsNullOrEmpty(culture.Name) && culture != CultureInfo.InvariantCulture && culture.Name != "en")
                {
                    WriteCulture(outputdir, fileName, extend, global, culture, aggregateScript);
                    count++;
                }
            }

            aggregateScript.Append("\r\n}( this ));\r\n");
            string aggregateScriptString = aggregateScript.ToString();
            string aggregatePath         = Path.Combine(outputdir, aggregateFileName);

            File.WriteAllText(aggregatePath, aggregateScriptString);
            Console.WriteLine(aggregatePath);

            Console.WriteLine("Done! Generated scripts for a total of {0} cultures, and 1 aggregate script.", count);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string outputdir = "output";
            string extend    = "extend";
            string global    = "Globalization";
            string fileName  = "Globalization.{0}.js";

            foreach (string param in string.Join(" ", args).SplitCommandLine())
            {
                if (param.StartsWith("/o:"))
                {
                    outputdir = param.Substring("/o:".Length);
                }
                else if (param.StartsWith("/e:"))
                {
                    extend = param.Substring("/e:".Length);
                }
                else if (param.StartsWith("/g:"))
                {
                    global = param.Substring("/g:".Length);
                }
                else if (param.StartsWith("/n:"))
                {
                    fileName = param.Substring("/n:".Length);
                }
                else if (param == "/?")
                {
                    Console.Write(@"
Usage:glob-generator [<options>]

options:

    /o: The directory to put the glob scripts into. The directory will be
        created if it does not exist. Existing scripts there will be
        overwritten if necessary.
        default: 'output'
    /e: Name of the 'extend' function on the given global. This is used
        so that each globalization file extends the standard one,
        reducing the amount of data in each. Set it to empty to disable
        this feature, and each script will have the full set of data.
        default: 'extend'
    /g: The name of the global to add cultures to.
        default: 'Globalization'
    /n: File name format. {0} is replaced with the culture key. The
        extension is changed to 'min.js' for the minified version.
        default: 'Globalization.{0}.js

");
                    return;
                }
            }
            Directory.CreateDirectory(outputdir);
            GlobalizationInfo.BasisGlobInfo = GlobalizationInfo.GetGlobInfo(CultureInfo.CreateSpecificCulture("en")).ToDictionary(false);

            StringBuilder aggregateScript = new StringBuilder();

            if (!String.IsNullOrEmpty(extend))
            {
                aggregateScript.Append(
                    @"(function($) {
    var culture, cultures = $.cultures,
    en = cultures.en,
    standard = en.calendars.standard;

");
            }
            else
            {
                aggregateScript.Append(
                    @"(function($) {
    var cultures = $.cultures;

");
            }

            int count = 0;

            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                if (!String.IsNullOrEmpty(culture.Name) && culture != CultureInfo.InvariantCulture && culture.Name != "en")
                {
                    WriteCulture(outputdir, fileName, extend, global, culture, aggregateScript);
                    count++;
                }
            }

            aggregateScript.Append("\r\n\r\n})(").Append(global).Append(");");
            string aggregateScriptString = aggregateScript.ToString();
            string aggregatePath         = Path.Combine(outputdir, String.Format(fileName, "all"));

            File.WriteAllText(aggregatePath, aggregateScriptString);
            Console.WriteLine(aggregatePath);
            // minimize
            var    minScript = minifier.MinifyJavaScript(aggregateScriptString, codeSettings);
            string minPath   = Path.ChangeExtension(aggregatePath, "min.js");

            File.WriteAllText(minPath, minScript);
            Console.WriteLine(minPath);


            Console.WriteLine("Done! Generated scripts for a total of {0} cultures, and 1 aggregate script.", count);
        }