vue/no-bare-strings-in-template
テンプレートに直接書かれた、国際化の対象となるテキストを検出します。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
なし | なし | なし |
適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。
悪い例
表示するテキストや利用者向けの説明を指定する属性に、翻訳されない文字列を直接書いています。
<template>
<div>hello</div>
<img alt="a cat" />
<input placeholder="Search" />
<button title="Close">x</button>
</template>
良い例
翻訳する内容を $t で取得します。記号だけ、数値だけの内容は例外です。
<template>
<div>{{ $t('hello') }}</div>
<img :alt="$t('cat')" />
<div>-</div>
<div>123</div>
<button :title="$t('close')">{{ $t('x') }}</button>
</template>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-bare-strings-in-template": "warn"
}
},
});
設定したら vp run lint を実行します。