@localey/react 0.1.2 → 0.1.3
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 +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
# @localey/
|
|
1
|
+
# @localey/react
|
|
2
2
|
|
|
3
|
-
React adapter for Localey.
|
|
3
|
+
React and JSX adapter for Localey.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package provides the logic necessary for Localey to understand and manipulate React source code. It utilizes high-precision Abstract Syntax Tree (AST) traversal to identify hardcoded strings within JSX elements and component properties.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Detection Logic
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
<div>Hello World</div> -> <div>{t("hello.world")}</div>
|
|
11
|
-
```
|
|
9
|
+
The adapter utilizes the `@babel/parser` and `@babel/traverse` packages to analyze source code. It targets specific nodes within the AST that predominantly contain user-facing text.
|
|
12
10
|
|
|
13
|
-
###
|
|
11
|
+
### Supported Patterns
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
- **JSX Text Nodes**: Standard text content between opening and closing JSX tags.
|
|
14
|
+
- **Component Attributes**: String literals passed to props (e.g., `label`, `title`, `placeholder`).
|
|
15
|
+
- **Conditional Strings**: Support for strings within ternary operators and template literals is currently handled via AST inspection.
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
### Code Transformation
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
During the `extract` process, this adapter replaces string literals with JSX expression containers.
|
|
20
|
+
|
|
21
|
+
- **Pattern**: `text` -> `{t("key")}`
|
|
22
|
+
- **Attribute Pattern**: `attr="value"` -> `attr={t("key")}`
|
|
23
|
+
|
|
24
|
+
## Technical Implementation
|
|
25
|
+
|
|
26
|
+
- **Parser Configuration**: The adapter is configured to support both `.js`/`.jsx` and `.ts`/`.tsx` files by enabling the `jsx` and `typescript` Babel plugins.
|
|
27
|
+
- **AST Visitor**: Implementation of the Visitor pattern to efficiently navigate the tree and identify candidates for localization.
|
|
28
|
+
- **Generator**: Uses `@babel/generator` to reconstruct the source code from the modified AST, ensuring syntactic correctness.
|