Beispiel #1
0
    public void Run()
    {
        List <Dictionary <string, string> > dataList = new List <Dictionary <string, string> >();

        string content = File.ReadAllText(Setting.Options.TextCodeTS);
        string pattern = "static[ \t]*(.*)[ \t]*=[ \t]*\"(.*)\"[ \t]*;";
        int    id      = 1;

        foreach (Match match in Regex.Matches(content, pattern))
        {
            string key   = match.Groups[1].ToString().Trim();
            string value = match.Groups[2].ToString().Trim();
            Dictionary <string, string> dict = new Dictionary <string, string>();
            dict.Add("id", id.ToString());
            dict.Add("key", key);
            dict.Add("zh_cn_value", value);
            dataList.Add(dict);
            id++;
        }

        List <DataField> fields = new List <DataField>();
        DataField        field  = new DataField();

        field.typeName = "int";
        field.cn       = "ID";
        field.field    = "id";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "Key";
        field.field    = "key";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "值";
        field.field    = "zh_cn_value";
        fields.Add(field);


        LangTableData langTableData = new LangTableData();

        langTableData.langPath = Setting.Options.TextCodeXlsx;
        langTableData.idKey    = "key";
        langTableData.ReaderLangTable();
        langTableData.SetFields(fields);
        langTableData.SetDataList(dataList);
        langTableData.Sort("id");
        langTableData.ResetGenerateID();
        langTableData.Save();
    }
Beispiel #2
0
    public void Generate()
    {
        foreach (var kvp in xlsxManager.tables)
        {
            TableReader table = kvp.Value;

            if (!table.hasLangField)
            {
                continue;
            }


            string        langPath      = Setting.Options.langDir + "/editor/" + table.tableName + ".xlsx";
            LangTableData langTableData = new LangTableData();
            langTableData.langPath = langPath;
            langTableData.ReaderLangTable();
            langTableData.SetFields(table.dataStruct.fields);
            langTableData.SetDataList(table.dataList);
            langTableData.Sort("id");
            langTableData.Save();
        }
    }
    public void Generate()
    {
        foreach (var kvp in xlsxManager.tables)
        {
            TableReader table = kvp.Value;

            Dictionary <string, DataField> fieldDict = new Dictionary <string, DataField>();

            foreach (DataField field in table.dataStruct.fields)
            {
                bool   isLangField = false;
                string fieldName   = field.field;
                foreach (string langFieldPrefix in Setting.Options.langFieldPrefixs)
                {
                    if (fieldName.StartsWith(langFieldPrefix))
                    {
                        fieldName   = fieldName.Replace(langFieldPrefix, string.Empty);
                        isLangField = true;
                        break;
                    }
                }


                if (!fieldDict.ContainsKey(fieldName))
                {
                    DataField item = field.Clone();
                    item.field       = fieldName;
                    item.isLangField = isLangField;
                    fieldDict.Add(fieldName, item);
                }
            }


            List <DataField> fieldList = new List <DataField>(fieldDict.Values);
            foreach (string lang in Setting.Options.langs)
            {
                string langFieldPrefix = lang.Replace("-", "_");
                List <Dictionary <string, string> > dataList = new List <Dictionary <string, string> >();
                foreach (Dictionary <string, string> line in table.dataList)
                {
                    Dictionary <string, string> langLine = new Dictionary <string, string>();
                    foreach (DataField field in fieldList)
                    {
                        string value = string.Empty;
                        string key   = field.field;

                        if (!line.ContainsKey(key))
                        {
                            key = langFieldPrefix + "_" + field.field;
                            if (!line.ContainsKey(key))
                            {
                                key = "cn_" + field.field;
                            }
                        }

                        if (line.ContainsKey(key))
                        {
                            value = line[key];
                        }

                        langLine.Add(field.field, value);
                    }
                    dataList.Add(langLine);
                }


                string        langPath      = Setting.Options.langDir + "/" + lang + "/" + table.tableName + ".xlsx";
                LangTableData langTableData = new LangTableData();
                langTableData.langPath = langPath;
                langTableData.SetFields(fieldList);
                langTableData.SetDataList(dataList);
                langTableData.Save();
            }
        }
    }
Beispiel #4
0
    public void Run()
    {
        List <Dictionary <string, string> > dataList = new List <Dictionary <string, string> >();


        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.Load(Setting.Options.TextFguiXml);


        XmlNode resources = xmlDocument.SelectSingleNode(@"resources");

        XmlNodeList xmlNodeList = resources.ChildNodes;

        int    id      = 1;
        string comment = string.Empty;

        foreach (XmlNode node in xmlNodeList)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Comment:
                comment = node.InnerText.Trim();
                Console.WriteLine(comment);
                break;

            case XmlNodeType.Element:
                string name  = node.Attributes.GetNamedItem("name").InnerText;
                string mz    = node.Attributes.GetNamedItem("mz").InnerText;
                string value = node.InnerText.Trim();
                Console.WriteLine($"name={name}, mz={mz}, value={value}");

                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict.Add("id", id.ToString());
                dict.Add("comment", comment);
                dict.Add("name", name);
                dict.Add("mz", mz);
                dict.Add("zh_cn_value", value);
                dataList.Add(dict);
                id++;
                break;
            }
        }


        List <DataField> fields = new List <DataField>();
        DataField        field  = new DataField();

        field.typeName = "int";
        field.cn       = "ID";
        field.field    = "id";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "备注";
        field.field    = "comment";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "UI编号";
        field.field    = "name";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "UI元件名称";
        field.field    = "mz";
        fields.Add(field);

        field          = new DataField();
        field.typeName = "string";
        field.cn       = "值";
        field.field    = "zh_cn_value";
        fields.Add(field);


        LangTableData langTableData = new LangTableData();

        langTableData.langPath = Setting.Options.TextFguiXlsx;
        langTableData.idKey    = "name";
        langTableData.ReaderLangTable();
        langTableData.SetFields(fields);
        langTableData.SetDataList(dataList);
        langTableData.Sort("id");
        langTableData.ResetGenerateID();
        langTableData.Save();
    }