aboutsummaryrefslogtreecommitdiffstats
path: root/src/App.js
diff options
context:
space:
mode:
authorBen Woodward <ben@bdw.to>2021-08-06 07:52:22 -0700
committerGitHub <noreply@github.com>2021-08-06 07:52:22 -0700
commit8be42a4e57928f82830be71fa6c9bc17ac63aa8a (patch)
tree584b315672d65cb5ad8d296980bf56bf4041c450 /src/App.js
parent3a63d9fb3fcc2750be155fa67008887bf38687ac (diff)
Refactor translation plumbing (#168)
- Centralize user-defined translations into a single file - Automatically sort the language dropdown - Update the translation contribution guide
Diffstat (limited to 'src/App.js')
-rw-r--r--src/App.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/App.js b/src/App.js
index 3d93bd6..baa3c83 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,13 +1,11 @@
1import { Button, Heading, Link, Pane, Paragraph } from 'evergreen-ui'; 1import { Button, Heading, Link, Pane, Paragraph } from 'evergreen-ui';
2import React, { useEffect, useRef, useState } from 'react'; 2import React, { useRef, useState } from 'react';
3import { useTranslation } from 'react-i18next'; 3import { useTranslation } from 'react-i18next';
4import logo from '../src/images/wifi.png'; 4import logo from '../src/images/wifi.png';
5import { Settings } from './components/Settings'; 5import { Settings } from './components/Settings';
6import { WifiCard } from './components/WifiCard'; 6import { WifiCard } from './components/WifiCard';
7import './style.css'; 7import './style.css';
8 8import { Translations } from './translations';
9/* List of languages that require RTL direction (alphabetic order). */
10const RTL_LANGUAGES = ['ar', 'fa-IR'];
11 9
12function App() { 10function App() {
13 const html = document.querySelector('html'); 11 const html = document.querySelector('html');
@@ -30,8 +28,14 @@ function App() {
30 passwordError: '', 28 passwordError: '',
31 }); 29 });
32 30
31 const htmlDirection = (languageID) => {
32 languageID = languageID || i18n.language;
33 const rtl = Translations.filter((t) => t.id === languageID)[0].rtl;
34 return rtl ? 'rtl' : 'ltr';
35 };
36
33 const onChangeLanguage = (language) => { 37 const onChangeLanguage = (language) => {
34 html.style.direction = RTL_LANGUAGES.includes(language) ? 'rtl' : 'ltr'; 38 html.style.direction = htmlDirection(language);
35 i18n.changeLanguage(language); 39 i18n.changeLanguage(language);
36 }; 40 };
37 41
@@ -84,16 +88,10 @@ function App() {
84 setSettings({ ...settings, hidePassword }); 88 setSettings({ ...settings, hidePassword });
85 }; 89 };
86 const onFirstLoad = () => { 90 const onFirstLoad = () => {
91 html.style.direction = htmlDirection();
87 firstLoad.current = false; 92 firstLoad.current = false;
88 }; 93 };
89 94
90 useEffect(() => {
91 /* handle the edge case of the initial render requiring RTL direction */
92 if (RTL_LANGUAGES.includes(i18n.language)) {
93 html.style.direction = 'rtl';
94 }
95 });
96
97 return ( 95 return (
98 <Pane> 96 <Pane>
99 <Pane display="flex"> 97 <Pane display="flex">
@@ -116,7 +114,7 @@ function App() {
116 </Pane> 114 </Pane>
117 115
118 <WifiCard 116 <WifiCard
119 direction={RTL_LANGUAGES.includes(i18n.language) ? 'rtl' : 'ltr'} 117 direction={htmlDirection()}
120 settings={settings} 118 settings={settings}
121 ssidError={errors.ssidError} 119 ssidError={errors.ssidError}
122 passwordError={errors.passwordError} 120 passwordError={errors.passwordError}