From 8be42a4e57928f82830be71fa6c9bc17ac63aa8a Mon Sep 17 00:00:00 2001 From: Ben Woodward Date: Fri, 6 Aug 2021 07:52:22 -0700 Subject: Refactor translation plumbing (#168) - Centralize user-defined translations into a single file - Automatically sort the language dropdown - Update the translation contribution guide --- src/App.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/App.js') 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 @@ import { Button, Heading, Link, Pane, Paragraph } from 'evergreen-ui'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import logo from '../src/images/wifi.png'; import { Settings } from './components/Settings'; import { WifiCard } from './components/WifiCard'; import './style.css'; - -/* List of languages that require RTL direction (alphabetic order). */ -const RTL_LANGUAGES = ['ar', 'fa-IR']; +import { Translations } from './translations'; function App() { const html = document.querySelector('html'); @@ -30,8 +28,14 @@ function App() { passwordError: '', }); + const htmlDirection = (languageID) => { + languageID = languageID || i18n.language; + const rtl = Translations.filter((t) => t.id === languageID)[0].rtl; + return rtl ? 'rtl' : 'ltr'; + }; + const onChangeLanguage = (language) => { - html.style.direction = RTL_LANGUAGES.includes(language) ? 'rtl' : 'ltr'; + html.style.direction = htmlDirection(language); i18n.changeLanguage(language); }; @@ -84,16 +88,10 @@ function App() { setSettings({ ...settings, hidePassword }); }; const onFirstLoad = () => { + html.style.direction = htmlDirection(); firstLoad.current = false; }; - useEffect(() => { - /* handle the edge case of the initial render requiring RTL direction */ - if (RTL_LANGUAGES.includes(i18n.language)) { - html.style.direction = 'rtl'; - } - }); - return ( @@ -116,7 +114,7 @@ function App() {