From 91ea6bb193d2a2ac37f6f5f571f3595f3570303e Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 13 Aug 2020 10:22:15 -0300 Subject: [PATCH] improvement: all app strings now using i18n --- frontend/src/App.js | 32 +++++++++++++------ .../src/components/ContactDrawer/index.js | 9 ++++-- frontend/src/components/MessageInput/index.js | 3 +- frontend/src/components/MessagesList/index.js | 12 ++++--- .../src/components/TicketOptionsMenu/index.js | 9 ++++-- frontend/src/translate/languages/pt.js | 24 ++++++++++++++ 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index 396a789..cb42d18 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,20 +1,32 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import Routes from "./routes"; import "react-toastify/dist/ReactToastify.css"; import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles"; import { ptBR } from "@material-ui/core/locale"; -const theme = createMuiTheme( - { - palette: { - primary: { main: "#1976d2" }, - }, - }, - ptBR -); - const App = () => { + const [locale, setLocale] = useState(); + + const theme = createMuiTheme( + { + palette: { + primary: { main: "#1976d2" }, + }, + }, + locale + ); + + useEffect(() => { + const i18nlocale = localStorage.getItem("i18nextLng"); + const browserLocale = + i18nlocale.substring(0, 2) + i18nlocale.substring(3, 5); + + if (browserLocale === "ptBR") { + setLocale(ptBR); + } + }, []); + return ( diff --git a/frontend/src/components/ContactDrawer/index.js b/frontend/src/components/ContactDrawer/index.js index 488294b..d0b0b3d 100644 --- a/frontend/src/components/ContactDrawer/index.js +++ b/frontend/src/components/ContactDrawer/index.js @@ -11,6 +11,7 @@ import Avatar from "@material-ui/core/Avatar"; import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; +import { i18n } from "../../translate/i18n"; import LinkifyWithTargetBlank from "../LinkifyWithTargetBlank"; import ContactModal from "../ContactModal"; import ContactDrawerSkeleton from "../ContactDrawerSkeleton"; @@ -123,7 +124,7 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { - Dados do contato + {i18n.t("contactDrawer.header")} {loading ? ( @@ -146,7 +147,7 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { color="primary" onClick={e => setModalOpen(true)} > - Editar contato + {i18n.t("contactDrawer.buttons.edit")} @@ -156,7 +157,9 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { aria-labelledby="form-dialog-title" contactId={contact.id} > - Outras informações + + {i18n.t("contactDrawer.extraInfo")} + {contact && contact.extraInfo && contact.extraInfo.map(info => ( diff --git a/frontend/src/components/MessageInput/index.js b/frontend/src/components/MessageInput/index.js index 2b566db..09d3a2b 100644 --- a/frontend/src/components/MessageInput/index.js +++ b/frontend/src/components/MessageInput/index.js @@ -18,6 +18,7 @@ import MicIcon from "@material-ui/icons/Mic"; import CheckCircleOutlineIcon from "@material-ui/icons/CheckCircleOutline"; import HighlightOffIcon from "@material-ui/icons/HighlightOff"; +import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import RecordingTimer from "./RecordingTimer"; @@ -310,7 +311,7 @@ const MessageInput = () => { input && input.focus()} className={classes.messageInput} - placeholder="Escreva uma mensagem" + placeholder={i18n.t("messagesInput.placeholder")} multiline rowsMax={5} value={inputMessage} diff --git a/frontend/src/components/MessagesList/index.js b/frontend/src/components/MessagesList/index.js index 8463931..02dc59f 100644 --- a/frontend/src/components/MessagesList/index.js +++ b/frontend/src/components/MessagesList/index.js @@ -23,6 +23,7 @@ import Skeleton from "@material-ui/lab/Skeleton"; import IconButton from "@material-ui/core/IconButton"; import MoreVertIcon from "@material-ui/icons/MoreVert"; +import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import ContactDrawer from "../ContactDrawer"; import whatsBackground from "../../assets/wa-background.png"; @@ -569,7 +570,10 @@ const MessagesList = () => { loading ? ( ) : ( - ticket.user && `Atribuído à: ${ticket.user.name}` + ticket.user && + `${i18n.t("messagesList.header.assignedTo")} ${ + ticket.user.name + }` ) } /> @@ -581,7 +585,7 @@ const MessagesList = () => { size="small" onClick={e => handleUpdateTicketStatus(e, "open", userId)} > - Reabrir + {i18n.t("messagesList.header.buttons.reopen")} ) : ( <> @@ -590,7 +594,7 @@ const MessagesList = () => { size="small" onClick={e => handleUpdateTicketStatus(e, "pending", null)} > - Retornar + {i18n.t("messagesList.header.buttons.return")} )} diff --git a/frontend/src/components/TicketOptionsMenu/index.js b/frontend/src/components/TicketOptionsMenu/index.js index da6f05b..e6c63bf 100644 --- a/frontend/src/components/TicketOptionsMenu/index.js +++ b/frontend/src/components/TicketOptionsMenu/index.js @@ -5,6 +5,7 @@ import { toast } from "react-toastify"; import MenuItem from "@material-ui/core/MenuItem"; import Menu from "@material-ui/core/Menu"; +import { i18n } from "../../translate/i18n"; import api from "../../services/api"; import ConfirmationModal from "../ConfirmationModal"; @@ -47,8 +48,12 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => { open={menuOpen} onClose={handleClose} > - Deletar - Transferir + + {i18n.t("ticketOptionsMenu.delete")} + + + {i18n.t("ticketOptionsMenu.transfer")} +