Ejemplo n.º 1
0
    public static void RefreshOldVersionInfo()
    {
        var Items = new Dictionary <string, LangMatrixRow>();

        //SqlServerReg.Parse(Items, LangsDesignDirs.other + "sqlserver.reg", LangsDesignDirs.other + "sqlserver-clsids.reg");
        //SqlServerQuery.Parse(Items, LangsDesignDirs.other + "sqlserver.query");
        //ByHand.Parse(Items, LangsDesignDirs.other + "by-hand.xml");
        GoogleTrans.Parse(Items);
        //SpellCheck.Parse(Items);
        foreach (var kv in Items)
        {
            var ci   = CultureInfo.GetCultureInfo(kv.Value.lang);
            var lcid = ci.LCID;
            if (lcid != 4096)
            {
                kv.Value.row[6] = lcid.ToString();
            }
            kv.Value.row[9] = ci.EnglishName;
        }
        var fullText = new LangMatrix(
            Items.Select(kv => kv.Value)
            );

        fullText.save(LangsDesignDirs.otherappdata + "oldVersionInfo.csv");

        var wrongs = LangMatrix.readLangs(LangsDesignDirs.otherappdata + "oldVersionInfo.csv").Where(l => !Langs.nameToMeta.ContainsKey(l)).ToArray();

        if (wrongs.Length > 1) // "", LCID 127
        {
            throw new Exception();
        }
    }
Ejemplo n.º 2
0
    public static void Build()
    {
        var cldr  = Json.Deserialize <Langs.CldrLang[]>(LangsDirs.dirCldrTexts);
        var roots = cldr.SelectMany(c => c.Regions.Select(r => LocaleIdentifier.Parse(string.Format("{0}-{1}-{2}", c.Lang, c.ScriptId, r)))).ToArray();
        var locs  = roots.Select(root => new Locale(root)).ToArray();

        // ALPHABETS
        var rx     = new Regex("[{} ]");
        var alphas = locs.Select(loc => {
            var localePattern = loc.Find("//characters");
            var data          = localePattern.SelectChildren(XPathNodeType.Element).OfType <XPathNavigator>().Where(al => al.Name == "exemplarCharacters").Select(al => {
                var value   = CldrUtils.decodeUnicodeLiteral(al.Value.Normalize().Trim('[', ']'));
                value       = rx.Replace(value, "");
                var keyNode = al.SelectSingleNode("./@type");
                var key     = keyNode == null ? "root" : keyNode.Value;
                //if (key == "numbers" || key == "punctuation" || string.IsNullOrEmpty(value)) return null;
                return(new { key, value });
            }).Where(n => n != null).ToArray();
            return(new {
                lang = loc.Id.ToString(),
                data
            });
        }).Where(d => d.data.Length > 0).OrderBy(l => l.lang).ToArray();

        Func <string, IEnumerable <LangMatrixRow> > alphasRes = (string key) => alphas.SelectMany(a => a.data.Where(aa => aa.key == key).Select(aa =>
                                                                                                                                                new LangMatrixRow {
            lang = a.lang, columnNames = Linq.Items(aa.key).ToArray(), row = Linq.Items(aa.value).ToArray()
        }));
        var alphaRoot        = new LangMatrix(alphasRes("root"), null, true);
        var alphaAuxlity     = new LangMatrix(alphasRes("auxiliary"), null, true);
        var alphaIndex       = new LangMatrix(alphasRes("index"), null, true);
        var alphaNumbers     = new LangMatrix(alphasRes("numbers"), null, true);
        var alphaPunctuation = new LangMatrix(alphasRes("punctuation"), null, true);

        var patterns = new LangMatrix(locs.Select(loc => {
            var localePattern   = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localePattern").ToString();
            var localeSeparator = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localeSeparator").ToString();
            return(new LangMatrixRow {
                lang = loc.Id.ToString(),
                row = new string[] { localePattern, localeSeparator },
                columnNames = new string[] { "pattern", "separator" },
            });
        }), null, true);
        Dictionary <string, Dictionary <string, string> > langsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var langs = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/languages")),
            langsProtocol, true
            );
        Dictionary <string, Dictionary <string, string> > scriptsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var scripts = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/scripts")),
            scriptsProtocol, true
            );
        Dictionary <string, Dictionary <string, string> > regionsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var regions = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/territories")),
            regionsProtocol, true
            );

        langs.save(LangsDesignDirs.cldr + "cldrNameLangs.csv", true);
        scripts.save(LangsDesignDirs.cldr + "cldrNameScripts.csv", true);
        regions.save(LangsDesignDirs.cldr + "cldrNameRegions.csv", true);
        patterns.save(LangsDesignDirs.cldr + "cldrNamePatterns.csv", true);
        alphaRoot.save(LangsDesignDirs.cldr + "alphaRoot.csv", true);
        alphaAuxlity.save(LangsDesignDirs.cldr + "alphaAuxlity.csv", true);
        alphaIndex.save(LangsDesignDirs.cldr + "alphaIndex.csv", true);
        alphaNumbers.save(LangsDesignDirs.cldr + "alphaNumbers.csv", true);
        alphaPunctuation.save(LangsDesignDirs.cldr + "alphaPunctuation.csv", true);

        // save to DART messages
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameLangs.msg", Protobuf.ToBytes(matrixToDart(langs)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameScripts.msg", Protobuf.ToBytes(matrixToDart(scripts)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameRegions.msg", Protobuf.ToBytes(matrixToDart(regions)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNamePatterns.msg", Protobuf.ToBytes(matrixToDart(patterns)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaRoot.msg", Protobuf.ToBytes(matrixToDart(alphaRoot)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaAuxlity.msg", Protobuf.ToBytes(matrixToDart(alphaAuxlity)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaIndex.msg", Protobuf.ToBytes(matrixToDart(alphaIndex)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaNumbers.msg", Protobuf.ToBytes(matrixToDart(alphaNumbers)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaPunctuation.msg", Protobuf.ToBytes(matrixToDart(alphaPunctuation)));

        //  var localePattern = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localePattern").ToString();
        //  var localeSeparator = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localeSeparator").ToString();
        //  fromCldr(loc, "//localeDisplayNames/languages");
        //  fromCldr(loc, "//localeDisplayNames/scripts");
        //  fromCldr(loc, "//localeDisplayNames/territories");
        //});
    }