【问题标题】:Add localization to vue-tables2 table向 vue-tables2 表添加本地化
【发布时间】:2018-06-20 07:59:11
【问题描述】:

Here 是我项目中的一个类似的表示例。

我的项目是一个多语言网站,所以我希望将 vue-table 也翻译成用户当前使用的语言。我要翻译的只是表格元素,而不是表格中的实际数据。例如,在示例中,字符串“记录”应翻译为用户语言。还应翻译分页下的文本“显示 50 条记录中的 1 到 10 条”。

.

示例代码:

Vue.use(VueTables.ClientTable);
new Vue({
  el: "#app",
  data: {
    columns: ['name', 'code', 'uri'],
    data: getData(),
    options: {
      headings: {
        name: 'Country Name',
        code: 'Country Code',
        uri: 'View Record'
      },
      sortable: ['name', 'code'],
      filterable: ['name', 'code']
    }
  }
});

还有 HTML:

<div id="app">
  <v-client-table :columns="columns" :data="data" :options="options">
    <a slot="uri" slot-scope="props" target="_blank" :href="props.row.uri" class="glyphicon glyphicon-eye-open"></a>

    <div slot="child_row" slot-scope="props">
      The link to {{props.row.name}} is <a :href="props.row.uri">{{props.row.uri}}</a>
    </div>

  </v-client-table>
</div>

如果有人知道我应该如何做到这一点,我将不胜感激。

【问题讨论】:

标签: javascript vue.js vue-tables-2


【解决方案1】:

documentation 中有一个“texts”选项,它指的是这个file 中的“texts”选项。

因此,在您的数据中,您只需添加 texts 参数并对其进行编辑:

new Vue({
    el: "#app",
    data: {
        columns: ['name', 'code', 'uri'],
        data: getData(),
        options: {
            headings: {
                name: 'Country Name',
                code: 'Country Code',
                uri: 'View Record'
            },
            sortable: ['name', 'code'],
            filterable: ['name', 'code'],
            // EDITABLE TEXT OPTIONS:
            texts: {
                count: "Showing {from} to {to} of {count} records|{count} records|One record",
                first: 'First',
                last: 'Last',
                filter: "Filter:",
                filterPlaceholder: "Search query",
                limit: "Records:",
                page: "Page:",
                noResults: "No matching records",
                filterBy: "Filter by {column}",
                loading: 'Loading...',
                defaultOption: 'Select {column}',
                columns: 'Columns'
            },
        }
    }
});

【讨论】:

  • 这是一个精彩的资源;感谢您编制清单。这个库有一些我用过的最没有帮助的documentation;这个答案很棒,非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-03
  • 2012-08-17
  • 1970-01-01
  • 2011-02-19
  • 2011-09-17
  • 2020-08-22
相关资源
最近更新 更多