Skip to content

Commit f4f4226

Browse files
committed
[refactor] expose Language Map Loading utility for Front & Back ends
[optimize] merge Language Changing methods [optimize] simplify Example codes [optimize] upgrade to Node.js 22, PNPM 10, TypeDoc 0.28 & other latest Upstream packages
1 parent 5f639cb commit f4f4226

File tree

8 files changed

+1583
-1686
lines changed

8 files changed

+1583
-1686
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414

1515
- uses: pnpm/action-setup@v4
1616
with:
17-
version: 9
17+
version: 10
1818
- uses: actions/setup-node@v4
1919
with:
20-
node-version: 20
20+
node-version: 22
2121
registry-url: https://registry.npmjs.org
2222
cache: pnpm
2323
- name: Install Dependencies

ReadMe.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Responsive **Translation** utility based on [TypeScript][1] & [MobX][2]
1010

1111
## Features
1212

13-
- [x] **Type hinting** of Text keys
14-
- [x] **Lambda Expression** values
15-
- [x] Space utility for CJK & other characters
16-
- [x] **Responsive re-rendering**
17-
- [x] **Async loading** of Language packages
18-
- [x] support **HTTP protocol** for **Server-side rendering**
19-
- [x] support BOM/DOM language API for Client-side rendering
20-
- [x] [Speech Synthesis API][6] for **Text-to-Speech** (TTS)
13+
- [x] **Type hinting** of Text keys
14+
- [x] **Lambda Expression** values
15+
- [x] Space utility for CJK & other characters
16+
- [x] **Responsive re-rendering**
17+
- [x] **Async loading** of Language packages
18+
- [x] support **HTTP protocol** for **Server-side rendering**
19+
- [x] support BOM/DOM language API for Client-side rendering
20+
- [x] [Speech Synthesis API][6] for **Text-to-Speech** (TTS)
2121

2222
## Versions
2323

@@ -26,14 +26,14 @@ Responsive **Translation** utility based on [TypeScript][1] & [MobX][2]
2626
| `>=0.5.0` | `main` | ✅developing | stage-3 | `>=6.11` |
2727
| `<0.5.0` | `master` | ❌deprecated | stage-2 | `>=4 <6.11` |
2828

29-
## Text internationalization (React/Next.js example)
29+
## Text internationalization (React example)
3030

31-
Original from https://github.com/kaiyuanshe/kaiyuanshe.github.io
31+
Original from https://github.com/idea2app/React-MobX-Bootstrap-ts
3232

3333
### Installation
3434

3535
```shell
36-
npm i mobx mobx-react mobx-i18n next-ssr-middleware
36+
npm i mobx mobx-react mobx-i18n
3737
```
3838

3939
### Configuration
@@ -92,47 +92,45 @@ export const LanguageName: Record<(typeof i18n)['currentLanguage'], string> = {
9292
};
9393
```
9494

95-
#### `pages/index.tsx`
95+
#### `page/index.tsx`
9696

9797
```tsx
9898
import { textJoin } from 'mobx-i18n';
99-
import { compose, translator } from 'next-ssr-middleware';
100-
import { Component } from 'react';
99+
import { observer } from 'mobx-react';
101100

102101
import { i18n, LanguageName } from '../model/Translation';
103102

