@18ways/eslint-plugin-translate 0.0.0-alpha.1aa37fb04f1f → 0.0.0-alpha.42e08a82e9b3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -194
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 18ways
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,215 +1,43 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# @18ways/eslint-plugin-translate
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
18ways makes i18n easy. SEO-ready, AI-powered translations for modern products.
|
|
6
|
+
|
|
7
|
+
`@18ways/eslint-plugin-translate` is the ESLint plugin for 18ways. It catches hard-coded user-facing strings and nudges code toward `<T>` and `useT()`.
|
|
4
8
|
|
|
5
|
-
##
|
|
9
|
+
## Install
|
|
6
10
|
|
|
7
11
|
```bash
|
|
8
|
-
|
|
12
|
+
npm install -D @18ways/eslint-plugin-translate
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
Add `@18ways/translate` to your ESLint configuration:
|
|
15
|
+
## Basic config
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
module.exports = {
|
|
19
|
-
plugins: ['@18ways/translate'],
|
|
20
|
-
rules: {
|
|
21
|
-
'@18ways/translate/require-translation': 'error',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Using Preset Configurations
|
|
27
|
-
|
|
28
|
-
#### Recommended Configuration
|
|
29
|
-
|
|
30
|
-
```javascript
|
|
17
|
+
```js
|
|
31
18
|
module.exports = {
|
|
32
19
|
extends: ['plugin:@18ways/translate/recommended'],
|
|
33
20
|
};
|
|
34
21
|
```
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
module.exports = {
|
|
40
|
-
extends: ['plugin:@18ways/translate/strict'],
|
|
41
|
-
};
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Rule: `require-translation`
|
|
45
|
-
|
|
46
|
-
Detects user-facing strings that should be wrapped in 18ways translation components or hooks.
|
|
47
|
-
|
|
48
|
-
### What it detects:
|
|
49
|
-
|
|
50
|
-
1. **JSX Text Content** - Text directly in JSX elements
|
|
51
|
-
2. **User-facing Attributes** - Attributes like `alt`, `placeholder`, `aria-label`, etc.
|
|
52
|
-
3. **String Literals** - Hardcoded strings in user-facing contexts
|
|
53
|
-
4. **Template Literals** - Template strings with user-facing content
|
|
54
|
-
|
|
55
|
-
### Examples
|
|
56
|
-
|
|
57
|
-
#### ❌ Invalid (will trigger the rule):
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
// JSX text content
|
|
61
|
-
<div>Hello World</div>
|
|
62
|
-
<button>Click Me</button>
|
|
63
|
-
|
|
64
|
-
// User-facing attributes
|
|
65
|
-
<img src="/logo.png" alt="Company Logo" />
|
|
66
|
-
<input placeholder="Enter your name" />
|
|
67
|
-
<button aria-label="Close dialog">×</button>
|
|
68
|
-
|
|
69
|
-
// String literals in JSX
|
|
70
|
-
<div>{"Welcome to our site"}</div>
|
|
71
|
-
|
|
72
|
-
// Template literals
|
|
73
|
-
<div>{`Hello ${name}!`}</div>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### ✅ Valid (properly translated):
|
|
23
|
+
## Good / bad
|
|
77
24
|
|
|
78
25
|
```tsx
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
// Using useT hook
|
|
84
|
-
const t = useT();
|
|
85
|
-
const message = t("Hello World");
|
|
86
|
-
|
|
87
|
-
// Non-user-facing content (automatically ignored)
|
|
88
|
-
<div id="my-component" className="header">
|
|
89
|
-
<img src="/images/logo.png" />
|
|
90
|
-
<div>{42}</div>
|
|
91
|
-
<a href="mailto:test@example.com">
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Rule Options
|
|
95
|
-
|
|
96
|
-
```javascript
|
|
97
|
-
{
|
|
98
|
-
"@18ways/translate/require-translation": ["error", {
|
|
99
|
-
"translateComponent": "T", // Name of translation component (default: "T")
|
|
100
|
-
"translateHook": "useT", // Name of translation hook (default: "useT")
|
|
101
|
-
"userFacingAttributes": [ // Attributes considered user-facing
|
|
102
|
-
"alt", "title", "aria-label",
|
|
103
|
-
"placeholder", "value", "label"
|
|
104
|
-
],
|
|
105
|
-
"ignorePatterns": [ // Regex patterns to ignore
|
|
106
|
-
"^[a-zA-Z0-9_-]{1,3}$", // Very short identifiers (1-3 chars)
|
|
107
|
-
"^[A-Z_]+$", // Constants
|
|
108
|
-
"^\\d+$", // Numbers
|
|
109
|
-
"^[a-z]+://.*", // URLs
|
|
110
|
-
"^/.*", // Paths
|
|
111
|
-
"^#[a-fA-F0-9]{3,8}$", // Hex colors
|
|
112
|
-
"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", // Emails
|
|
113
|
-
"^\\s*$" // Whitespace only
|
|
114
|
-
],
|
|
115
|
-
"ignoreFiles": [ // File patterns to ignore
|
|
116
|
-
".*\\.test\\.[jt]sx?$",
|
|
117
|
-
".*\\.spec\\.[jt]sx?$",
|
|
118
|
-
".*/test/.*"
|
|
119
|
-
]
|
|
120
|
-
}]
|
|
26
|
+
// Bad
|
|
27
|
+
export function Header() {
|
|
28
|
+
return <h1>Hello world</h1>;
|
|
121
29
|
}
|
|
122
|
-
```
|
|
123
30
|
|
|
124
|
-
|
|
31
|
+
// Good
|
|
32
|
+
import { T } from '@18ways/react';
|
|
125
33
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}]
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Then use it like:
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
<Translate>Hello World</Translate>
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Additional User-facing Attributes
|
|
143
|
-
|
|
144
|
-
To check additional attributes:
|
|
145
|
-
|
|
146
|
-
```javascript
|
|
147
|
-
{
|
|
148
|
-
"@18ways/translate/require-translation": ["error", {
|
|
149
|
-
"userFacingAttributes": [
|
|
150
|
-
"alt", "title", "aria-label", "placeholder",
|
|
151
|
-
"data-tooltip", "summary", "caption"
|
|
152
|
-
]
|
|
153
|
-
}]
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Custom Ignore Patterns
|
|
158
|
-
|
|
159
|
-
To ignore specific patterns:
|
|
160
|
-
|
|
161
|
-
```javascript
|
|
162
|
-
{
|
|
163
|
-
"@18ways/translate/require-translation": ["error", {
|
|
164
|
-
"ignorePatterns": [
|
|
165
|
-
"^[a-zA-Z0-9_-]+$", // Default patterns
|
|
166
|
-
"^TEST_.*", // Custom: ignore test constants
|
|
167
|
-
"^\\$.*" // Custom: ignore $ prefixed strings
|
|
168
|
-
]
|
|
169
|
-
}]
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Integration with 18ways
|
|
174
|
-
|
|
175
|
-
This plugin is designed to work with the 18ways translation system:
|
|
176
|
-
|
|
177
|
-
```tsx
|
|
178
|
-
import { Ways, T, useT } from '18ways';
|
|
179
|
-
|
|
180
|
-
// Wrap your app
|
|
181
|
-
<Ways apiKey="your-api-key" locale="en-US" baseLocale="en-US">
|
|
182
|
-
<Ways context="header">
|
|
183
|
-
<T>Welcome to our site</T>
|
|
184
|
-
</Ways>
|
|
185
|
-
</Ways>;
|
|
186
|
-
|
|
187
|
-
// Use translation hook
|
|
188
|
-
function MyComponent() {
|
|
189
|
-
const t = useT();
|
|
190
|
-
return <p>{t('Learn more about our company')}</p>;
|
|
34
|
+
export function Header() {
|
|
35
|
+
return (
|
|
36
|
+
<h1>
|
|
37
|
+
<T>Hello world</T>
|
|
38
|
+
</h1>
|
|
39
|
+
);
|
|
191
40
|
}
|
|
192
41
|
```
|
|
193
42
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
# Install dependencies
|
|
198
|
-
bun install
|
|
199
|
-
|
|
200
|
-
# Build the plugin
|
|
201
|
-
bun run build
|
|
202
|
-
|
|
203
|
-
# Run tests
|
|
204
|
-
bun run test
|
|
205
|
-
|
|
206
|
-
# Run tests in watch mode
|
|
207
|
-
bun run test:watch
|
|
208
|
-
|
|
209
|
-
# Lint the code
|
|
210
|
-
bun run lint
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## License
|
|
214
|
-
|
|
215
|
-
MIT
|
|
43
|
+
Docs: [18ways.com/docs](https://18ways.com/docs)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@18ways/eslint-plugin-translate",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.42e08a82e9b3",
|
|
4
4
|
"description": "ESLint plugin to detect untranslated strings that should use 18ways translate functionality",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|