From 84907b535fc1dfb2968493f03719b3f21546d9d3 Mon Sep 17 00:00:00 2001 From: clj Date: Wed, 18 Mar 2020 12:49:49 +0800 Subject: [PATCH 1/2] Add chinese with i18n --- package.json | 3 +- public/index.html | 1 + src/App.jsx | 10 +++- src/Main.jsx | 126 +++++++++++++++++++++++----------------------- src/i18n/en.json | 64 +++++++++++++++++++++++ src/i18n/zh.json | 64 +++++++++++++++++++++++ src/index.js | 14 ++++++ 7 files changed, 215 insertions(+), 67 deletions(-) create mode 100644 src/i18n/en.json create mode 100644 src/i18n/zh.json diff --git a/package.json b/package.json index 8f1daf9c..f378bde4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "react": "^16.13.0", "react-dom": "^16.13.0", "react-router-dom": "^5.1.2", - "react-scripts": "^3.4.0" + "react-scripts": "^3.4.0", + "react-intl-universal": "2.2.2" }, "scripts": { "predeploy": "npm run build", diff --git a/public/index.html b/public/index.html index e28e15d1..baec75ee 100644 --- a/public/index.html +++ b/public/index.html @@ -78,6 +78,7 @@ who loves numbers and loves you

With many amazing PRs from @iamchrissmith and @brianmcmichael

+

With an awesome language contribution of @xiaopao

Take a look at the Source code

diff --git a/src/App.jsx b/src/App.jsx index cff409e3..f80cc0cd 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,5 @@ import React, { Component } from 'react' +import intl from 'react-intl-universal' import { BrowserRouter as Router, Switch, @@ -325,9 +326,14 @@ class App extends Component { const combo = duty.add(base); return this.calcFee(combo); } + ethApi = eapi => intl.get('ethapi') + getEthApi = () => { + return intl.get('ethapi') + } etherscanEthSupply = async () => { - const json = await jsonFetch('https://api.etherscan.io/api?action=ethsupply&module=stats&apikey=N5TICDBVG4MHDS7CGPJ9MHXRYC1Y84963N'); + const ethapi = intl.get('ethapi') + const json = await jsonFetch(ethapi+'/api?action=ethsupply&module=stats&apikey=N5TICDBVG4MHDS7CGPJ9MHXRYC1Y84963N'); return json.result; } @@ -388,7 +394,7 @@ class App extends Component {
15% -

One sec, fetching data from Ethereum Mainnet

+

{intl.get('One_sec')}

) diff --git a/src/Main.jsx b/src/Main.jsx index a8b040cd..1eacde12 100644 --- a/src/Main.jsx +++ b/src/Main.jsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from 'react' +import intl from 'react-intl-universal' import HealButton from './components/HealButton'; import FlapButton from './components/FlapButton'; import BurnButton from './components/BurnButton'; @@ -73,9 +74,9 @@ const Main = (props) => {
{ /* eslint-disable-next-line */ } - Block: {props.blockNumber}. {props.paused ? 'Paused.' : 'Auto-updating.'} {props.paused ? 'Restart' : 'Pause'} + {intl.get('Block')}: {props.blockNumber}. {props.paused ? intl.get('Paused')+'.' : intl.get('Auto-updating')+'.'} {props.paused ? intl.get('Restart') : intl.get('Pause') }
- USDC is here, lock it up! + {intl.get('USDC_here')} {/* watch my ETHDenver 2020 talk ;) */}
@@ -104,13 +105,13 @@ const Main = (props) => {

{formatAmount.format(props.debt)}

-

Total Dai

+

{intl.get('Total_Dai')}

{formatAmount.format(props.saiSupply)}

-

Total Sai

+

{intl.get('Total_Sai')}

@@ -132,7 +133,7 @@ const Main = (props) => {

{formatAmount.format(props.ilks[0].Art * props.ilks[0].rate)}

-

Dai from ETH +

{intl.get('Dai_from_ETH')} ({formatAmount.format(props.ilks[0].Art * props.ilks[0].rate / props.debt * 100)}%)

@@ -140,14 +141,14 @@ const Main = (props) => {

{formatAmount.format(props.ilks[1].Art * props.ilks[1].rate)}

-

Dai from BAT +

{intl.get('Dai_from_BAT')} ({formatAmount.format(props.ilks[1].Art * props.ilks[1].rate / props.debt * 100)}%)

{formatAmount.format(props.ilks[2].Art)}

-

Dai from Migration +

{intl.get('Dai_from_Migration')} ({formatAmount.format(props.ilks[2].Art * props.ilks[2].rate / props.debt * 100)}%)

@@ -155,7 +156,7 @@ const Main = (props) => {

{formatAmount.format(props.ilks[3].Art * props.ilks[3].rate)}

-

Dai from USDC +

{intl.get('Dai_from_USDC')} ({formatAmount.format(props.ilks[3].Art * props.ilks[3].rate / props.debt * 100)}%)

@@ -164,24 +165,23 @@ const Main = (props) => {

{formatNoDecimals.format(props.ethLocked)}

-

ETH Locked (in ETH)

-

ETH Supply - Locked: {formatPercent.format(props.ethLocked / props.ethSupply)}

+

{intl.get('ETH_Locked')}

+

{intl.get('ETH_Supply_Locked')}: {formatPercent.format(props.ethLocked / props.ethSupply)}

{formatAmount.format(props.ilks[0].line)}

-

ETH Ceiling (in Dai)

+

{intl.get('ETH_Ceiling')}

Utilization: {formatAmount.format(props.ilks[0].Art * props.ilks[0].rate / props.ilks[0].line * 100)}%

+ className="subtitle is-size-6">{intl.get('Utilization')}: {formatAmount.format(props.ilks[0].Art * props.ilks[0].rate / props.ilks[0].line * 100)}%

{props.ethFee}%

-

ETH Stability Fee

-

Last Drip: {props.jugEthDrip}

+

{intl.get('ETH_Stability_Fee')}

+

{intl.get('Last_Drip')}: {props.jugEthDrip}

@@ -189,24 +189,23 @@ const Main = (props) => {

{formatNoDecimals.format(props.batLocked)}

-

BAT Locked (in BAT)

-

BAT Supply - Locked: {formatPercent.format(props.batLocked / props.batSupply)}

+

{intl.get('BAT_Locked')}

+

{intl.get('BAT_Supply_Locked')}: {formatPercent.format(props.batLocked / props.batSupply)}

{formatAmount.format(props.ilks[1].line)}

-

BAT Ceiling (in Dai)

+

{intl.get('BAT_Ceiling')}

Utilization: {formatAmount.format(props.ilks[1].Art * props.ilks[1].rate / props.ilks[1].line * 100)}%

+ className="subtitle is-size-6">{intl.get('Utilization')}: {formatAmount.format(props.ilks[1].Art * props.ilks[1].rate / props.ilks[1].line * 100)}%

{props.batFee}%

-

BAT Stability Fee

-

Last Drip: {props.jugBatDrip}

+

{intl.get('BAT_Stability_Fee')}

+

{intl.get('Last_Drip')}: {props.jugBatDrip}

@@ -214,24 +213,23 @@ const Main = (props) => {

{formatNoDecimals.format(props.usdcLocked)}

-

USDC Locked (in USDC)

-

USDC Supply - Locked: {formatPercent.format(props.usdcLocked / props.usdcSupply)}

+

{intl.get('USDC_Locked')}

+

{intl.get('USDC_Supply_Locked')}: {formatPercent.format(props.usdcLocked / props.usdcSupply)}

{formatAmount.format(props.ilks[3].line)}

-

USDC Ceiling (in Dai)

+

{intl.get('USDC_Ceiling')}

Utilization: {formatAmount.format(props.ilks[3].Art * props.ilks[3].rate / props.ilks[3].line * 100)}%

+ className="subtitle is-size-6">{intl.get('Utilization')}: {formatAmount.format(props.ilks[3].Art * props.ilks[3].rate / props.ilks[3].line * 100)}%

{props.usdcFee}%

-

USDC Stability Fee

-

Last Drip: {props.jugUsdcDrip}

+

{intl.get('USDC_Stability_Fee')}

+

{intl.get('Last_Drip')}: {props.jugUsdcDrip}

@@ -239,14 +237,14 @@ const Main = (props) => {

{formatAmount.format(props.daiSupply)}

-

Dai (ERC20) Supply ({formatAmount.format(props.daiSupply / props.debt * 100)}%)

+

{intl.get('Dai_ERC20_Supply')} ({formatAmount.format(props.daiSupply / props.debt * 100)}%)

{formatPercent.format(sysCollat)}

-

Collat. Ratio

-

Total Locked: ${formatAmount.format(props.sysLocked)}

+

{intl.get('Collat_Ratio')}

+

{intl.get('Total_Locked')}: ${formatAmount.format(props.sysLocked)}

@@ -254,33 +252,33 @@ const Main = (props) => {

${formatCurrency.format(props.daiPrice)}

-

Dai Price

+

{intl.get('Dai_Price')}

${formatAmount.format(props.ethPrice)}

-

ETH Price

-

Next OSM Price: ${formatAmount.format(props.ethPriceNxt)}

+

{intl.get('ETH_Price')}

+

{intl.get('Next_OSM_Price')}: ${formatAmount.format(props.ethPriceNxt)}

${formatCurrency.format(props.batPrice)}

-

BAT Price

-

Next OSM Price: ${formatCurrency.format(props.batPriceNxt)}

+

{intl.get('BAT_Price')}

+

{intl.get('Next_OSM_Price')}: ${formatCurrency.format(props.batPriceNxt)}

${formatCurrency.format(props.usdcPrice)}

-

USDC Price

+

{intl.get('USDC_Price')}

${formatCurrency.format(props.mkrPrice)}

-

MKR Price

+

{intl.get('MKR_Price')}

@@ -289,17 +287,17 @@ const Main = (props) => {

{formatAmount.format(props.savingsDai)}

-

Dai in DSR +

{intl.get('Dai_in_DSR')} ({formatAmount.format(props.savingsDai / props.debt * 100)}%)

-

(Pie in DSR: {formatAmount.format(props.savingsPie)})

+

({intl.get('Pie_in_DSR')}: {formatAmount.format(props.savingsPie)})

{props.potFee}%

-

Dai Savings Rate

-

Last Drip: {props.potDrip}

+

{intl.get('Dai_Savings_Rate')}

+

{intl.get('Last_Drip')}: {props.potDrip}

@@ -307,24 +305,24 @@ const Main = (props) => {

{formatAmount.format(props.sysDebt)}

-

Debt available to heal (Dai)

-

Debt Buffer: {formatAmount.format(props.debtSize)}

+

{intl.get('Debt_available_to_heal')} (Dai)

+

{intl.get('Debt_Buffer')}: {formatAmount.format(props.debtSize)}

{(props.networkId === 1) && }

{formatAmount.format(props.sysSurplus)}

-

System Surplus (Dai)

-

Surplus Buffer: {formatAmount.format(props.surplusBuffer)} / Lot: {formatAmount.format(props.surplusBump)}

+

{intl.get('System_Surplus')} (Dai)

+

{intl.get('Surplus_Buffer')}: {formatAmount.format(props.surplusBuffer)} / {intl.get('Lot')}: {formatAmount.format(props.surplusBump)}

{(props.networkId === 1) && }

{formatAmount.format(props.flapKicks)}

-

Dai Surplus (Flap) Auctions

-

Till next Flap Possible: {nextFlap()}

+

{intl.get('Dai_Surplus_Flap_Auctions')}

+

{intl.get('Till_next_Flap_Possible')}: {nextFlap()}

@@ -332,28 +330,28 @@ const Main = (props) => {

{props.cdps}

-

Vaults Opened

+

{intl.get('Vaults_Opened')}

{formatAmount.format(props.ethKicks)}

-

ETH Vault Auctions

+

{intl.get('ETH_Vault_Auctions')}

{formatAmount.format(props.batKicks)}

-

BAT Vault Auctions

+

{intl.get('BAT_Vault_Auctions')}

{formatAmount.format(props.flopKicks)}

-

Debt (Flop) Auctions

-

Initial Lot Size: {formatAmount.format(props.debtDump)} MKR Initial Price: ${formatAmount.format(props.debtSize / props.debtDump)}

+

{intl.get('Debt_Flop_Auctions')}

+

{intl.get('Initial_Lot_Size')}: {formatAmount.format(props.debtDump)} {intl.get('MKR_Initial_Price')}: ${formatAmount.format(props.debtSize / props.debtDump)}

@@ -361,20 +359,20 @@ const Main = (props) => {

{formatAmount.format(props.mkrSupply)}

-

MKR Supply

+

{intl.get('MKR_Supply')}

{formatAmount.format(props.gemPit)}

-

MKR in Burner

+

{intl.get('MKR_in_Burner')}

{(props.networkId === 1 && props.gemPit > 0.01) && }

{formatAmount.format(props.mkrAnnualBurn)}

-

Annual MKR Burn Rate

+

{intl.get('Annual_MKR_Burn_Rate')}

${formatAmount.format(props.mkrAnnualBurn * props.mkrPrice)} USD

@@ -383,21 +381,21 @@ const Main = (props) => {

{formatAmount.format(props.chaiSupply)}

-

Total Chai 🍵

-

(Dai brewing: {formatAmount.format(props.daiBrewing)})

+

{intl.get('Total_Chai')} 🍵

+

({intl.get('Dai_brewing')}: {formatAmount.format(props.daiBrewing)})

{formatAmount.format(props.uniswapDai)}

-

Dai in Uniswap

+

{intl.get('Dai_in_Uniswap')}

- +

Dai

{props.MCD_DAI}

@@ -405,7 +403,7 @@ const Main = (props) => {
- +

BAT

{props.BAT}

@@ -413,7 +411,7 @@ const Main = (props) => {
- +

USDC

{props.USDC}

@@ -421,7 +419,7 @@ const Main = (props) => {
- +

MKR

{props.MCD_GOV}

diff --git a/src/i18n/en.json b/src/i18n/en.json new file mode 100644 index 00000000..37432f67 --- /dev/null +++ b/src/i18n/en.json @@ -0,0 +1,64 @@ +{ + "One_sec":"One sec, fetching data from Ethereum Mainnet", + "Block":"Block", + "Paused":"Paused", + "Auto-updating":"Auto-updating", + "Restart":"Restart", + "Pause":"Pause", + "USDC_here":"USDC is here, lock it up", + "Total_Dai":"Total Dai", + "Total_Sai":"Total Sai", + "Dai_from_ETH":"Dai from ETH", + "Dai_from_BAT":"Dai from BAT", + "Dai_from_Migration":"Dai from Migration", + "Dai_from_USDC":"Dai from USDC", + "ETH_Locked":"ETH Locked (in ETH)", + "ETH_Supply_Locked":"ETH Supply Locked", + "ETH_Ceiling":"ETH Ceiling (in Dai)", + "Utilization":"Utilization", + "ETH_Stability_Fee":"ETH Stability Fee", + "Last_Drip":"Last Drip", + "BAT_Locked":"BAT Locked (in BAT)", + "BAT_Supply_Locked":"BAT Supply Locked", + "BAT_Ceiling":"BAT Ceiling (in Dai)", + "BAT_Stability_Fee":"BAT Stability Fee", + "USDC_Locked":"USDC Locked (in USDC)", + "USDC_Supply_Locked":"USDC Supply Locked", + "USDC_Ceiling":"USDC Ceiling (in Dai)", + "USDC_Stability_Fee":"USDC Stability Fee", + "Dai_ERC20_Supply":"Dai (ERC20) Supply", + "Collat_Ratio":"Collat. Ratio", + "Total_Locked":"Total Locked", + "Dai_Price":"Dai Price", + "ETH_Price":"ETH Price", + "Next_OSM_Price":"Next OSM Price", + "BAT_Price":"BAT Price", + "USDC_Price":"USDC Price", + "MKR_Price":"MKR Price", + "Dai_in_DSR":"Dai in DSR", + "Pie_in_DSR":"Pie in DSR", + "Dai_Savings_Rate":"Dai Savings Rate", + "Debt_available_to_heal":"Debt available to heal", + "Debt_Buffer":"Debt Buffer", + "System_Surplus":"System Surplus", + "Surplus_Buffer":"Surplus Buffer", + "Lot":"Lot", + "Dai_Surplus_Flap_Auctions":"Dai Surplus (Flap) Auctions", + "Till_next_Flap_Possible":"Till next Flap Possible", + "Vaults_Opened":"Vaults Opened", + "ETH_Vault_Auctions":"ETH Vault Auctions", + "BAT_Vault_Auctions":"BAT Vault Auctions", + "Debt_Flop_Auctions":"Debt (Flop) Auctions", + "Initial_Lot_Size":"Initial Lot Size", + "MKR_Initial_Price":"MKR Initial Price", + "MKR_Supply":"MKR Supply", + "MKR_in_Burner":"MKR in Burner", + "Annual_MKR_Burn_Rate":"Annual MKR Burn Rate", + "Total_Chai":"Total Chai", + "Dai_brewing":"Dai brewing", + "Dai_in_Uniswap":"Dai in Uniswap", + + "ethapi":"https://api.etherscan.io", + "ethscan":"https://etherscan.io" + +} \ No newline at end of file diff --git a/src/i18n/zh.json b/src/i18n/zh.json new file mode 100644 index 00000000..92894834 --- /dev/null +++ b/src/i18n/zh.json @@ -0,0 +1,64 @@ +{ + "One_sec":"请等待几秒,正在从以太坊主网加载数据", + "Block":"区块", + "Paused":"已停止", + "Auto-updating":"自动更新中", + "Restart":"重启", + "Pause":"暂停", + "USDC_here":"USDC已上线,快来锁仓吧!", + "Total_Dai":"总计Dai", + "Total_Sai":"总计Sai", + "Dai_from_ETH":"来源于ETH的Dai", + "Dai_from_BAT":"来源于BAT的Dai", + "Dai_from_Migration":"来源于迁移的Dai", + "Dai_from_USDC":"来源于USDC的Dai", + "ETH_Locked":"已锁定ETH(单位ETH)", + "ETH_Supply_Locked":"占ETH供应量锁定比例", + "ETH_Ceiling":"ETH上限(单位Dai)", + "Utilization":"利用率", + "ETH_Stability_Fee":"ETH稳定费率", + "Last_Drip":"最新更新", + "BAT_Locked":"已锁定BAT(单位BAT)", + "BAT_Supply_Locked":"占BAT供应量锁定比例", + "BAT_Ceiling":"BAT上限(单位Dai)", + "BAT_Stability_Fee":"BAT稳定费率", + "USDC_Locked":"已锁定USDC(单位USDC)", + "USDC_Supply_Locked":"占USDC供应量锁定比例", + "USDC_Ceiling":"USDC上限(单位Dai)", + "USDC_Stability_Fee":"USDC稳定费率", + "Dai_ERC20_Supply":"Dai供应量(ERC20)", + "Collat_Ratio":"抵押率", + "Total_Locked":"总计锁定", + "Dai_Price":"Dai价格", + "ETH_Price":"ETH价格", + "Next_OSM_Price":"下次OSM喂价", + "BAT_Price":"BAT价格", + "USDC_Price":"USDC价格", + "MKR_Price":"MKR价格", + "Dai_in_DSR":"储蓄中的Dai", + "Pie_in_DSR":"储蓄中享有利息的Dai", + "Dai_Savings_Rate":"Dai储蓄利率", + "Debt_available_to_heal":"可治愈的债务", + "Debt_Buffer":"债务缓冲", + "System_Surplus":"系统盈余", + "Surplus_Buffer":"盈余缓冲", + "Lot":"批", + "Dai_Surplus_Flap_Auctions":"Dai盈余拍卖(Flap)", + "Till_next_Flap_Possible":"目前将要被盈余拍卖的", + "Vaults_Opened":"开启的金库", + "ETH_Vault_Auctions":"ETH金库拍卖", + "BAT_Vault_Auctions":"BAT金库拍卖", + "Debt_Flop_Auctions":"债务拍卖(Flop)", + "Initial_Lot_Size":"初始批大小", + "MKR_Initial_Price":"MKR初始价格", + "MKR_Supply":"MKR供应量", + "MKR_in_Burner":"销毁池中的MKR", + "Annual_MKR_Burn_Rate":"MKR年度销毁量", + "Total_Chai":"总计Chai", + "Dai_brewing":"酝酿中的Dai", + "Dai_in_Uniswap":"Uniswap中的Dai", + + "ethapi":"https://ethapi.xiaopao.gq", + "ethscan":"https://cn.etherscan.com" + +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 342eee20..96d692cd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,22 @@ import React from 'react'; import ReactDOM from 'react-dom'; // import './index.css'; +import intl from 'react-intl-universal'; import App from './App'; import * as serviceWorker from './serviceWorker'; +import zh from './i18n/zh.json' +import en from './i18n/en.json' + +let lang = (navigator.languages && navigator.languages[0]) || navigator.language +intl.init({ + currentLocale: lang.split('-')[0], + locales: { + zh, + en + } +}) + + ReactDOM.render(, document.getElementById('root')); From 6cbc7d8675e7daff04bd8523f794719e1cba1cfe Mon Sep 17 00:00:00 2001 From: clj Date: Fri, 20 Mar 2020 12:50:26 +0800 Subject: [PATCH 2/2] update --- src/App.jsx | 5 +---- src/Main.jsx | 4 ++-- src/i18n/en.json | 2 ++ src/i18n/zh.json | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 6256cd2b..d8f1bd40 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -330,10 +330,7 @@ class App extends Component { const combo = duty.add(base); return this.calcFee(combo); } - ethApi = eapi => intl.get('ethapi') - getEthApi = () => { - return intl.get('ethapi') - } + etherscanEthSupply = async () => { const ethapi = intl.get('ethapi') diff --git a/src/Main.jsx b/src/Main.jsx index df92e64a..ee1cf20c 100644 --- a/src/Main.jsx +++ b/src/Main.jsx @@ -89,10 +89,10 @@ const Main = (props) => {
-

MKR Debt Auction start Thursday March 19 around 10:28 ET (14:28 UTC)

+

{intl.get('MKR_Debt_Auction_start')}

- Read more about it on the Maker Blog + {intl.get('Read_Maker_blog')}

diff --git a/src/i18n/en.json b/src/i18n/en.json index 37432f67..65647f8b 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -6,6 +6,8 @@ "Restart":"Restart", "Pause":"Pause", "USDC_here":"USDC is here, lock it up", + "MKR_Debt_Auction_start":"MKR Debt Auction start Thursday March 19 around 10:28 ET (14:28 UTC)", + "Read_Maker_blog":"Read more about it on the Maker Blog", "Total_Dai":"Total Dai", "Total_Sai":"Total Sai", "Dai_from_ETH":"Dai from ETH", diff --git a/src/i18n/zh.json b/src/i18n/zh.json index 92894834..04f69a37 100644 --- a/src/i18n/zh.json +++ b/src/i18n/zh.json @@ -6,6 +6,8 @@ "Restart":"重启", "Pause":"暂停", "USDC_here":"USDC已上线,快来锁仓吧!", + "MKR_Debt_Auction_start":"MKR债务拍卖将于3月19日(周四)晚10:28左右开始(14:28 UTC)", + "Read_Maker_blog":"到Maker博客阅读更多相关信息", "Total_Dai":"总计Dai", "Total_Sai":"总计Sai", "Dai_from_ETH":"来源于ETH的Dai",