From cdc44535cbacb5fe1347313e356f7b4eeca96826 Mon Sep 17 00:00:00 2001 From: Leonardo Ferreira Date: Mon, 25 Sep 2023 23:37:33 -0300 Subject: [PATCH 1/4] base --- src/components/MenuAppBar/MenuAppBar.js | 28 +++++++++++++++++++- src/i18n/en.js | 2 ++ src/i18n/i18n.js | 35 +++++++++++++++++++++++++ src/i18n/pt_BR.js | 21 +++++++++++++++ src/pages/Board/ListBoard/ListBoard.js | 14 +++++----- src/pages/Login/Login.js | 29 +++++++++++--------- src/services/HttpService.js | 2 +- src/services/LocalStoreService.js | 10 +++++-- 8 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 src/i18n/en.js create mode 100644 src/i18n/i18n.js create mode 100644 src/i18n/pt_BR.js diff --git a/src/components/MenuAppBar/MenuAppBar.js b/src/components/MenuAppBar/MenuAppBar.js index 77c27b5..735a719 100644 --- a/src/components/MenuAppBar/MenuAppBar.js +++ b/src/components/MenuAppBar/MenuAppBar.js @@ -6,9 +6,12 @@ import { authActions } from "stores/ducks/auth"; import M from "materialize-css"; import { Link } from "react-router-dom"; -import { AuthService, NotificationService } from "services"; +import { AuthService, NotificationService, LocalStoreService } from "services"; class MenuAppBar extends Component { + state = { + lang: LocalStoreService.getI18n() || 'en' + } componentDidMount() { const dropdown = document.querySelectorAll(".dropdown-trigger"); @@ -22,6 +25,13 @@ class MenuAppBar extends Component { NotificationService.notifySuccess("Logout realizado com sucesso"); }; + handleLangChange = lang => { + LocalStoreService.setI18n(lang) + this.setState({ + lang + }) + } + render() { const { userConfig } = this.props; @@ -47,6 +57,22 @@ class MenuAppBar extends Component { + ; diff --git a/src/i18n/en.js b/src/i18n/en.js new file mode 100644 index 0000000..29b1ecf --- /dev/null +++ b/src/i18n/en.js @@ -0,0 +1,2 @@ +export default { +} \ No newline at end of file diff --git a/src/i18n/i18n.js b/src/i18n/i18n.js new file mode 100644 index 0000000..424b439 --- /dev/null +++ b/src/i18n/i18n.js @@ -0,0 +1,35 @@ +import ptBr from './pt_BR' +import en from './en' + +import LocalStoreService from "services/LocalStoreService"; + +const langs = { + 'pt_BR':ptBr, + 'en': en +} + +function _accessByString(o, s) { + s = s.replace(/\[(\w+)\]/g, '.$1'); + s = s.replace(/^\./, ''); + var a = s.split('.'); + for (var i = 0, n = a.length; i < n; ++i) { + var k = a[i]; + if (k in o) { + o = o[k]; + } else { + return; + } + } + return o; +} + +function t(key) { + const lang = langs[LocalStoreService.getI18n() || 'en'] + const result = _accessByString(lang, key) + if (result) { + return result + } + return `{${key}}`; +} + +export default t \ No newline at end of file diff --git a/src/i18n/pt_BR.js b/src/i18n/pt_BR.js new file mode 100644 index 0000000..fbdfc71 --- /dev/null +++ b/src/i18n/pt_BR.js @@ -0,0 +1,21 @@ +export default { + unauthorized: "", + login: { + title: "Login", + submit: "Entrar", + usernameLabel: "Usuário", + passwordLabel: "Senha", + successMessage: "Login realizado com sucesso", + failureMessage: "Usuário e/ou senha inválido(s)" + }, + boards: { + allOwners: "Todos", + new: "Novo Board", + filter: { + title: 'Filtro', + button: 'Filtrar' + }, + nameLabel: "Nome", + ownerLabel: "Dono" + } +} \ No newline at end of file diff --git a/src/pages/Board/ListBoard/ListBoard.js b/src/pages/Board/ListBoard/ListBoard.js index ad71d74..5bce73e 100644 --- a/src/pages/Board/ListBoard/ListBoard.js +++ b/src/pages/Board/ListBoard/ListBoard.js @@ -9,6 +9,8 @@ import { Button, Col, InputField, Link, Pagination, Panel, Preloader, Row, Selec import CardBoard from "./CardBoard/CardBoard"; import EmptyBoardAlert from "./EmptyBoardAlert/EmptyBoardAlert"; +import t from "i18n/i18n"; + class ListBoard extends Component { state = { boards: { @@ -59,7 +61,7 @@ class ListBoard extends Component { const { data } = await HttpService.get("/boards/owners"); const owners = [ { - label: "Todos", + label: t('boards.allOwners'), value: "all" }, ...data.map(owner => ({ @@ -127,14 +129,14 @@ class ListBoard extends Component { return Novo board + {t('boards.new')} }/> - - Filtrar + {t('boards.filter.button')} }> @@ -142,12 +144,12 @@ class ListBoard extends Component { name="name" onChange={e => this.changeFilterValue("name", e.target.value)} value={filter.name} - label="Nome"/> + label={t('boards.nameLabel')}/>