admin管理员组文章数量:1287579
I'm pulling my hair out with this one:
I want to provide translations for my plugin, but they're not showing up. I followed the documentation and took the following steps:
- Set up local wordpress using docker
- Added Text Domain to Plugin-Info
* Text Domain: my-plugin
- Added Domain Path to Plugin-Info
* Domain Path: /languages/
- Added translation loading to
plugin.php
:
add_action( 'plugins_loaded', 'load_i18n' );
function load_i18n() {
load_plugin_textdomain("my-plugin", false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
}
I have a
settings.php
which is responsible for rendering my plugin's Settings page and is initialized fromplugin.php
. I added this line there to test my translation:<?php _e( 'Hello, dear user!', 'my-plugin' ); ?>
I used
wp i18n make-pot
to create the pot file. It successfully detects the line in settings and the plugin info stuff and creates what looks like a propermy-plugin.pot
inside my plugin'slanguage
directory.I used PoEdit to create translations from that pot file. I made
en_US.po
anden_US.mo
inside thelanguage
directory. I translated my test string in the settings page as well as the plugin description.Set Wordpress language to en_US via general settings. (I also tried
define ('WPLANG', 'en_US');
insidewp_config.php
)Installed my plugin.
Translations don't show up (original text is displayed), neither in the plugin description nor the settings page. I also tried other hooks for loading the text domain and other languages. The plugin is not going to be uploaded to the plugin repository, so the translations need to come with the plugin directly.
I'm pulling my hair out with this one:
I want to provide translations for my plugin, but they're not showing up. I followed the documentation and took the following steps:
- Set up local wordpress using docker
- Added Text Domain to Plugin-Info
* Text Domain: my-plugin
- Added Domain Path to Plugin-Info
* Domain Path: /languages/
- Added translation loading to
plugin.php
:
add_action( 'plugins_loaded', 'load_i18n' );
function load_i18n() {
load_plugin_textdomain("my-plugin", false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
}
I have a
settings.php
which is responsible for rendering my plugin's Settings page and is initialized fromplugin.php
. I added this line there to test my translation:<?php _e( 'Hello, dear user!', 'my-plugin' ); ?>
I used
wp i18n make-pot
to create the pot file. It successfully detects the line in settings and the plugin info stuff and creates what looks like a propermy-plugin.pot
inside my plugin'slanguage
directory.I used PoEdit to create translations from that pot file. I made
en_US.po
anden_US.mo
inside thelanguage
directory. I translated my test string in the settings page as well as the plugin description.Set Wordpress language to en_US via general settings. (I also tried
define ('WPLANG', 'en_US');
insidewp_config.php
)Installed my plugin.
Translations don't show up (original text is displayed), neither in the plugin description nor the settings page. I also tried other hooks for loading the text domain and other languages. The plugin is not going to be uploaded to the plugin repository, so the translations need to come with the plugin directly.
Share Improve this question asked Oct 5, 2021 at 12:37 MepsipaxMepsipax 111 bronze badge1 Answer
Reset to default 1So i found my own mistake:
I did not properly read https://developer.wordpress/plugins/internationalization/localization/#translate-the-po-file
My .mo
files were just called like en-US.mo
. But they should be called my-plugin-en-US.mo
.
Solved!
本文标签: Translations for my plugin don39t show up
版权声明:本文标题:Translations for my plugin don't show up 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741286233a2370285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论