Localization 本地化窗口。location.href

Localization 本地化窗口。location.href,localization,internationalization,wpml,Localization,Internationalization,Wpml,我正在编写一个404定制页面,一切都很好,但我使用的是WPML,因此我正在本地化我的字符串 这是我代码的一部分: <h4><?php _e('You still can\'t find anything?', 'kslang'); ?></h4> <h5><?php _e('Well, then you probably should give us a wake up call...', 'kslang'); "\n"?></h

我正在编写一个404定制页面,一切都很好,但我使用的是WPML,因此我正在本地化我的字符串

这是我代码的一部分:

<h4><?php _e('You still can\'t find anything?', 'kslang'); ?></h4>
<h5><?php _e('Well, then you probably should give us a wake up call...', 'kslang'); "\n"?></h5>
<h5><?php _e('but be aware who you\'re waking up!', 'kslang');?></h5>
<h5><?php _e('You\'re sure? Well, then...', 'kslang'); ?></h5>
<form>
    <input type="button" value="<?php _e('Contact Us!', 'kslang'); ?>" onClick="window.location.href='http://example.com/contact-us-today'">
</form>
<h5><?php _e('or try the Site Map Below. You\'re also welcome to check out our related projects!', 'kslang'); ?></h5>
未重定向到相对语言

我想我可以简单地将href链接包装在get text中,比如按按钮文本和其他字符串

这不起作用,显然事情更复杂。 我需要使用if/else语句吗

有人知道如何重定向到正确的语言吗? (我尝试使用_e来翻译字符串转换器中的href链接,但这不适用于_e,因为在这种情况下插入php代码片段会破坏我的网站)


希望有人能提供输入…

要使用window.location.href重定向到相应的语言版本,您需要在URL中包含该语言。。。i、 e,对于法语,重定向到“”(域后带有“fr”)。您可以通过在PHP中检测当前WPML语言并将其作为JavaScript变量进行响应来动态执行此操作,如下所示:

//Get current WPML language
global $sitepress;
$language = $sitepress->get_current_language();
//Echo as JS variable
echo "<script>var lang = '".$language."';</script>"
window.location.href='http://www.example.com/'+lang+'/contact-us-today';

注意:此示例假设您正在为不同的语言使用语言文件夹。如果您正在使用,您需要进行相应的调整。

好的,我找到了一个更简单的解决方案,我创建了一个CSS类,然后使用以下代码添加带有icl规则的联系人按钮:这非常有效。不是window.location.href的解决方案,而是更好的解决方案
window.location.href='http://www.example.com/'+lang+'/contact-us-today';