104-
export const getServerSideProps = compose(translator(i18n));
103+
export const HomePage = observer(() => {
104+
const { currentLanguage, t } = i18n;
105+
106+
return (
107+
<>
108+
<select
109+
value={currentLanguage}
110+
onChange={({ currentTarget: { value } }) =>
111+
i18n.loadLanguages(value as typeof currentLanguage)
112+
}
113+
>
114+
{Object.entries(LanguageName).map(([code, name]) => (
115+
<option key={code} value={code}>
116+
{name}
117+
</option>
118+
))}
119+
</select>
120+
<p>
121+
{t('love', {
122+
a: '',
123+
b: textJoin(t('open_source'), t('project'))
124+
})}
125+
</p>
126+
</>
127+
);
128+
});
129+
```
105130

106-
@observer
107-
export default class HomePage extends Component {
108-
render() {
109-
const { currentLanguage, t } = i18n;
131+
### Server Side Rendering (Next.js example)
110132

111-
return (
112-
<>
113-
<select
114-
value={currentLanguage}
115-
onChange={({ currentTarget: { value } }) =>
116-
i18n.changeLanguage(value as typeof currentLanguage)
117-
}
118-
>
119-
{Object.entries(LanguageName).map(([code, name]) => (
120-
<option key={code} value={code}>
121-
{name}
122-
</option>
123-
))}
124-
</select>
125-
<p>
126-
{t('love', {
127-
a: '',
128-
b: textJoin(t('open_source'), t('project'))
129-
})}
130-
</p>
131-
</>
132-
);
133-
}
134-
}
135-
```
133+
You can use [React Context API][7] to share the `TranslationModel` instance cross Class & Function components in Client & Server runtimes, which has been all set in an [One-key Template Repository][8].
136134

137135
## Text to Speech (WebCell example)
138136

@@ -197,3 +195,5 @@ export class ArticlePage extends HTMLElement {
197195
[4]: https://github.com/idea2app/MobX-i18n/actions/workflows/main.yml
198196
[5]: https://nodei.co/npm/mobx-i18n/
199197
[6]: https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis
198+
[7]: https://legacy.reactjs.org/docs/context.html#passing-info-automatically-through-a-tree
199+
[8]: https://github.com/idea2app/Next-Bootstrap-ts

package.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-i18n",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"license": "LGPL-3.0",
55
"author": "[email protected]",
66
"description": "Responsive Translation utility based on TypeScript & MobX",
@@ -27,32 +27,38 @@
2727
"module": "dist/index.esm.js",
2828
"main": "dist/index.js",
2929
"dependencies": {
30-
"@swc/helpers": "^0.5.13",
30+
"@swc/helpers": "^0.5.17",
31+
"@types/node": "^22.15.14",
3132
"regenerator-runtime": "^0.14.1",
32-
"web-utility": "^4.4.0"
33+
"web-utility": "^4.4.3"
3334
},
3435
"peerDependencies": {
3536
"mobx": ">=6.11"
3637
},
3738
"devDependencies": {
38-
"@parcel/config-default": "~2.12.0",
39-
"@parcel/packager-ts": "~2.12.0",
40-
"@parcel/transformer-typescript-tsc": "~2.12.0",
41-
"@parcel/transformer-typescript-types": "~2.12.0",
42-
"@types/jest": "^29.5.13",
43-
"@types/node": "^20.16.10",
44-
"husky": "^9.1.6",
39+
"@parcel/config-default": "~2.14.4",
40+
"@parcel/packager-ts": "~2.14.4",
41+
"@parcel/transformer-typescript-tsc": "~2.14.4",
42+
"@parcel/transformer-typescript-types": "~2.14.4",
43+
"@types/jest": "^29.5.14",
44+
"husky": "^9.1.7",
4545
"jest": "^29.7.0",
4646
"jest-environment-jsdom": "^29.7.0",
47-
"lint-staged": "^15.2.10",
48-
"mobx": "^6.13.3",
49-
"parcel": "~2.12.0",
50-
"prettier": "^3.3.3",
51-
"ts-jest": "^29.2.5",
47+
"lint-staged": "^15.5.2",
48+
"mobx": "^6.13.7",
49+
"parcel": "~2.14.4",
50+
"prettier": "^3.5.3",
51+
"ts-jest": "^29.3.2",
5252
"ts-node": "^10.9.2",
53-
"typedoc": "^0.26.8",
54-
"typedoc-plugin-mdn-links": "^3.3.2",
55-
"typescript": "~5.6.2"
53+
"typedoc": "^0.28.4",
54+
"typedoc-plugin-mdn-links": "^5.0.1",
55+
"typescript": "~5.8.3"
56+
},
57+
"pnpm": {
58+
"onlyBuiltDependencies": [
59+
"@parcel/watcher",
60+
"@swc/core"
61+
]
5662
},
5763
"prettier": {
5864
"singleQuote": true,

0 commit comments

Comments
 (0)