@localey/react 0.1.2 → 0.1.4

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.
Files changed (2) hide show
  1. package/README.md +20 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,22 +1,28 @@
1
- # @localey/adapter-react
1
+ # @localey/react
2
2
 
3
- React adapter for Localey. Uses Babel AST traversal to identify hardcoded strings in JSX and component props.
3
+ React and JSX adapter for Localey.
4
4
 
5
- ## Supported Patterns
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
- ### JSX Text
7
+ ## Detection Logic
8
8
 
9
- ```tsx
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
- ### Component Props
11
+ ### Supported Patterns
14
12
 
15
- ```tsx
16
- <Button label="Save" /> -> <Button label={t("save")} />
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
- ## Internal Tools
17
+ ### Code Transformation
20
18
 
21
- - **Babel Parser**: Supports TypeScript and JSX.
22
- - **AST Visitor**: Framework-aware detection logic.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localey/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "dependencies": {