From 671da6b5fa1bc532430229345221849ed1eded6b Mon Sep 17 00:00:00 2001 From: Rafael Faria Date: Wed, 6 Feb 2019 14:39:02 -0200 Subject: [PATCH] added pt-br and some improvements to language control --- mock/route.js | 77 ++++++++++++++++++++++++++++----- src/layouts/PrimaryLayout.js | 9 ++-- src/locales/pt-br/messages.json | 54 +++++++++++++++++++++++ src/utils/config.js | 7 ++- 4 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 src/locales/pt-br/messages.json diff --git a/mock/route.js b/mock/route.js index b4f35ee8..89d892e8 100644 --- a/mock/route.js +++ b/mock/route.js @@ -6,14 +6,24 @@ const database = [ id: '1', icon: 'dashboard', name: 'Dashboard', - zhName: '仪表盘', + zh: { + name: '仪表盘' + }, + 'pt-br': { + name: 'Dashboard' + }, route: '/dashboard', }, { id: '2', breadcrumbParentId: '1', name: 'Users', - zhName: '用户管理', + zh: { + name: '用户管理' + }, + 'pt-br': { + name: 'Usuário' + }, icon: 'user', route: '/user', }, @@ -21,7 +31,12 @@ const database = [ id: '7', breadcrumbParentId: '1', name: 'Posts', - zhName: '文章管理', + zh: { + name: '用户管理' + }, + 'pt-br': { + name: 'Posts' + }, icon: 'shopping-cart', route: '/post', }, @@ -30,14 +45,24 @@ const database = [ menuParentId: '-1', breadcrumbParentId: '2', name: 'User Detail', - zhName: '用户详情', + zh: { + name: '用户详情' + }, + 'pt-br': { + name: 'Detalhes do usuário' + }, route: '/user/:id', }, { id: '3', breadcrumbParentId: '1', name: 'Request', - zhName: 'Request', + zh: { + name: 'Request' + }, + 'pt-br': { + name: 'Requisição' + }, icon: 'api', route: '/request', }, @@ -45,7 +70,12 @@ const database = [ id: '4', breadcrumbParentId: '1', name: 'UI Element', - zhName: 'UI组件', + zh: { + name: 'UI组件' + }, + 'pt-br': { + name: 'Elementos UI' + }, icon: 'camera-o', }, { @@ -53,7 +83,12 @@ const database = [ breadcrumbParentId: '4', menuParentId: '4', name: 'Editor', - zhName: 'Editor', + zh: { + name: 'Editor' + }, + 'pt-br': { + name: 'Editor' + }, icon: 'edit', route: '/UIElement/editor', }, @@ -61,7 +96,12 @@ const database = [ id: '5', breadcrumbParentId: '1', name: 'Charts', - zhName: 'Charts', + zh: { + name: 'Charts' + }, + 'pt-br': { + name: 'Graficos' + }, icon: 'code-o', }, { @@ -69,7 +109,12 @@ const database = [ breadcrumbParentId: '5', menuParentId: '5', name: 'ECharts', - zhName: 'ECharts', + zh: { + name: 'ECharts' + }, + 'pt-br': { + name: 'ECharts' + }, icon: 'line-chart', route: '/chart/ECharts', }, @@ -78,7 +123,12 @@ const database = [ breadcrumbParentId: '5', menuParentId: '5', name: 'HighCharts', - zhName: 'HighCharts', + zh: { + name: 'HighCharts' + }, + 'pt-br': { + name: 'HighCharts' + }, icon: 'bar-chart', route: '/chart/highCharts', }, @@ -87,7 +137,12 @@ const database = [ breadcrumbParentId: '5', menuParentId: '5', name: 'Rechartst', - zhName: 'Rechartst', + zh: { + name: 'Rechartst' + }, + 'pt-br': { + name: 'Rechartst' + }, icon: 'area-chart', route: '/chart/Recharts', }, diff --git a/src/layouts/PrimaryLayout.js b/src/layouts/PrimaryLayout.js index 3d5c33c7..f3f5e3fb 100644 --- a/src/layouts/PrimaryLayout.js +++ b/src/layouts/PrimaryLayout.js @@ -58,17 +58,20 @@ class PrimaryLayout extends PureComponent { const { onCollapseChange } = this // Localized route name. + + const lang = langFromPath(location.pathname); const newRouteList = - langFromPath(location.pathname) === 'zh' + lang !== 'en' ? routeList.map(item => { - const { zhName, ...other } = item + const { name , ...other } = item return { ...other, - name: zhName, + name: ((item[lang] || {}).name || name), } }) : routeList + // Find a route that matches the pathname. const currentRoute = newRouteList.find( _ => _.route && pathMatchRegexp(_.route, location.pathname) diff --git a/src/locales/pt-br/messages.json b/src/locales/pt-br/messages.json new file mode 100644 index 00000000..2e931da1 --- /dev/null +++ b/src/locales/pt-br/messages.json @@ -0,0 +1,54 @@ +{ + "/dashboard": "/dashboard", + "Add Param": "Add Parametro", + "Address": "Endereço", + "Age": "Ano", + "Are you sure delete this record?": "Tem certeza de excluir este registro?", + "Author": "Autor", + "Avatar": "Avatar", + "Categories": "Categorias", + "Clear notifications": "limpar notificações", + "Comments": "Comentarios", + "Create": "Criar", + "Create User": "Criar Usuário", + "CreateTime": "CreateTime", + "Dark": "Escuro", + "Delete": "Deletar", + "Email": "Email", + "Female": "Feminino", + "Gender": "Genero", + "Hi,": "Olá,", + "Image": "Imagem", + "Light": "Claro", + "Male": "masculino", + "Name": "Nome", + "NickName": "NickName", + "Not Found": "Não Encontrado", + "Operation": "Operation", + "Params": "Parametros", + "Password": "Senha", + "Phone": "Fone", + "Pick an address": "Escolha um endereço", + "Please pick an address": "Por favor, escolha um endereço", + "Publised": "Publicado", + "Publish Date": "Data de publicação", + "Reset": "Reset", + "Search": "procurar", + "Search Name": "Search Name", + "Send": "Enviar", + "Sign in": "Sign in", + "Sign out": "Sign out", + "Switch Theme": "Trocar tema", + "Tags": "Tags", + "The input is not valid E-mail!": "Não é um E-mail valido!", + "The input is not valid phone!": "Não é um telefone Valido!", + "Title": "Titulo", + "Total {total} Items": "Total {total} Items", + "Unpublished": "Não publicado", + "Update": "Atualizar", + "Update User": "Atualizar Usuário", + "Username": "Usuário", + "Views": "visualizações", + "Visibility": "Visibilidade", + "You have viewed all notifications.": "Você visualizou todas as notificações." +} diff --git a/src/utils/config.js b/src/utils/config.js index 991eed11..037d346e 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -18,6 +18,11 @@ module.exports = { i18n: { /* Countrys flags: https://www.flaticon.com/packs/countrys-flags */ languages: [ + { + key: 'pt-br', + title: 'Português', + flag: '/brazil.svg', + }, { key: 'en', title: 'English', @@ -29,6 +34,6 @@ module.exports = { flag: '/china.svg', }, ], - defaultLanguage: 'en', + defaultLanguage: 'pt-br', }, }