From 3c4de3c8b59547cdb3ab76033d0dbba8d1df3dba Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 15 Apr 2020 21:37:02 -0400 Subject: [PATCH] Move language merge logic to i18n/index This simplifies implementations one new languages --- ui/src/App.js | 4 +- ui/src/i18n/index.js | 15 ++- ui/src/i18n/pt.js | 195 +++++++++++++++++++-------------------- ui/src/subsonic/index.js | 2 +- 4 files changed, 110 insertions(+), 106 deletions(-) diff --git a/ui/src/App.js b/ui/src/App.js index 8c990eeea..dc6851ea0 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -1,7 +1,7 @@ import React from 'react' import { Provider } from 'react-redux' import { createHashHistory } from 'history' -import { Admin, resolveBrowserLocale, Resource } from 'react-admin' +import { Admin, Resource } from 'react-admin' import dataProvider from './dataProvider' import authProvider from './authProvider' import polyglotI18nProvider from 'ra-i18n-polyglot' @@ -21,7 +21,7 @@ import createAdminStore from './store/createAdminStore' const i18nProvider = polyglotI18nProvider( (locale) => (messages[locale] ? messages[locale] : messages.en), - localStorage.getItem('locale') || resolveBrowserLocale() + localStorage.getItem('locale') || 'en' ) const history = createHashHistory() diff --git a/ui/src/i18n/index.js b/ui/src/i18n/index.js index a63e142da..ef7725486 100644 --- a/ui/src/i18n/index.js +++ b/ui/src/i18n/index.js @@ -1,13 +1,18 @@ +import deepmerge from 'deepmerge' import en from './en' import pt from './pt' -// When adding a new translation, import it above and add it to the list bellow +const addLanguages = (lang) => { + Object.keys(lang).forEach((l) => (languages[l] = deepmerge(en, lang[l]))) +} +const languages = { en } -const allLanguages = { en, pt } +// Add new languages to the object bellow +addLanguages({ pt }) // "Hack" to make "albumSongs" resource use the same translations as "song" -Object.keys(allLanguages).forEach( - (k) => (allLanguages[k].resources.albumSong = allLanguages[k].resources.song) +Object.keys(languages).forEach( + (k) => (languages[k].resources.albumSong = languages[k].resources.song) ) -export default allLanguages +export default languages diff --git a/ui/src/i18n/pt.js b/ui/src/i18n/pt.js index 5792701d4..e3e754c8a 100644 --- a/ui/src/i18n/pt.js +++ b/ui/src/i18n/pt.js @@ -1,113 +1,112 @@ import deepmerge from 'deepmerge' -import en from './en' import portugueseMessages from 'ra-language-portuguese' -export default deepmerge.all([ - en, - portugueseMessages, - { - languageName: 'Português', - resources: { - song: { - name: 'Música |||| Músicas', - fields: { - title: 'Título', - artist: 'Artista', - album: 'Álbum', - path: 'Caminho', - genre: 'Gênero', - compilation: 'Coletânea', - duration: 'Duração', - year: 'Ano', - trackNumber: '#' - }, - bulk: { - addToQueue: 'Play Later' - } +export default deepmerge(portugueseMessages, { + languageName: 'Português', + resources: { + song: { + name: 'Música |||| Músicas', + fields: { + title: 'Título', + artist: 'Artista', + album: 'Álbum', + path: 'Arquivo', + genre: 'Gênero', + compilation: 'Coletânea', + duration: 'Duração', + year: 'Ano', + playCount: 'Execuções', + trackNumber: '#', + size: 'Tamanho', + updatedAt: 'Últ. Atualização' }, - album: { - name: 'Álbum |||| Álbuns', - fields: { - name: 'Nome', - artist: 'Artista', - songCount: 'Songs', - genre: 'Gênero', - playCount: 'Plays', - compilation: 'Coletânea', - duration: 'Duração', - year: 'Ano' - }, - actions: { - playAll: 'Play', - playNext: 'Play Next', - addToQueue: 'Play Later', - shuffle: 'Shuffle' - } - }, - artist: { - name: 'Artista |||| Artistas', - fields: { - name: 'Nome' - } - }, - user: { - name: 'Usuário |||| Usuários', - fields: { - name: 'Nome' - } - }, - transcoding: { - name: 'Conversão |||| Conversões', - fields: { - name: 'Nome' - } - }, - player: { - name: 'Tocador |||| Tocadores', - fields: { - name: 'Nome' - } + bulk: { + addToQueue: 'Play Later' } }, - ra: { - auth: { - welcome1: 'Thanks for installing Navidrome!', - welcome2: 'To start, create an admin user', - confirmPassword: 'Confirm Password', - buttonCreateAdmin: 'Create Admin' + album: { + name: 'Álbum |||| Álbuns', + fields: { + name: 'Nome', + artist: 'Artista', + songCount: 'Músicas', + genre: 'Gênero', + playCount: 'Execuções', + compilation: 'Coletânea', + duration: 'Duração', + year: 'Ano' }, - validation: { - invalidChars: 'Please only use letter and numbers', - passwordDoesNotMatch: 'Password does not match' + actions: { + playAll: 'Play', + playNext: 'Play Next', + addToQueue: 'Play Later', + shuffle: 'Shuffle' } }, - menu: { - library: 'Biblioteca', - settings: 'Configurações', - version: 'Versão %{version}', - personal: { - name: 'Pessoal', - options: { - theme: 'Tema', - language: 'Língua' - } + artist: { + name: 'Artista |||| Artistas', + fields: { + name: 'Nome', + albumCount: 'Total de Álbuns' + } + }, + user: { + name: 'Usuário |||| Usuários', + fields: { + name: 'Nome' + } + }, + transcoding: { + name: 'Conversão |||| Conversões', + fields: { + name: 'Nome' } }, player: { - playListsText: 'Fila de Execução', - openText: 'Abrir', - closeText: 'Fechar', - clickToPlayText: 'Clique para tocar', - clickToPauseText: 'Clique para pausar', - nextTrackText: 'Próxima faixa', - previousTrackText: 'Faixa anterior', - clickToDeleteText: `Clique para remover %{name}`, - playModeText: { - order: 'Em ordem', - orderLoop: 'Repetir tudo', - singleLoop: 'Repetir', - shufflePlay: 'Aleatório' + name: 'Tocador |||| Tocadores', + fields: { + name: 'Nome' } } + }, + ra: { + auth: { + welcome1: 'Thanks for installing Navidrome!', + welcome2: 'To start, create an admin user', + confirmPassword: 'Confirm Password', + buttonCreateAdmin: 'Create Admin' + }, + validation: { + invalidChars: 'Please only use letter and numbers', + passwordDoesNotMatch: 'Password does not match' + } + }, + menu: { + library: 'Biblioteca', + settings: 'Configurações', + version: 'Versão %{version}', + personal: { + name: 'Pessoal', + options: { + theme: 'Tema', + language: 'Língua' + } + } + }, + player: { + playListsText: 'Fila de Execução', + openText: 'Abrir', + closeText: 'Fechar', + clickToPlayText: 'Clique para tocar', + clickToPauseText: 'Clique para pausar', + nextTrackText: 'Próxima faixa', + previousTrackText: 'Faixa anterior', + clickToDeleteText: `Clique para remover %{name}`, + playModeText: { + order: 'Em ordem', + orderLoop: 'Repetir tudo', + singleLoop: 'Repetir', + shufflePlay: 'Aleatório' + } } -]) +}) diff --git a/ui/src/subsonic/index.js b/ui/src/subsonic/index.js index a08f06f5f..6404cb307 100644 --- a/ui/src/subsonic/index.js +++ b/ui/src/subsonic/index.js @@ -1,5 +1,5 @@ import { fetchUtils } from 'react-admin' -import baseUrl from "../utils/baseUrl" +import baseUrl from '../utils/baseUrl' const url = (command, id, options) => { const params = new URLSearchParams()