yoast / i18n-module
此包已被 废弃 并不再维护。未建议替代包。
处理WordPress插件的i18n。
3.1.1
2019-05-07 06:45 UTC
Requires
- php: >=5.2
Requires (Dev)
- roave/security-advisories: dev-master
- yoast/yoastcs: ^1.2.2
README
⚠️ 更新于2023年9月28日 ⚠️
我们已停止此项目开发。如果您对此模块感兴趣,我们很乐意向您推荐由 @mte90 在 https://github.com/WPBP/i18n-notice 维护的优质分支。
Yoast i18n模块
推广您的翻译网站,以便使用您插件的其他语言(非 en_US
)的用户。
渲染推广框的示例
图像、您的插件名称以及您的翻译项目名称均可配置(见下例)。语言名称从您的GlotPress安装中检索,翻译百分比也是如此。当语言的翻译达到90%或更多时,此框不会显示。
如何使用此模块
使用composer将其包含在您的项目中
composer require yoast/i18n-module
或者,您可以将库作为子模块包含。确保类被加载,并按如下方式实例化
new Yoast_I18n_v3( array( 'textdomain' => '{your text domain}', 'project_slug' => '{your probject slug}', 'plugin_name' => '{your plugin name}', 'hook' => '{the hook to display the message box on}', 'glotpress_url' => '{url to your glotpress installation; http://translate.yoast.com}', 'glotpress_name' => '{name of your glotpress installation}', 'glotpress_logo' => '{url to a logo which will be shown}', 'register_url ' => '{url to use when registering for a project}', ) );
如果您使用的服务不遵循GlotPress的URL约定,您可能需要直接传递完整的 api_url
以获取可用翻译列表,而不是让类从 glotpress_url
构建它
new Yoast_I18n_v3( array( 'textdomain' => '{your text domain}', 'project_slug' => '{your probject slug}', 'plugin_name' => '{your plugin name}', 'hook' => '{the hook to display the message box on}', 'api_url' => '{url the JSON list of the available languages}', 'glotpress_name' => '{name of your glotpress installation}', 'glotpress_logo' => '{url to a logo which will be shown}', 'register_url ' => '{url to use when registering for a project}', ) );
因为translate.wordpress.org也是一个GlotPress安装,您可以使用i18n-module在该网站上推广您的插件翻译。为此,您可以使用专门的wordpress.org类
new Yoast_I18n_WordPressOrg_v3( array( 'textdomain' => '{your text domain}', 'plugin_name' => '{your plugin name}', 'hook' => '{hook to display the message box on}', ) );
自定义显示消息的位置和时间
从3.0.0版本开始,您还可以决定在您自己的消息框中渲染消息。只需将构造函数的第二个参数作为 false
提供即可禁用模块本身显示框。
$i18n_module = new Yoast_I18n_v3( array( 'textdomain' => '{your text domain}', 'project_slug' => '{your probject slug}', 'plugin_name' => '{your plugin name}', 'hook' => '{the hook to display the message on - not used in this example}', 'glotpress_url' => '{url to your glotpress installation; http://translate.yoast.com}', 'glotpress_name' => '{name of your glotpress installation}', 'glotpress_logo' => '{url to a logo which will be shown}', 'register_url ' => '{url to use when registering for a project}', ), false ); $message = $i18n_module->get_promo_message();
$i18n_module = new Yoast_I18n_WordPressOrg_v3( array( 'textdomain' => '{your text domain}', 'plugin_name' => '{your plugin name}', 'hook' => '{hook to display the message on - not used in this example}', ), false ); $message = $i18n_module->get_promo_message();