【问题标题】:WordPress: Add a language attribute to the shortcode for translationWordPress:向简码添加语言属性以进行翻译
【发布时间】:2018-03-15 00:15:36
【问题描述】:

我正在尝试让我的简码能够切换语言。

例如[my-form lang="fr_FR"] 将加载我的法语 mo 文件并以法语显示表单。其他语言也一样:[my-form lang="en_US"] 将以英文显示表单。

.mo 文件没问题,我的插件管理根据 worpress 语言设置显示正确的语言。为此,我将这一行放在我的插件主文件中('plugins_loaded' 挂钩):

load_plugin_textdomain( 'my-plugin', false, basename( dirname( __ FILE __ ) ) . '/languages' ); 

在简码函数中,我称之为:

load_textdomain( 'my-plugin', $pathtomofile ) 

$pathtomofile 根据语言 shorcode 属性适配:'fr_FR' 调用法语 mo 文件,'en_US' 调用英语 mo 文件...

问题是:当简码调用“en_US”时,它适用于切换到“français”的英文 wordpress 安装。当我将设置切换回“英语(美国)”并尝试使用简码调用“fr_FR”时,它不起作用。 我的脑子会爆炸,你能解释一下吗?

谢谢。

【问题讨论】:

    标签: wordpress plugins translation shortcode


    【解决方案1】:

    我找到了解决方案。实际上,我需要删除 WP 注册的翻译:

    global $l10n;
    if (isset($l10n['my-plugin'])){
        unset($l10n['my-plugin']);
    }
    load_textdomain( 'my-plugin', $pathtomofile ) 
    

    【讨论】:

      猜你喜欢
      • 2012-03-26
      • 2022-07-28
      • 2012-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 2017-03-05
      • 2018-07-15
      相关资源
      最近更新 更多