【问题标题】:Add translation to a script option line inside JS as a variable将翻译添加到 JS 内的脚本选项行作为变量
【发布时间】:2018-05-21 06:46:38
【问题描述】:

我正在使用 Prestashop,我需要在 JS 文件中添加可翻译的文本。在 TPL 文件中,我添加了以下内容:

{strip}
{addJsDefL name=showmore}{l s='Show all' d='Shop.Theme.Actions' js=1}{/addJsDefL}
{addJsDefL name=showless}{l s='Show less' d='Shop.Theme.Actions' js=1}{/addJsDefL}
{/strip}

根据 Prestashop 的说法,我相信上面的代码会生成: var showmore='显示全部'; var showless= '少看';

然后在 JS 文件中,我这样做是为了在下面的“文本”选项中包含可翻译的文本:

$('.demo').curtail({
  limit: 140,
  toggle: true,
  text: ['" + showless + "', '" + showmore + "']
});

我怀疑我在方括号内添加 var 的方式有误,因为 text: ['" + showless + "', '" + showmore + "'] 它不起作用。 有什么想法吗?

【问题讨论】:

  • 试试 '"'+showless+'"',' " ' + showmore + ' " '

标签: javascript html prestashop smarty


【解决方案1】:

如果您的文本参数需要一个数组,只需使用此text: [showless, showmore]。您不需要使用任何引号,因为您已经获得了字符串。

【讨论】:

    【解决方案2】:

    我可以通过在 TPL 文件中添加以下内容来解决此问题:

    <script type="text/javascript">
    // <![CDATA[
        // Translations
        var showmore = '{l s='Show all' d='Shop.Theme.Actions' js=1}';
        var showless = '{l s='Show less' d='Shop.Theme.Actions' js=1}';
    //]]>
    </script>
    

    然后我将这个添加到 JS 文件的选项中

    text: [(showless), (showmore)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 2020-05-20
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多