@studyjoyful/shared 1.0.1 → 1.0.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 +63 -0
- package/package.json +1 -2
- package/src/i18n/locales/en/auth.json +9 -0
package/README.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Shared code for StudyJoyful Web and App.
|
|
4
4
|
|
|
5
|
+
## 🎯 Design Principles
|
|
6
|
+
|
|
7
|
+
### i18n: Single Source of Truth
|
|
8
|
+
|
|
9
|
+
> ⚠️ **Critical**: This package is the **ONLY** source of translations.
|
|
10
|
+
> Web and App do NOT have their own `locales/` directories.
|
|
11
|
+
|
|
12
|
+
| Principle | Description |
|
|
13
|
+
| ----------------- | --------------------------------------- |
|
|
14
|
+
| **Single Source** | All translations here, nowhere else |
|
|
15
|
+
| **English Only** | Singapore market = English only |
|
|
16
|
+
| **Modular** | Split by feature (auth, chat, tasks...) |
|
|
17
|
+
| **Shared** | Web + App import from this package |
|
|
18
|
+
|
|
5
19
|
## 📦 Modules
|
|
6
20
|
|
|
7
21
|
| Module | Description | Exports |
|
|
@@ -111,6 +125,55 @@ npx tsc --noEmit
|
|
|
111
125
|
3. Re-export from main `src/index.ts`
|
|
112
126
|
4. Test in both Web and App
|
|
113
127
|
|
|
128
|
+
## 🌍 Adding Translations
|
|
129
|
+
|
|
130
|
+
### DO:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Add to this package
|
|
134
|
+
src/i18n/locales/en/auth.json # ✅ Correct
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### DON'T:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Never create locales in consumer projects
|
|
141
|
+
studyjoyful-app/locales/ # ❌ WRONG
|
|
142
|
+
studyjoyful-web/locales/ # ❌ WRONG
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Translation File Structure
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
// src/i18n/locales/en/auth.json
|
|
149
|
+
{
|
|
150
|
+
"welcome": {
|
|
151
|
+
"title": "StudyJoyful",
|
|
152
|
+
"subtitle": "Turn homework into 10-minute learning games",
|
|
153
|
+
"getStarted": "Get Started"
|
|
154
|
+
},
|
|
155
|
+
"errors": {
|
|
156
|
+
"signInFailed": "Sign In Failed",
|
|
157
|
+
"tryAgain": "Please try again"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Usage in Consumer Projects
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// lib/i18n.ts (in Web or App)
|
|
166
|
+
import { resources, namespaces, defaultNS } from "@studyjoyful/shared";
|
|
167
|
+
|
|
168
|
+
// Component
|
|
169
|
+
import { useTranslation } from "react-i18next";
|
|
170
|
+
|
|
171
|
+
function WelcomeScreen() {
|
|
172
|
+
const { t } = useTranslation("auth");
|
|
173
|
+
return <Text>{t("welcome.title")}</Text>;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
114
177
|
---
|
|
115
178
|
|
|
116
179
|
**Package**: `@studyjoyful/shared`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studyjoyful/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Shared code for StudyJoyful Web and App (i18n, constants, types, utils)",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -32,4 +32,3 @@
|
|
|
32
32
|
"typescript": "^5.7.3"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
+
"welcome": {
|
|
3
|
+
"title": "StudyJoyful",
|
|
4
|
+
"subtitle": "Turn homework into 10-minute learning games",
|
|
5
|
+
"getStarted": "Get Started",
|
|
6
|
+
"termsAgreement": "By continuing, you agree to our",
|
|
7
|
+
"termsOfService": "Terms of Service",
|
|
8
|
+
"and": "and",
|
|
9
|
+
"privacyPolicy": "Privacy Policy"
|
|
10
|
+
},
|
|
2
11
|
"signIn": {
|
|
3
12
|
"title": "StudyJoyful",
|
|
4
13
|
"subtitle": "Joyful Learning Starts Here",
|