如何本地化联系表单 7 中的字段标签
我已成功将我的客户网站从西班牙语本地化为法语:
http://www.microcementoeuropeo.com
...使用 WPML 插件和 Gettext 框架的组合。我唯一翻译不成功的是联系表格本身的标签:
<p>Nombre<br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" class="wpcf7-text wpcf7-validates-as-required" size="40" /></span> </p>
<p>Email<br />
<span class="wpcf7-form-control-wrap your-email"><input type="text" name="your-email" value="" class="wpcf7-text wpcf7-validates-as-email wpcf7-validates-as-required" size="40" /></span> </p>
<p>Teléfono<br />
...所以我试图翻译的文本将是“Nombre” - 法语。
我尝试过适用于其他硬编码区域的 gettext 方法:
<p><?php _e('Nombre', theme_domain);?><br />
<p><?php __('Nombre', theme_domain);?><br />
...但这不起作用。
(我通过 admin 将这些添加到 WordPress 中,而不是直接添加到 .php 文件中)。
我熟悉创建 .po / .mo 文件,并且知道如何本地化普通的硬编码文本 - 但联系表单 7 让我感到困惑。
任何建议表示赞赏。
I have managed to localize my clients site from Spanish to French:
http://www.microcementoeuropeo.com
...using a combination of the WPML plugin and the Gettext framework. The only thing i have been unsuccessful translating are the labels on the contact form itslef:
<p>Nombre<br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" class="wpcf7-text wpcf7-validates-as-required" size="40" /></span> </p>
<p>Email<br />
<span class="wpcf7-form-control-wrap your-email"><input type="text" name="your-email" value="" class="wpcf7-text wpcf7-validates-as-email wpcf7-validates-as-required" size="40" /></span> </p>
<p>Teléfono<br />
...so the text i'm trying to translate would be "Nombre" - to the French.
I've tried the gettext methods that worked for other hard-coded areas:
<p><?php _e('Nombre', theme_domain);?><br />
<p><?php __('Nombre', theme_domain);?><br />
...but this does not work.
(i´m adding these into wordpress through admin and not directly to the .php file).
I'm familiar with creating .po / .mo files and know how to localize normal hard-coded text - but contact form 7 has me baffled.
Any suggestions appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您的问题的解决方案在于能够在 Contact Form 7 模板中运行 PHP。您可以通过编写自己的短代码然后将其添加到 CF7 中来完成此操作。
首先,设置一个短代码,以便您的翻译功能在 WP 内容区域中可用。像这样的东西:(
免责声明:我还没有测试过这个!)
然后你可以使用 像这样的插件,这样您就可以将短代码添加到 CF7 模板区域。使用此插件,您必须定义要用作“键”的代码,例如:
然后您应该能够在 CF7 表单模板和电子邮件模板中使用 e_text 短代码。
I think the solution to your problem lies in the ability to run PHP within the Contact Form 7 template. You can do this by writing your own shortcode and then adding this into CF7.
Firstly, setup a shortcode so your translation functions are available within WP content areas. Something like:
(disclaimer: I haven't tested this!)
Then you can use a plugin like this one so you can add shortcodes to the CF7 template area. With this plugin you have to define the codes you want to use as 'keys', something like:
Then you should be able to use e_text shortcode in the CF7 form template and email templates.
感谢您的建议 JunkMyFunk。我尝试实现这一点,但遇到了一些问题。
我最终使用以下方法找到了解决方法:
使用以下条件语句显示每种语言的正确联系表单。
仍然感谢您的帮助 -
Thanks for the suggestion JunkMyFunk. I tried to implement this but ran into some issues.
I eventually found a workaround using the following method:
Use the following conditional statement to show the correct contact form for each language.
Thanks for your help all the same -
这不起作用的原因是因为从 v4.4.1 开始,CF7 插件 不包括语言 语言环境不再存在,这些在 worpdress 翻译中维护 GlotPress< /a> 反而。因此,您需要手动安装区域设置,针对您要为其创建表单的每种语言安装一个区域设置。然后,您可以通过在仪表板网址中添加
locale
属性来创建新语言的表单,例如对于德语区域设置 de_DE,http://<您的域名>/wp-admin/admin.php?page=wpcf7-new&locale=de_DE
或者,您可以使用 CF7 PolyLang 模块,它允许您管理 CF7 表单使用 PolyLang 插件 (WP 推荐)。 PolyLang 是 WPML 的替代品,
The reason why this does not work is because as of v4.4.1 the CF7 plugin does not include language locales anymore, these are maintained in the worpdress translation GlotPress instead. As a result, you need to install locales manually, one for each language you want to create forms for. You can then create a form in a new language by adding the
locale
attribute in your dashboard url, for example for the German locale de_DE,http://<your-domain>/wp-admin/admin.php?page=wpcf7-new&locale=de_DE
Alternatively, you can use the CF7 PolyLang module which allows you to manage CF7 forms in different languages using the PolyLang plugin (recommended by WP). PolyLang is an alternative to WPML,