From bc51f1b761763ca585f225190e7d859e0cd03209 Mon Sep 17 00:00:00 2001 From: Baoyuan Date: Fri, 16 Jul 2021 23:02:03 +0800 Subject: [Issue #49] feat: add i18n (#58) * feat: add i18n * fix: code clean --- src/App.js | 23 +++++++++++------- src/components/Card.js | 31 +++++++++++++----------- src/i18n.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 1 + 4 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 src/i18n.js (limited to 'src') diff --git a/src/App.js b/src/App.js index 3832de1..1b97aec 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,32 @@ import React from 'react'; +import { useTranslation } from 'react-i18next'; import { Card } from './components/Card'; import './style.css'; import logo from '../src/images/wifi.png'; function App() { + const { t, i18n } = useTranslation(); + return (

icon -   WiFi Card +   {t('title')}

-

- Print a simple card with your WiFi login details. Tape it to the fridge, - keep it in your wallet, etc. -

+
+ + +
+ +

{t('desc.use')}

- Your WiFi information is never sent to the server. No tracking, - analytics, or fingerprinting are used on this website. View the{' '} - source code. + {t('desc.privacy')}{' '} + {t('desc.source')}.

diff --git a/src/components/Card.js b/src/components/Card.js index 7409d6c..50db589 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -1,5 +1,6 @@ import QRCode from 'qrcode.react'; import { useEffect, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import './style.css'; export const Card = () => { @@ -12,7 +13,7 @@ export const Card = () => { hidePassword: false, }); const [portrait, setPortrait] = useState(false); - + const { t } = useTranslation(); const escape = (v) => { const needsEscape = ['"', ';', ',', ':', '\\']; @@ -31,17 +32,17 @@ export const Card = () => { const onPrint = () => { if (network.ssid.length > 0) { if (network.password.length < 8 && network.encryptionMode === 'WPA') { - alert('Password must be at least 8 characters'); + alert(t('wifi.alert.password.8')); } else if ( network.password.length < 5 && network.encryptionMode === 'WEP' ) { - alert('Password must be at least 5 characters'); + alert(t('wifi.alert.password.5')); } else { window.print(); } } else { - alert('Network name cannot be empty'); + alert(t('wifi.alert.name')); } }; @@ -62,7 +63,9 @@ export const Card = () => { id="print-area" style={{ maxWidth: portrait ? '350px' : '100%' }} > -

WiFi Login

+

+ {t('wifi.login')} +

{ />
- +