Skip to content

Commit ed3a92e

Browse files
committed
feat: added new rule for obj prop translate
1 parent deb2682 commit ed3a92e

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

commitlint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable translate-obj-prop/translate-obj-prop */
2+
13
export default {
24
parserPreset: 'conventional-changelog-conventionalcommits',
35
prompt: {

configs/eslint-config.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import unusedImports from 'eslint-plugin-unused-imports'
1616
import globals from 'globals'
1717
import tseslint from 'typescript-eslint'
1818

19+
import translateObjProp from './obj-prop-translate.mjs'
20+
1921
export default tseslint.config(
2022
eslint.configs.recommended,
2123
...tseslint.configs.strict,
@@ -43,11 +45,6 @@ export default tseslint.config(
4345
}
4446
},
4547
plugins: {
46-
// custom: {
47-
// rules: {
48-
// // 'plugin-name': importedPlugin,
49-
// }
50-
// },
5148
cypress,
5249
import: fixupPluginRules(importPlugin),
5350
jsxA11Y,
@@ -57,6 +54,11 @@ export default tseslint.config(
5754
'react-hooks': fixupPluginRules(reactHooks),
5855
'react-refresh': reactRefresh,
5956
stylisticTs,
57+
'translate-obj-prop': {
58+
rules: {
59+
'translate-obj-prop': translateObjProp['translate-obj-prop']
60+
}
61+
},
6062
unicorn: eslintPluginUnicorn,
6163
'unused-imports': unusedImports
6264
},
@@ -151,6 +153,7 @@ export default tseslint.config(
151153
]
152154
}
153155
],
156+
'translate-obj-prop/translate-obj-prop': ['warn'],
154157

155158
'object-curly-newline': [
156159
'error',

configs/obj-prop-translate.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable translate-obj-prop/translate-obj-prop */
2+
3+
export default {
4+
'translate-obj-prop': {
5+
create(context) {
6+
const translatableObjKeys = new Set([
7+
'addConnectionHelpingText',
8+
'cancelText',
9+
'description',
10+
'helperText',
11+
'label',
12+
'okText',
13+
'placeholder',
14+
'title'
15+
])
16+
return {
17+
Property(node) {
18+
// Check if the property is "label"
19+
if (
20+
node.key &&
21+
translatableObjKeys.has(node.key.name) &&
22+
node.value.type === 'Literal' &&
23+
typeof node.value.value === 'string'
24+
) {
25+
// Report a warning if `label` is not translated
26+
context.report({
27+
fix(fixer) {
28+
// Replace the value with a translation function call
29+
const fixedValue = `__('${node.value.value.replaceAll("'", String.raw`\'`)}')`
30+
return fixer.replaceText(node.value, fixedValue)
31+
},
32+
message: 'property should be wrapped in a translation function.',
33+
node
34+
})
35+
}
36+
}
37+
}
38+
},
39+
meta: {
40+
docs: {
41+
description: 'Ensure that the translatable property is wrapped in a translation function.'
42+
},
43+
fixable: 'code', // Indicates that this rule has an auto-fix
44+
schema: [], // No options needed
45+
type: 'suggestion' // Indicates this rule is a suggestion
46+
}
47+
}
48+
}

frontend/components/SupportPage/data/pluginInfoData.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { __ } from '@common/helpers/i18nwrap'
2+
13
export default {
24
chatLink: 'https://tawk.to/chat/60eac4b6d6e7610a49aab375/1faah0r3e',
35
facebookCommunity: 'https://www.facebook.com/groups/bitcommunityusers',
46
linkedIn: 'https://www.linkedin.com/company/bitapps',
57
plugins: {
6-
'bit-pi': {
7-
buyLink: 'https://bit-pi.com/#pricing/',
8-
description: `Bit Pi - Zapier Alternative in WordPress Unlimited Task.`,
9-
docLink: 'https://bit-pi.com/documentation/',
8+
'bit-flows': {
9+
buyLink: 'https://bit-flows.com/#pricing/',
10+
description: __('Bit Flows - Zapier Alternative in WordPress Unlimited Task.'),
11+
docLink: 'https://bit-flows.com/documentation/',
1012
reviewLink: 'https://wordpress.org/support/plugin/bit-pi/reviews/',
11-
title: 'Bit Pi',
12-
website: 'https://bit-pi.com',
13+
title: __('Bit Flows'),
14+
website: 'https://bit-flows.com',
1315
wpSupportThread: 'https://wordpress.org/support/plugin/bit-pi/'
1416
},
1517
'bit-social': {
@@ -19,7 +21,7 @@ export default {
1921
feature.`,
2022
docLink: 'https://bit-social.com/documentation/',
2123
reviewLink: 'https://wordpress.org/support/plugin/bit-social/reviews/',
22-
title: 'Bit Social',
24+
title: __('Bit Social'),
2325
website: 'https://bit-social.com',
2426
wpSupportThread: 'https://wordpress.org/support/plugin/bit-social/'
2527
}

0 commit comments

Comments
 (0)