You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68-17Lines changed: 68 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ npm install react-autolocalise
26
26
yarn add react-autolocalise
27
27
```
28
28
29
-
## Usage
29
+
## React Client Side Component Usage
30
30
31
31
### Initialize the SDK
32
32
@@ -117,7 +117,7 @@ const MyComponent = () => {
117
117
118
118
This SDK provides comprehensive SSR support through middleware-based locale detection and server components. Here's how to implement end-to-end server-side translation:
119
119
120
-
### Middleware Setup
120
+
### Middleware Setup for language detection
121
121
122
122
Create a middleware file to detect user's locale from request headers or URL parameters:
123
123
@@ -146,45 +146,96 @@ export const config = {
146
146
};
147
147
```
148
148
149
+
### Initialize Translation Service (Singleton Pattern)
150
+
151
+
The SDK uses a singleton pattern for the TranslationService to ensure efficient caching and batch processing. Create a utility file to manage the translator instance:
Create server components that utilize the detected locale:
152
172
153
173
> **Note**: For server-side rendering, all translations must be completed before sending the response to the client. This requires a two-step process: first mark texts for translation using t() , then execute all translations in a single batch with execute() . This ensures all translations are ready before rendering occurs.
0 commit comments