Wordpress插件本地化 [英] Wordpress Plugin Localization

查看:203
本文介绍了Wordpress插件本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为wp构建了我的第一个插件,即使它不是出色的代码诗";)也可以正常工作. 它是一个使用GalleryView 3.0 jquery插件( http://spaceforaname.com/galleryview 转换为默认wp画廊的插件. ).

i've just built my first plugin for wp, and even if it's not a great "code poetry" ;) it works as it should. It's a plugin that transform the default wp gallery using the GalleryView 3.0 jquery plugin (http://spaceforaname.com/galleryview).

我唯一不能做的就是本地化. 此插件的本地化意味着要翻译管理界面,有人可以在其中配置jquery插件选项以更改生成的库的外观.

The only thing i'm not able to do is localization. Localization for this plugin in means translating the admin interface, where someone can configure the jquery plugin options to change the aspect of the resulting gallery.

我试图遵循网络上数以百万计的教程,在论坛上阅读了很多有关此问题的文章,并遵循了法典的指导方针……但还是没有运气.

I've tried to follow the millions of tutorials present on the web, read a lot of posts about this issue on forums and followed the guidelinees of codex... but still with no luck.

这就是我所做的:

  1. 每行文本都在gettext函数(___e)内
  2. 使用poedit,我创建了.po和.mo文件,扫描了插件目录(一切正常),然后在该文件上添加了翻译.
  3. 我将.po文件命名为NAME-OF-THE-PLUGIN-it_IT.po(.mo文件以相同的名称生成)
  4. 我已将翻译文件放在插件文件夹/语言中(文件夹名称与插件和翻译文件相同)
  5. 然后我尝试在主插件文件中添加load_plugin_textdomain函数.我已尝试过,因为无法使其正常工作.
  1. every text line is inside a gettext function ( __ and _e )
  2. using poedit i created the .po and .mo file scanning the plugin directory (everythig went ok), then i added translations on that file.
  3. i named the .po file like that NAME-OF-THE-PLUGIN-it_IT.po (the .mo file was generated with the same name)
  4. i've put the translations files inside the plugin folder/languages (name of the folder is the same of the plugin and of the translations files)
  5. then i've tried to add the load_plugin_textdomain function inside the main plugin file. I've tried because there's no way to get it working.

我不确定的唯一事实是我创建的插件不在类+构造函数的作用下……只是因为我的编码还不太好.

The only thing on wich i'm not sure is the fact that the plugin i've created is not under a class+constructor funcions... just because i'm still not so good in coding.

但是我已经将load_plugin_textdomain放在了init add_action里面,像这样:

But i've put the load_plugin_textdomain inside an init add_action, like this:

add_action('init', 'gw_load_translation_file');

function gw_load_translation_file() {
// relative path to WP_PLUGIN_DIR where the translation files will sit:
$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
load_plugin_textdomain( 'gallery-view-for-wordpress', false, $plugin_path );
}

上面的几行不在逻辑之内,只是在主插件文件中.

the lines above are not inside a logic, they are just in the main plugin file, like that.

这是我使用gettext函数的一个示例:

this is an example of my use of gettext functions:

<h3><?php _e('Panel Options','gallery-view-for-wordpress') ?></h3>

我不明白什么?

推荐答案

我的错误在于语言文件路径声明.

My mistake was on language files path declaration.

此修复程序:

$plugin_path = dirname( plugin_basename( __FILE__ ) ) . '/languages/';

这是错误的:

$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );

我在 Wordpress Stack Exchange

这篇关于Wordpress插件本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