浏览代码

added translate mecanism that can overrides tracim_lib translate resources

Skylsmoi 6 年前
父节点
当前提交
4126a7f352
共有 5 个文件被更改,包括 55 次插入3 次删除
  1. 4 2
      package.json
  2. 2 1
      src/container/Thread.jsx
  3. 31 0
      src/i18n.js
  4. 9 0
      src/translate/en.js
  5. 9 0
      src/translate/fr.js

+ 4 - 2
package.json 查看文件

@@ -24,18 +24,20 @@
24 24
     "classnames": "^2.2.5",
25 25
     "css-loader": "^0.28.7",
26 26
     "file-loader": "^1.1.5",
27
+    "i18next": "^10.5.0",
27 28
     "prop-types": "^15.6.0",
28 29
     "react": "^16.0.0",
29 30
     "react-dom": "^16.0.0",
31
+    "react-i18next": "^7.5.0",
30 32
     "standard": "^11.0.0",
31 33
     "standard-loader": "^6.0.1",
32 34
     "style-loader": "^0.19.0",
33 35
     "stylus": "^0.54.5",
34 36
     "stylus-loader": "^3.0.1",
37
+    "tracim_lib": "git://github.com/tracim/tracim_lib.git",
35 38
     "url-loader": "^0.6.2",
36 39
     "webpack": "^3.8.1",
37
-    "whatwg-fetch": "^2.0.3",
38
-    "tracim_lib": "git://github.com/tracim/tracim_lib.git"
40
+    "whatwg-fetch": "^2.0.3"
39 41
   },
40 42
   "devDependencies": {
41 43
     "webpack-dashboard": "^1.1.1",

+ 2 - 1
src/container/Thread.jsx 查看文件

@@ -9,6 +9,7 @@ import {
9 9
 } from 'tracim_lib'
10 10
 import { listMessageDebugData } from '../listMessageDebugData.js'
11 11
 import { FETCH_CONFIG } from '../helper.js'
12
+import i18n from '../i18n.js'
12 13
 
13 14
 const debug = {
14 15
   loggedUser: {
@@ -105,7 +106,7 @@ class Thread extends React.Component {
105 106
           onClickCloseBtn={this.handleClickBtnCloseApp}
106 107
         />
107 108
 
108
-        <PopinFixedOption customClass={`${appConfig.customClass}`} />
109
+        <PopinFixedOption customClass={`${appConfig.customClass}`} i18n={i18n} />
109 110
 
110 111
         <PopinFixedContent customClass={`${appConfig.customClass}__contentpage`}>
111 112
           <ThreadComponent

+ 31 - 0
src/i18n.js 查看文件

@@ -0,0 +1,31 @@
1
+import i18n from 'i18next'
2
+import { reactI18nextModule } from 'react-i18next'
3
+import { langFr, langEn } from 'tracim_lib'
4
+import fr from './translate/fr.js'
5
+import en from './translate/en.js'
6
+
7
+i18n
8
+  .use(reactI18nextModule)
9
+  .init({
10
+    fallbackLng: 'fr',
11
+    // have a common namespace used around the full app
12
+    ns: ['translation'], // namespace
13
+    defaultNS: 'translation',
14
+    debug: true,
15
+    // interpolation: {
16
+    //   escapeValue: false, // not needed for react!!
17
+    // },
18
+    react: {
19
+      wait: true
20
+    },
21
+    resources: {
22
+      en: {
23
+        translation: {...langEn.translation, ...en.translation}
24
+      },
25
+      fr: {
26
+        translation: {...langFr.translation, ...fr.translation}
27
+      }
28
+    }
29
+  })
30
+
31
+export default i18n

+ 9 - 0
src/translate/en.js 查看文件

@@ -0,0 +1,9 @@
1
+const en = {
2
+  translation: { // 'en' in the namespace 'translation'
3
+    PopinFixedOption: {
4
+      new_version: 'New version'
5
+    }
6
+  }
7
+}
8
+
9
+export default en

+ 9 - 0
src/translate/fr.js 查看文件

@@ -0,0 +1,9 @@
1
+const fr = {
2
+  translation: { // 'fr' in the namespace 'translation'
3
+    PopinFixedOption: {
4
+      new_version: 'test overrides trad from tracim_lib'
5
+    }
6
+  }
7
+}
8
+
9
+export default fr