summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDessalines <happydooby@gmail.com>2019-08-07 11:01:26 -0700
committerDessalines <happydooby@gmail.com>2019-08-07 11:01:26 -0700
commit7e84f9a0c4274b3182dbf7c13a91aa52dde3fa89 (patch)
treefed6206a7d2b287d3f4ae1e5a5af60d49eadfacd
parent59a0dd8caf4143d038cc809b9bb9cbde738bab9a (diff)
Starting to work on internationalization
-rw-r--r--ui/fuse.js5
-rw-r--r--ui/package.json3
-rw-r--r--ui/src/components/main.tsx46
-rw-r--r--ui/src/i18n.ts32
-rw-r--r--ui/src/i18next.ts40
-rw-r--r--ui/src/index.tsx6
-rw-r--r--ui/yarn.lock104
7 files changed, 158 insertions, 78 deletions
diff --git a/ui/fuse.js b/ui/fuse.js
index cc2a206d..4755d9f5 100644
--- a/ui/fuse.js
+++ b/ui/fuse.js
@@ -24,11 +24,6 @@ Sparky.task('config', _ => {
transformers: {
before: [transformClasscat(), transformInferno()],
},
- alias: {
- 'react': 'inferno-compat',
- 'react-dom': 'inferno-compat',
- 'react-redux': 'inferno-compat',
- },
plugins: [
EnvPlugin({ NODE_ENV: isProduction ? 'production' : 'development' }),
CSSPlugin(),
diff --git a/ui/package.json b/ui/package.json
index 9ff9ebba..180d80ef 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -20,11 +20,12 @@
"@types/jwt-decode": "^2.2.1",
"@types/markdown-it": "^0.0.7",
"@types/markdown-it-container": "^2.0.2",
- "@types/react-i18next": "^8.1.0",
"autosize": "^4.0.2",
"classcat": "^1.1.3",
"dotenv": "^6.1.0",
"inferno": "^7.0.1",
+ "inferno-router": "^7.0.1",
+ "i18next": "^17.0.9",
"inferno-i18next": "nimbusec-oss/inferno-i18next",
"js-cookie": "^2.2.0",
"jwt-decode": "^2.2.0",
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx
index c513fc5c..73d6deac 100644
--- a/ui/src/components/main.tsx
+++ b/ui/src/components/main.tsx
@@ -7,8 +7,6 @@ import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
import { SiteForm } from './site-form';
import { msgOp, repoUrl, mdToHtml, fetchLimit, routeSortTypeToEnum, routeListingTypeToEnum } from '../utils';
-import { useTranslation } from 'react-i18next';
-const { t } = useTranslation();
interface MainState {
subscribedCommunities: Array<CommunityUser>;
@@ -122,26 +120,34 @@ export class Main extends Component<any, MainState> {
{this.posts()}
</div>
<div class="col-12 col-md-4">
- {!this.state.loading &&
+ {this.my_sidebar()}
+ </div>
+ </div>
+ </div>
+ )
+ }
+
+ my_sidebar() {
+ return(
+ <div>
+ {!this.state.loading &&
+ <div>
+ {this.trendingCommunities()}
+ {UserService.Instance.user && this.state.subscribedCommunities.length > 0 &&
<div>
- {this.trendingCommunities()}
- {UserService.Instance.user && this.state.subscribedCommunities.length > 0 &&
- <div>
- <h5>Subscribed <Link class="text-white" to="/communities">communities</Link></h5>
- <ul class="list-inline">
- {this.state.subscribedCommunities.map(community =>
- <li class="list-inline-item"><Link to={`/c/${community.community_name}`}>{community.community_name}</Link></li>
- )}
- </ul>
- </div>
- }
- <Link class="btn btn-sm btn-secondary btn-block mb-3"
- to="/create_community">Create a Community</Link>
- {this.sidebar()}
+ <h5><T i18nKey="subscribed_to_communities">#<Link class="text-white" to="/communities">#</Link></T></h5>
+ <ul class="list-inline">
+ {this.state.subscribedCommunities.map(community =>
+ <li class="list-inline-item"><Link to={`/c/${community.community_name}`}>{community.community_name}</Link></li>
+ )}
+ </ul>
</div>
}
- </div>
- </div>
+ <Link class="btn btn-sm btn-secondary btn-block mb-3"
+ to="/create_community"><T i18nKey="create_a_community"> </T></Link>
+ {this.sidebar()}
+ </div>
+ }
</div>
)
}
@@ -149,7 +155,7 @@ export class Main extends Component<any, MainState> {
trendingCommunities() {
return (
<div>
- <h5>{t('Trending')} <Link class="text-white" to="/communities">communities</Link></h5>
+ {/* <h5>{t('Trending')} <Link class="text-white" to="/communities">communities</Link></h5> */}
<ul class="list-inline">
{this.state.trendingCommunities.map(community =>
<li class="list-inline-item"><Link to={`/c/${community.name}`}>{community.name}</Link></li>
diff --git a/ui/src/i18n.ts b/ui/src/i18n.ts
deleted file mode 100644
index 46604e91..00000000
--- a/ui/src/i18n.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import i18n from "i18next";
-import { initReactI18next } from "inferno-i18next";
-
-// the translations
-// (tip move them in a JSON file and import them)
-const resources = {
- en: {
- translation: {
- trending: "Trending",
- }
- },
- es: {
- translation: {
- trending: "Trending, but in spanish",
- }
- }
-};
-
-i18n
- .use(initReactI18next) // passes i18n down to react-i18next
- .init({
- resources,
- lng: "en",
-
- keySeparator: false, // we do not use keys in form messages.welcome
-
- interpolation: {
- escapeValue: false // react already safes from xss
- }
- });
-
-export default i18n;
diff --git a/ui/src/i18next.ts b/ui/src/i18next.ts
new file mode 100644
index 00000000..b2eb9688
--- /dev/null
+++ b/ui/src/i18next.ts
@@ -0,0 +1,40 @@
+import * as i18next from 'i18next';
+
+const resources = {
+ en: {
+ translation: {
+ trending: 'NO',
+ subscribed_to_communities:'Subscribed to <1>communities</1>',
+ create_a_community: 'Create a community',
+
+
+
+
+
+
+ foo: 'foo',
+ bar: '<1>bar</1>',
+ baz: '<1>{{count}}</1>',
+ qux: 'qux<1></1>',
+ qux_plural: 'quxes<1></1>',
+ quux: '<1>{{name, uppercase}}</1>',
+ userMessagesUnread: 'Hello <1>{{name}}</1>, you have {{count}} unread messages. <3>Go to messages</3>.',
+ userMessagesUnread_plural: 'Hello <1>{{name}}</1>, you have {{count}} unread messages. <3>Go to messages</3>.'
+ },
+ },
+};
+
+function format(value: any, format: any, lng: any) {
+ if (format === 'uppercase') return value.toUpperCase();
+ return value;
+}
+
+i18next.init({
+ lng: 'en',
+ resources,
+ interpolation: {
+ format: format
+ }
+});
+
+export { i18next, resources };
diff --git a/ui/src/index.tsx b/ui/src/index.tsx
index a13b84f8..2067c06b 100644
--- a/ui/src/index.tsx
+++ b/ui/src/index.tsx
@@ -1,5 +1,5 @@
import { render, Component } from 'inferno';
-import { HashRouter, BrowserRouter, Route, Switch } from 'inferno-router';
+import { BrowserRouter, Route, Switch } from 'inferno-router';
import { Provider } from 'inferno-i18next';
import { Main } from './components/main';
import { Navbar } from './components/navbar';
@@ -17,7 +17,7 @@ import { Inbox } from './components/inbox';
import { Search } from './components/search';
import { Sponsors } from './components/sponsors';
import { Symbols } from './components/symbols';
-import './i18n';
+import { i18next } from './i18next';
import './css/bootstrap.min.css';
import './css/main.css';
@@ -36,7 +36,7 @@ class Index extends Component<any, any> {
render() {
return (
- <Provider i18next={i18n}>
+ <Provider i18next={i18next}>
<BrowserRouter>
<Navbar />
<div class="mt-1 p-0">
diff --git a/ui/yarn.lock b/ui/yarn.lock
index ccec64e9..f47c16c4 100644
--- a/ui/yarn.lock
+++ b/ui/yarn.lock
@@ -2,7 +2,7 @@
# yarn lockfile v1
-"@babel/runtime@^7.3.1":
+"@babel/runtime@^7.1.2", "@babel/runtime@^7.3.1":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==
@@ -64,13 +64,6 @@
dependencies:
"@types/linkify-it" "*"
-"@types/react-i18next@^8.1.0":
- version "8.1.0"
- resolved "https://registry.yarnpkg.com/@types/react-i18next/-/react-i18next-8.1.0.tgz#5faacbfe7dc0f24729c1df6914610bfe861a50de"
- integrity sha512-d4xhcjX5b3roNMObRNMfb1HinHQlQLPo8xlDj60dnHeeAw2bBymR2cy/l1giJpHzo/ZFgSvgVUvIWr4kCrenCg==
- dependencies:
- react-i18next "*"
-
"@types/sizzle@*":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
@@ -1164,7 +1157,24 @@ has-values@^1.0.0:
is-number "^3.0.0"
kind-of "^4.0.0"
-html-parse-stringify2@2.0.1, html-parse-stringify2@^2.0.1:
+history@^4.9.0:
+ version "4.9.0"
+ resolved "https://registry.yarnpkg.com/history/-/history-4.9.0.tgz#84587c2068039ead8af769e9d6a6860a14fa1bca"
+ integrity sha512-H2DkjCjXf0Op9OAr6nJ56fcRkTSNrUiv41vNJ6IswJjif6wlpZK0BTfFbi7qK9dXLSYZxkq5lBsj3vUjlYBYZA==
+ dependencies:
+ "@babel/runtime" "^7.1.2"
+ loose-envify "^1.2.0"
+ resolve-pathname "^2.2.0"
+ tiny-invariant "^1.0.2"
+ tiny-warning "^1.0.0"
+ value-equal "^0.4.0"
+
+hoist-non-inferno-statics@^1.1.3:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/hoist-non-inferno-statics/-/hoist-non-inferno-statics-1.1.3.tgz#7d870f4160bfb6a59269b45c343c027f0e30ab35"
+ integrity sha1-fYcPQWC/tqWSabRcNDwCfw4wqzU=
+
+html-parse-stringify2@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/html-parse-stringify2/-/html-parse-stringify2-2.0.1.tgz#dc5670b7292ca158b7bc916c9a6735ac8872834a"
integrity sha1-3FZwtyksoVi3vJFsmmc1rIhyg0o=
@@ -1202,6 +1212,13 @@ http-signature@~1.2.0:
jsprim "^1.2.2"
sshpk "^1.7.0"
+i18next@^17.0.9:
+ version "17.0.9"
+ resolved "https://registry.yarnpkg.com/i18next/-/i18next-17.0.9.tgz#5f835e91a34fa5e7da1e5ae4c4586c81d7c4b17f"
+ integrity sha512-fCYpm3TDzcfPIPN3hmgvC/QJx17QHI+Ul88qbixwIrifN9nBmk2c2oVxVYSDxnV5FgBXZJJ0O4yBYiZ8v1bX2A==
+ dependencies:
+ "@babel/runtime" "^7.3.1"
+
iconv-lite@0.4.24, iconv-lite@^0.4.17, iconv-lite@^0.4.4:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -1246,6 +1263,16 @@ inferno-i18next@nimbusec-oss/inferno-i18next:
inferno-shared "^7.1.12"
inferno-vnode-flags "^7.1.12"
+inferno-router@^7.0.1:
+ version "7.2.1"
+ resolved "https://registry.yarnpkg.com/inferno-router/-/inferno-router-7.2.1.tgz#ebea346a31422ed141df7177fb0b5aeb06cf8fe3"
+ integrity sha512-8DMIhAvMVfvFSax+uNsTYCWOktqMIM952EsYRn5V0LMYvnJtUczJH77vSCe1DF4o1jK+/kf9KLNfa1QPQC/CQg==
+ dependencies:
+ history "^4.9.0"
+ hoist-non-inferno-statics "^1.1.3"
+ inferno "7.2.1"
+ path-to-regexp-es6 "1.7.0"
+
inferno-shared@7.2.1, inferno-shared@^7.1.12:
version "7.2.1"
resolved "https://registry.yarnpkg.com/inferno-shared/-/inferno-shared-7.2.1.tgz#7512d626e252a4e0e3ea28f0396a815651226ed6"
@@ -1470,6 +1497,11 @@ is-windows@^1.0.2:
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==
+isarray@0.0.1:
+ version "0.0.1"
+ resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
+ integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=
+
isarray@1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -1497,6 +1529,11 @@ js-cookie@^2.2.0:
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.0.tgz#1b2c279a6eece380a12168b92485265b35b1effb"
integrity sha1-Gywnmm7s44ChIWi5JIUmWzWx7/s=
+"js-tokens@^3.0.0 || ^4.0.0":
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
+ integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
+
jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
@@ -1595,6 +1632,13 @@ lodash@^4.3.0:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
+loose-envify@^1.2.0:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
+ integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
+ dependencies:
+ js-tokens "^3.0.0 || ^4.0.0"
+
map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
@@ -2017,11 +2061,25 @@ path-is-absolute@^1.0.0:
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
+path-to-regexp-es6@1.7.0:
+ version "1.7.0"
+ resolved "https://registry.yarnpkg.com/path-to-regexp-es6/-/path-to-regexp-es6-1.7.0.tgz#965657c9f8ea8f660e103ccb839abf038cba4caf"
+ integrity sha512-QdT7okCAMGv7FR7w6KWFH9OSMivOgtXAGKodD6MDZBNR/XNL16W+hHoj6qBmV6cy/7eR1fr0Qujrg9OhBf5QPw==
+ dependencies:
+ path-to-regexp "1.7.0"
+
path-to-regexp@0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=
+path-to-regexp@1.7.0:
+ version "1.7.0"
+ resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
+ integrity sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=
+ dependencies:
+ isarray "0.0.1"
+
performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -2136,14 +2194,6 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
-react-i18next@*:
- version "10.11.5"
- resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-10.11.5.tgz#10d0726a6c63c2d928078a7e7ec3db708246be04"
- integrity sha512-+LXYehLGWbOzM4on9pgeCMTmo7J24Pm2rio4S8OSVdYudUKxLSYzoMDgJect0SQbTlIiK6b6+OTgTGY4YKPECw==
- dependencies:
- "@babel/runtime" "^7.3.1"
- html-parse-stringify2 "2.0.1"
-
readable-stream@^2.0.2, readable-stream@^2.0.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
@@ -2271,6 +2321,11 @@ request@^2.79.0:
tunnel-agent "^0.6.0"
uuid "^3.3.2"
+resolve-pathname@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-2.2.0.tgz#7e9ae21ed815fd63ab189adeee64dc831eefa879"
+ integrity sha512-bAFz9ld18RzJfddgrO2e/0S2O81710++chRMUxHjXOYKF6jTAMrUNZrEZ1PvV0zlhfjidm08iRPdTLPno1FuRg==
+
resolve-url@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
@@ -2614,6 +2669,16 @@ through@^2.3.6:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
+tiny-invariant@^1.0.2:
+ version "1.0.6"
+ resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.0.6.tgz#b3f9b38835e36a41c843a3b0907a5a7b3755de73"
+ integrity sha512-FOyLWWVjG+aC0UqG76V53yAWdXfH8bO6FNmyZOuUrzDzK8DI3/JRY25UD7+g49JWM1LXwymsKERB+DzI0dTEQA==
+
+tiny-warning@^1.0.0:
+ version "1.0.3"
+ resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
+ integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==
+
tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
@@ -2811,6 +2876,11 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
+value-equal@^0.4.0:
+ version "0.4.0"
+ resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-0.4.0.tgz#c5bdd2f54ee093c04839d71ce2e4758a6890abc7"
+ integrity sha512-x+cYdNnaA3CxvMaTX0INdTCN8m8aF2uY9BvEqmxuYp8bL09cs/kWVQPVGcA35fMktdOsP69IgU7wFj/61dJHEw==
+
vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"