<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>主题语言包相关文章列表 | 皇家元林</title>
	<atom:link href="https://hjyl.org/tags/%E4%B8%BB%E9%A2%98%E8%AF%AD%E8%A8%80%E5%8C%85/feed/" rel="self" type="application/rss+xml" />
	<link>https://hjyl.org</link>
	<description>刘元林的个人博客</description>
	<lastBuildDate>Wed, 13 Nov 2024 16:20:29 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://img.hjyl.org/uploads/2019/10/cropped-about-me-32x32.png</url>
	<title>主题语言包相关文章列表 | 皇家元林</title>
	<link>https://hjyl.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress6.7主题语言包失效(已解决)</title>
		<link>https://hjyl.org/wordpress67-languages-lost/</link>
					<comments>https://hjyl.org/wordpress67-languages-lost/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Wed, 13 Nov 2024 05:22:06 +0000</pubDate>
				<category><![CDATA[元林手札]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress6.7]]></category>
		<category><![CDATA[主题语言包]]></category>
		<guid isPermaLink="false">https://hjyl.org/?p=5476</guid>

					<description><![CDATA[刚更新到WordPress 6.7，发现自己主题的语言包失效了。我换了其他几个主题也是一样，我也没看到更新日志 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>刚更新到WordPress 6.7，发现自己主题的语言包失效了。我换了其他几个主题也是一样，我也没看到更新日志有关于语言包的更新啊。怎么回事？又出bug了？</p>



<hr class="wp-block-separator has-text-color has-luminous-vivid-orange-color has-alpha-channel-opacity has-luminous-vivid-orange-background-color has-background is-style-wide"/>



<p>根据<a href="https://hjyl.org/go/aHR0cHM6Ly93d3cudGpza3kubmV0" rel="nofollow" target="_blank">秋风于渭水</a>和<a href="https://hjyl.org/go/aHR0cHM6Ly9oNGNrLm9yZy5jbg==" rel="nofollow" target="_blank">obaby</a>在评论区的反馈，我也测试了其他主题，发现确实是部分主题的问题。正好<a href="https://hjyl.org/go/aHR0cHM6Ly93cHRlYS5jb20vd29yZHByZXNzLTYtNy1jaGluZXNlLXRyYW5zbGF0aW9uLW1pc3NpbmctZml4Lw==" rel="nofollow" target="_blank">WPTEA</a>也发现这样的问题，我以为也会帮到我，可没找到相关解决办法。</p>



<p>后来我发现，将load_theme_textdomain函数放在after_setup_theme外就能正常显示翻译，但是会提示“_load_textdomain_just_in_time 的调用方式不正确。 域的翻译加载触发得太早。翻译应该在 init 操作或之后加载.....”，所以这样做也不能解决问题，官方要求必须在init或after_setup_theme内。</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="876" height="387" src="https://img.hjyl.org/uploads/2024/11/wechat_2024-11-13_193628_611.png"  class="wp-image-5480" title="wechat_2024 11 13_193628_611.png" alt="wechat_2024 11 13_193628_611.png" /><figcaption class="wp-element-caption">load_theme_textdomain函数</figcaption></figure>



<p>经过三四个小时不断的测试，最终给我找到问题所在。所以这是主题的问题，而不是程序的问题。block-patterns.php和block-styles.php这是我借鉴WordPress默认的主题，因为提交官方主题库必须要有register_block_style和register_block_pattern的存在，即使对我来说一无是处。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>RECOMMENDED: No reference to register_block_style was found in the theme. Theme authors are encouraged to implement new block styles as a transition to block themes.<br>RECOMMENDED: No reference to register_block_pattern was found in the theme. Theme authors are encouraged to implement custom block patterns as a transition to block themes.</p>
</blockquote>



<p>然后我发现这两个位置，少了个符号“!”，因为按照逻辑来说，应该是如果没有什么什么，便注册什么什么。所以加上感叹号，问题就解决了。神奇吧！之前都没有验证过这个问题，却能正常显示。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="681" height="508" src="https://img.hjyl.org/uploads/2024/11/wechat_2024-11-13_205842_910.png"  class="wp-image-5479" title="wechat_2024 11 13_205842_910.png" alt="wechat_2024 11 13_205842_910.png" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity has-blush-bordeaux-gradient-background has-background is-style-wide"/>



<p>虽然上面没有错误提示，但经过<a href="https://hjyl.org/wordpress67-languages-lost/#comment-40452">ZWW</a>大佬一观，就发现问题所在了。其实我也想过，我抄的WordPress的主题代码，他们不至于犯这种错误啊。看到block-styles.php文件里，将这些函数放进init钩子，于是我照葫芦画个瓢，搞定。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="723" height="646" src="https://img.hjyl.org/uploads/2024/11/wechat_2024-11-13_232023_348.png"  class="wp-image-5485" title="wechat_2024 11 13_232023_348.png" alt="wechat_2024 11 13_232023_348.png" /></figure>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="WordPress6.7主题语言包失效(已解决)" href="https://hjyl.org/wordpress67-languages-lost/">WordPress6.7主题语言包失效(已解决)</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/wordpress67-languages-lost/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
	</channel>
</rss>
