如何本地化联系表单 7 中的字段标签

发布于 2025-01-03 03:12:14 字数 1106 浏览 1 评论 0原文

我已成功将我的客户网站从西班牙语本地化为法语:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘味果▽酱 2025-01-10 03:12:14

我认为您的问题的解决方案在于能够在 Contact Form 7 模板中运行 PHP。您可以通过编写自己的短代码然后将其添加到 CF7 中来完成此操作。

首先,设置一个短代码,以便您的翻译功能在 WP 内容区域中可用。像这样的东西:(

function e_text_shortcode( $atts ) {
    extract( shortcode_atts( array(
        'text' => 'something',
        'theme_domain' => 'something else',
    ), $atts ) );

    return _e($text, $theme_domain);
}
add_shortcode('e_text', 'e_text_shortcode');

免责声明:我还没有测试过这个!)

然后你可以使用 像这样的插件,这样您就可以将短代码添加到 CF7 模板区域。使用此插件,您必须定义要用作“键”的代码,例如:

e_text key='e_text'

然后您应该能够在 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:

function e_text_shortcode( $atts ) {
    extract( shortcode_atts( array(
        'text' => 'something',
        'theme_domain' => 'something else',
    ), $atts ) );

    return _e($text, $theme_domain);
}
add_shortcode('e_text', 'e_text_shortcode');

(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:

e_text key='e_text'

Then you should be able to use e_text shortcode in the CF7 form template and email templates.

狼亦尘 2025-01-10 03:12:14

感谢您的建议 JunkMyFunk。我尝试实现这一点,但遇到了一些问题。

我最终使用以下方法找到了解决方法:

  1. 安装 WPML 插件。
  2. 为 WP CF7 中的每种语言创建联系表单
  3. 使用以下条件语句显示每种语言的正确联系表单。

    
    

仍然感谢您的帮助 -

Thanks for the suggestion JunkMyFunk. I tried to implement this but ran into some issues.

I eventually found a workaround using the following method:

  1. Install WPML plugin.
  2. Create a contact form for each language in WP CF7
  3. Use the following conditional statement to show the correct contact form for each language.

    <?php if(get_bloginfo('language')=='es-ES') 
    { 
    echo do_shortcode('[contact-form 1 "Contact form 1"]'); 
    } else {   
    echo do_shortcode('[contact-form 2 "Contact_form_2"]');   
    } 
    ?>
    

Thanks for your help all the same -

淡写薰衣草的香 2025-01-10 03:12:14

这不起作用的原因是因为从 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 的替代品,

  1. 安装 PolyLang 插件并激活。
  2. 在仪表板“设置”->“语言”部分中,将语言添加到您的 Polylang 设置中。您添加的每种语言,polylang 都会管理每种语言的内容。您网站的访问者将能够选择他们想要查看的语言内容,或者根据您选择的设置自动查看其浏览器默认语言。
  3. 接下来,安装CF7模块并激活它。它将查找您在 Polylang 设置中设置的语言并下载正确的 CF7 语言环境。它还将使这些语言的表单管理成为可能。

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,

  1. Install the PolyLang plugin, and activate.
  2. In the dashboard Settings->Language section, add languages to your polylang settings. Each language you add, polylang will manage the content in each of these languages. Visitors to your site will be able to choose which language content they want to see, or automatically view their browser default language depending on the settings you choose.
  3. Next, install the CF7 module and activate it. It will lookup the languages you set up in the the polylang settings and download the correct CF7 locale. It will also enable the management of the forms in those languages.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文