@@ -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
9898import { textJoin } from ' mobx-i18n' ;
99- import { compose , translator } from ' next-ssr-middleware' ;
100- import { Component } from ' react' ;
99+ import { observer } from ' mobx-react' ;
101100
102101import { 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
0 commit comments