Browse Source

added translate mecanism that can overrides tracim_lib translate resources

Skylsmoi 6 years ago
parent
commit
353217f587
5 changed files with 55 additions and 3 deletions
  1. 4 2
      package.json
  2. 2 1
      src/container/PageHtml.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 View File

@@ -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/PageHtml.jsx View File

@@ -10,6 +10,7 @@ import {
10 10
 } from 'tracim_lib'
11 11
 import { timelineDebugData } from '../timelineDebugData.js'
12 12
 import { FETCH_CONFIG } from '../helper.js'
13
+import i18n from '../i18n.js'
13 14
 
14 15
 const debug = {
15 16
   workspace: {
@@ -108,7 +109,7 @@ class pageHtml extends React.Component {
108 109
           onClickCloseBtn={this.handleClickBtnCloseApp}
109 110
         />
110 111
 
111
-        <PopinFixedOption customClass={`${appConfig.customClass}`} />
112
+        <PopinFixedOption customClass={`${appConfig.customClass}`} i18n={i18n} />
112 113
 
113 114
         <PopinFixedContent customClass={`${appConfig.customClass}__contentpage`}>
114 115
           <PageHtmlComponent

+ 31 - 0
src/i18n.js View File

@@ -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 View File

@@ -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 View File

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