lingo-guardian 0.1.0
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/README.md +45 -0
- package/dist/bin/cli.d.ts +10 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +36 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/commands/lint.d.ts +19 -0
- package/dist/commands/lint.d.ts.map +1 -0
- package/dist/commands/lint.js +166 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/constants.d.ts +110 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +41 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/auditor.d.ts +62 -0
- package/dist/core/auditor.d.ts.map +1 -0
- package/dist/core/auditor.js +261 -0
- package/dist/core/auditor.js.map +1 -0
- package/dist/core/lingo-integration.d.ts +109 -0
- package/dist/core/lingo-integration.d.ts.map +1 -0
- package/dist/core/lingo-integration.js +243 -0
- package/dist/core/lingo-integration.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/reporters/reporter.d.ts +35 -0
- package/dist/reporters/reporter.d.ts.map +1 -0
- package/dist/reporters/reporter.js +322 -0
- package/dist/reporters/reporter.js.map +1 -0
- package/dist/transforms/pseudo-locale.d.ts +22 -0
- package/dist/transforms/pseudo-locale.d.ts.map +1 -0
- package/dist/transforms/pseudo-locale.js +181 -0
- package/dist/transforms/pseudo-locale.js.map +1 -0
- package/dist/transforms/rtl.d.ts +26 -0
- package/dist/transforms/rtl.d.ts.map +1 -0
- package/dist/transforms/rtl.js +120 -0
- package/dist/transforms/rtl.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RTL (Right-to-Left) Transformation
|
|
3
|
+
*
|
|
4
|
+
* Applies RTL layout transformation for testing Arabic, Hebrew,
|
|
5
|
+
* Farsi, and other RTL languages.
|
|
6
|
+
*
|
|
7
|
+
* Detects layout breaks from improper CSS that doesn't support
|
|
8
|
+
* bidirectional text properly.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* RTL locale codes
|
|
12
|
+
*/
|
|
13
|
+
const RTL_LOCALES = ['ar', 'he', 'fa', 'ur', 'yi', 'ps', 'sd', 'ug'];
|
|
14
|
+
export class RTLTransform {
|
|
15
|
+
/**
|
|
16
|
+
* Check if a locale is RTL
|
|
17
|
+
*/
|
|
18
|
+
static isRTL(locale) {
|
|
19
|
+
return RTL_LOCALES.includes(locale.toLowerCase().split('-')[0]);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Apply RTL transformation using Playwright
|
|
23
|
+
* Cross-platform compatible (Mac, Windows, Linux)
|
|
24
|
+
*/
|
|
25
|
+
static async applyPlaywright(page, locale = 'ar') {
|
|
26
|
+
await page.evaluate((localeCode) => {
|
|
27
|
+
// Set document direction
|
|
28
|
+
document.documentElement.dir = 'rtl';
|
|
29
|
+
document.documentElement.lang = localeCode;
|
|
30
|
+
// Add RTL styles
|
|
31
|
+
const rtlStyles = document.createElement('style');
|
|
32
|
+
rtlStyles.id = 'lingo-guardian-rtl-styles';
|
|
33
|
+
rtlStyles.textContent = `
|
|
34
|
+
/* Base RTL direction */
|
|
35
|
+
html[dir="rtl"] body {
|
|
36
|
+
direction: rtl;
|
|
37
|
+
text-align: right;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Fix common RTL issues */
|
|
41
|
+
html[dir="rtl"] [style*="text-align: left"] {
|
|
42
|
+
text-align: right !important;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Flip flexbox alignment */
|
|
46
|
+
html[dir="rtl"] .flex-row,
|
|
47
|
+
html[dir="rtl"] [style*="flex-direction: row"] {
|
|
48
|
+
flex-direction: row-reverse;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Highlight potential RTL issues */
|
|
52
|
+
html[dir="rtl"] [style*="margin-left"]:not([style*="margin-right"]),
|
|
53
|
+
html[dir="rtl"] [style*="padding-left"]:not([style*="padding-right"]),
|
|
54
|
+
html[dir="rtl"] [style*="left:"]:not([style*="right:"]) {
|
|
55
|
+
outline: 2px dashed #FF6B6B !important;
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Indicator */
|
|
60
|
+
#lingo-guardian-rtl-indicator {
|
|
61
|
+
position: fixed;
|
|
62
|
+
top: 4px;
|
|
63
|
+
left: 4px;
|
|
64
|
+
background: #10B981;
|
|
65
|
+
color: white;
|
|
66
|
+
padding: 4px 8px;
|
|
67
|
+
border-radius: 4px;
|
|
68
|
+
font-size: 10px;
|
|
69
|
+
font-family: monospace;
|
|
70
|
+
z-index: 99999;
|
|
71
|
+
opacity: 0.9;
|
|
72
|
+
direction: ltr;
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
document.head.appendChild(rtlStyles);
|
|
76
|
+
// Process inline styles that might cause RTL issues
|
|
77
|
+
const elementsWithInlineStyles = document.querySelectorAll('[style]');
|
|
78
|
+
elementsWithInlineStyles.forEach((el) => {
|
|
79
|
+
const htmlEl = el;
|
|
80
|
+
const style = htmlEl.style;
|
|
81
|
+
const marginLeft = style.marginLeft;
|
|
82
|
+
const marginRight = style.marginRight;
|
|
83
|
+
if (marginLeft && !marginRight) {
|
|
84
|
+
style.marginRight = marginLeft;
|
|
85
|
+
style.marginLeft = '';
|
|
86
|
+
}
|
|
87
|
+
const paddingLeft = style.paddingLeft;
|
|
88
|
+
const paddingRight = style.paddingRight;
|
|
89
|
+
if (paddingLeft && !paddingRight) {
|
|
90
|
+
style.paddingRight = paddingLeft;
|
|
91
|
+
style.paddingLeft = '';
|
|
92
|
+
}
|
|
93
|
+
if (style.textAlign === 'left') {
|
|
94
|
+
style.textAlign = 'right';
|
|
95
|
+
}
|
|
96
|
+
else if (style.textAlign === 'right') {
|
|
97
|
+
style.textAlign = 'left';
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// Add visual indicator
|
|
101
|
+
const indicator = document.createElement('div');
|
|
102
|
+
indicator.id = 'lingo-guardian-rtl-indicator';
|
|
103
|
+
indicator.innerHTML = `⬅️ RTL (${localeCode.toUpperCase()})`;
|
|
104
|
+
document.body.appendChild(indicator);
|
|
105
|
+
}, locale);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get sample RTL text for testing
|
|
109
|
+
*/
|
|
110
|
+
static getSampleText(locale = 'ar') {
|
|
111
|
+
const samples = {
|
|
112
|
+
ar: 'مرحبا بالعالم',
|
|
113
|
+
he: 'שלום עולם',
|
|
114
|
+
fa: 'سلام دنیا',
|
|
115
|
+
ur: 'ہیلو ورلڈ',
|
|
116
|
+
};
|
|
117
|
+
return samples[locale] || samples.ar;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=rtl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtl.js","sourceRoot":"","sources":["../../src/transforms/rtl.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAErE,MAAM,OAAO,YAAY;IACrB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAc;QACvB,OAAO,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAoB,EAAE,SAAiB,IAAI;QACpE,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,UAAkB,EAAE,EAAE;YACvC,yBAAyB;YACzB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;qBAAM,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,EAAE,CAAC;oBACrC,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;gBAC7B,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,uBAAuB;YACvB,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAChD,SAAS,CAAC,EAAE,GAAG,8BAA8B,CAAC;YAC9C,SAAS,CAAC,SAAS,GAAG,WAAW,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC;YAC7D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACzC,CAAC,EAAE,MAAM,CAAC,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAAiB,IAAI;QACtC,MAAM,OAAO,GAA2B;YACpC,EAAE,EAAE,eAAe;YACnB,EAAE,EAAE,WAAW;YACf,EAAE,EAAE,WAAW;YACf,EAAE,EAAE,WAAW;SAClB,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC;IACzC,CAAC;CACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lingo-guardian",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool to detect i18n layout issues - CSS overflows, RTL breaks, and text expansion problems. Powered by Lingo.dev",
|
|
5
|
+
"author": "Lingo-Guardian Team",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"lingo-guardian": "./dist/bin/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/ashpreetsinghanand/lingo-guardian.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/ashpreetsinghanand/lingo-guardian#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/ashpreetsinghanand/lingo-guardian/issues"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"dev": "tsc --watch",
|
|
28
|
+
"start": "node ./dist/bin/cli.js",
|
|
29
|
+
"lint": "eslint src --ext .ts",
|
|
30
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
31
|
+
"clean": "rm -rf dist",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"postinstall": "npx playwright install chromium --with-deps 2>/dev/null || true"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"chalk": "^5.3.0",
|
|
37
|
+
"commander": "^11.1.0",
|
|
38
|
+
"ora": "^8.0.1",
|
|
39
|
+
"playwright": "^1.40.0",
|
|
40
|
+
"table": "^6.8.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.10.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
45
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
46
|
+
"typescript": "^5.3.3"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"i18n",
|
|
53
|
+
"internationalization",
|
|
54
|
+
"localization",
|
|
55
|
+
"lingo.dev",
|
|
56
|
+
"lingo",
|
|
57
|
+
"overflow",
|
|
58
|
+
"rtl",
|
|
59
|
+
"ltr",
|
|
60
|
+
"css",
|
|
61
|
+
"lint",
|
|
62
|
+
"devtools",
|
|
63
|
+
"react",
|
|
64
|
+
"testing",
|
|
65
|
+
"accessibility"
|
|
66
|
+
],
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
}
|
|
70
|
+
}
|