<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>GLgele&apos;s Blog</title>
    <description>这是我的博客</description>
    <link>http://glgele.github.io/</link>
    <atom:link href="http://glgele.github.io/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Sat, 15 Feb 2025 22:27:17 +0800</pubDate>
    <lastBuildDate>Sat, 15 Feb 2025 22:27:17 +0800</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>C#-winform控件多语言-json</title>
        <description>&lt;h1 id=&quot;问题描述&quot;&gt;问题描述&lt;/h1&gt;
&lt;p&gt;通过json实现winform窗体控件多语言&lt;/p&gt;

&lt;h1 id=&quot;需要用到&quot;&gt;需要用到&lt;/h1&gt;
&lt;p&gt;Newtonsoft.Json&lt;/p&gt;

&lt;h1 id=&quot;思路&quot;&gt;思路&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;解析json&lt;/li&gt;
  &lt;li&gt;遍历控件，修改text&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;解决方案&quot;&gt;解决方案&lt;/h1&gt;
&lt;p&gt;先对json进行解析&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        private static string lang;
        private string source;
        private StreamReader file;
        private Dictionary&amp;lt;string, string&amp;gt; dict = new Dictionary&amp;lt;string, string&amp;gt;();
        public trans()
        {
            lang = IniReadValue(iniFilePath, &quot;Language&quot;, &quot;lang&quot;);
            logger.DebugFormat(&quot;Language:{0}&quot;, lang);
            try
            {
                file = new StreamReader(new FileStream(&quot;lang/&quot; + lang + &quot;.json&quot;, FileMode.Open, FileAccess.Read, FileShare.Read));
            }
            catch (IOException)
            {
                file = new StreamReader(new FileStream(&quot;lang/en_us.json&quot;, FileMode.Open, FileAccess.Read, FileShare.Read));
                General.logger.Error(&quot;Can&apos;t find settings.ini!&quot;);
            }
            catch (Exception)
            {
                General.logger.Fatal(&quot;Can&apos;t load language file!&quot;);
                ErrorForm form = new ErrorForm(&quot;Can&apos;t load language file!&quot;);
            }
            source = file.ReadToEnd();
            file.Close();
            source = source.Replace(&quot;\r&quot;, &quot;&quot;).Replace(&quot;\n&quot;, &quot;&quot;).Replace(&quot;\t&quot;, &quot;&quot;);
            //source = file.ToString();
            JsonTextReader reader = new JsonTextReader(new StringReader(source));
            string tmp1 = &quot;&quot;;
            string tmp2 = &quot;&quot;;
            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    //Console.WriteLine(&quot;Token: {0}, Value: {1}&quot;, reader.TokenType, reader.Value);
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        tmp1 = reader.Value.ToString();
                    }
                    else if (reader.TokenType == JsonToken.String)
                    {
                        tmp2 = reader.Value.ToString();
                        dict[tmp1] = tmp2;
                        tmp1 = &quot;&quot;;
                        tmp2 = &quot;&quot;;
                    }
                }
                else
                {
                    //Console.WriteLine(&quot;Token: {0}&quot;, reader.TokenType);
                }
            }
        }
        ~trans()
        {
            file.Dispose();
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;做一个return&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        public string tr(string s)
        {
            try
            {
                return dict[s];
            }
            catch (Exception)
            {
                General.logger.WarnFormat(&quot;Translate string not found! Source:({0})&quot;, s);
                return s;
            }
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;最后写一个函数对form的控件进行遍历&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        public void Init(Form form)
        {
            foreach (Control control in form.Controls)
            {
                try
                {
                    control.Text = tr(&quot;Form.Control&quot;.Replace(&quot;Form&quot;, form.Name).Replace(&quot;Control&quot;, control.Name));
                }
                catch (Exception)
                {
                    //Actually we do nothing if we catch an exception.
                }
            }
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 14 Jun 2022 00:00:00 +0800</pubDate>
        <link>http://glgele.github.io/blog/2022/06/14/cs-window-lang-json/</link>
        <guid isPermaLink="true">http://glgele.github.io/blog/2022/06/14/cs-window-lang-json/</guid>
        
        <category>C#</category>
        
        <category>.net</category>
        
        <category>json</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>MC1.12目标选择器-scores</title>
        <description>&lt;h1 id=&quot;问题描述&quot;&gt;问题描述&lt;/h1&gt;
&lt;p&gt;在1.13+中，可以用选择器参数&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[scores={foo=0..3}] &lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;execute if scores&lt;/code&gt;来检测记分板分数达到一定量的玩家
但在1.12中，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scores=&lt;/code&gt;会被认定为无效的选择器参数&lt;/p&gt;

&lt;h1 id=&quot;解决方案&quot;&gt;解决方案&lt;/h1&gt;
&lt;p&gt;在1.12中，记分板分数的目标选择器参数格式是：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;score_记分板名称&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;score_记分板名称_min&lt;/code&gt;&lt;/p&gt;
</description>
        <pubDate>Tue, 14 Jun 2022 00:00:00 +0800</pubDate>
        <link>http://glgele.github.io/blog/2022/06/14/mc1.12-target-selector/</link>
        <guid isPermaLink="true">http://glgele.github.io/blog/2022/06/14/mc1.12-target-selector/</guid>
        
        <category>Minecraft</category>
        
        <category>命令</category>
        
        <category>1.8-1.12</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Gitalk Update</title>
        <description>&lt;p&gt;添加了Gitalk作为评论模块&lt;/p&gt;
</description>
        <pubDate>Sun, 03 Apr 2022 00:00:00 +0800</pubDate>
        <link>http://glgele.github.io/blog/2022/04/03/blog-update/</link>
        <guid isPermaLink="true">http://glgele.github.io/blog/2022/04/03/blog-update/</guid>
        
        <category>开发日志</category>
        
        <category>Blog</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>这是一篇博客文章模板</title>
        <description>&lt;p&gt;这里是博客正文。&lt;/p&gt;

</description>
        <pubDate>Mon, 02 Mar 2015 00:00:00 +0800</pubDate>
        <link>http://glgele.github.io/blog/2015/03/02/how-to-write/</link>
        <guid isPermaLink="true">http://glgele.github.io/blog/2015/03/02/how-to-write/</guid>
        
        <category>标签一</category>
        
        <category>标签二</category>
        
        
        <category>blog</category>
        
      </item>
    
  </channel>
</rss>
