【问题标题】:Placeholder i18next translation not working占位符 i18next 翻译不起作用
【发布时间】:2015-12-26 02:39:31
【问题描述】:

我已经创建了一个注册表单。我正在使用 i18next 服务器端。

这是我的服务器端配置:

var i18n = require('i18next');
i18n.init({
saveMissing: true,
debug: true
});

app.use(i18n.handle);

以下是我的语言环境 json"

{
"app": {
  "lblalreadyhaveanaccount": "¿Ya tienes una cuenta?",
  "lblsignin": "Ingresar",
  "lblhelp": "Ayuda",
  "lblletscreateyouraccount": "Vamos a crear su cuenta",
  "lblname": "Nombre",
  "phfirstname": "Nombre de pila",
  ....
 }

我使用 ejs 作为我的模板引擎。这是以下代码:

...
<form ng-submit="validateForm()">
                <div class="form-group">
                    <!-- Name -->
                    <label><%= t('app.lblname') %></label>

                    <div class="row">
                        <div class="col-md-6">
                            <input id="fname" type="text" class="form-control"
                                   placeholder=<%= t('app.phfirstname') %>>
                        </div>
                        <div class="col-md-6">
                            <input id="lname" type="text" class="form-control"
                                   placeholder=<%= t('app.phlastname') %>>
                        </div>
                    </div>
  ....

我的问题是具有多字字符串的标签被正确呈现,但是占位符仅显示语言环境 json 中字符串中的第一个单词。

这是检查元素显示的内容:

<input id="fname" type="text" class="form-control" placeholder="Nombre" de="" pila="">

我无法找到解决此问题的方法。请帮帮我。 提前谢谢你。

【问题讨论】:

  • 您的“lblletscreateyouraccount”密钥看起来如何?也许有一些你看不到的奇怪编码。
  • 抱歉,打错了。问题依旧。

标签: json node.js internationalization ejs i18next


【解决方案1】:

看起来浏览器正在尝试理解输入标签中的单词。为了帮助它,请尝试在占位符文本周围添加双引号,如下所示:

<div class="row">
    <div class="col-md-6">
        <input id="fname" type="text" class="form-control"
               placeholder="<%= t('app.phfirstname') %>"
    </div>
    <div class="col-md-6">
        <input id="lname" type="text" class="form-control"
               placeholder="<%= t('app.phlastname') %>"
    </div>
</div>

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 1970-01-01
    • 2021-02-08
    • 2014-05-08
    • 1970-01-01
    • 2018-04-15
    • 2012-01-12
    • 2014-05-02
    • 1970-01-01
    相关资源
    最近更新 更多