Skip to content

Commit

Permalink
Fix NavBar title translations
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Apr 28, 2020
1 parent 069de0f commit ea1d534
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 26 deletions.
4 changes: 3 additions & 1 deletion ui/src/album/AlbumList.js
Expand Up @@ -67,7 +67,9 @@ const AlbumList = (props) => {
return (
<List
{...props}
title={<Title subTitle={'Albums'} />}
title={
<Title subTitle={'resources.album.name'} args={{ smart_count: 2 }} />
}
exporter={false}
bulkActionButtons={false}
actions={<AlbumListActions />}
Expand Down
4 changes: 3 additions & 1 deletion ui/src/artist/ArtistList.js
Expand Up @@ -25,7 +25,9 @@ const artistRowClick = (id) => {
const ArtistList = (props) => (
<List
{...props}
title={<Title subTitle={'Artists'} />}
title={
<Title subTitle={'resources.artist.name'} args={{ smart_count: 2 }} />
}
sort={{ field: 'name', order: 'ASC' }}
exporter={false}
bulkActionButtons={false}
Expand Down
9 changes: 6 additions & 3 deletions ui/src/common/Title.js
@@ -1,13 +1,16 @@
import React from 'react'
import { useMediaQuery } from '@material-ui/core'
import { useTranslate } from 'react-admin'

const Title = ({ subTitle }) => {
const Title = ({ subTitle, args }) => {
const translate = useTranslate()
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
const text = translate(subTitle, { ...args, _: subTitle })

if (isDesktop) {
return <span>Navidrome {subTitle ? ` - ${subTitle}` : ''}</span>
return <span>Navidrome {text ? ` - ${text}` : ''}</span>
}
return <span>{subTitle ? subTitle : 'Navidrome'}</span>
return <span>{text ? text : 'Navidrome'}</span>
}

export default Title
13 changes: 13 additions & 0 deletions ui/src/i18n/en.js
Expand Up @@ -17,6 +17,7 @@ export default deepmerge(englishMessages, {
},
},
album: {
name: 'Album |||| Albums',
fields: {
albumArtist: 'Album Artist',
artist: 'Artist',
Expand All @@ -31,6 +32,18 @@ export default deepmerge(englishMessages, {
shuffle: 'Shuffle',
},
},
artist: {
name: 'Artist |||| Artists',
},
user: {
name: 'User |||| Users',
},
player: {
name: 'Player |||| Players',
},
transcoding: {
name: 'Transcoding |||| Transcodings',
},
},
ra: {
auth: {
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/pt.js
Expand Up @@ -92,6 +92,9 @@ export default deepmerge(portugueseMessages, {
invalidChars: 'Somente use letras e numeros',
passwordDoesNotMatch: 'Senha n茫o confere',
},
page: {
create: 'Criar %{name}',
},
},
menu: {
library: 'Biblioteca',
Expand Down
5 changes: 4 additions & 1 deletion ui/src/player/PlayerEdit.js
Expand Up @@ -7,11 +7,14 @@ import {
SimpleForm,
SelectInput,
ReferenceInput,
useTranslate,
} from 'react-admin'
import { Title } from '../common'

const PlayerTitle = ({ record }) => {
return <Title subTitle={`Player ${record ? record.name : ''}`} />
const translate = useTranslate()
const resourceName = translate('resources.player.name', { smart_count: 1 })
return <Title subTitle={`${resourceName} ${record ? record.name : ''}`} />
}

const PlayerEdit = (props) => (
Expand Down
8 changes: 7 additions & 1 deletion ui/src/player/PlayerList.js
Expand Up @@ -13,7 +13,13 @@ import { SimpleList, Title } from '../common'
const PlayerList = (props) => {
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
return (
<List title={<Title subTitle={'Players'} />} exporter={false} {...props}>
<List
title={
<Title subTitle={'resources.player.name'} args={{ smart_count: 2 }} />
}
exporter={false}
{...props}
>
{isXsmall ? (
<SimpleList
primaryText={(r) => r.client}
Expand Down
4 changes: 3 additions & 1 deletion ui/src/song/SongList.js
Expand Up @@ -36,7 +36,9 @@ const SongList = (props) => {
return (
<List
{...props}
title={<Title subTitle={'Songs'} />}
title={
<Title subTitle={'resources.song.name'} args={{ smart_count: 2 }} />
}
sort={{ field: 'title', order: 'ASC' }}
exporter={false}
bulkActionButtons={<SongBulkActions />}
Expand Down
12 changes: 10 additions & 2 deletions ui/src/transcoding/TranscodingCreate.js
Expand Up @@ -5,11 +5,19 @@ import {
Create,
required,
SimpleForm,
useTranslate,
} from 'react-admin'
import { Title } from '../common'

const TranscodingTitle = ({ record }) => {
return <Title subTitle={`Transcoding ${record ? record.name : ''}`} />
const TranscodingTitle = () => {
const translate = useTranslate()
const resourceName = translate('resources.transcoding.name', {
smart_count: 1,
})
const title = translate('ra.page.create', {
name: `${resourceName}`,
})
return <Title subTitle={title} />
}

const TranscodingCreate = (props) => (
Expand Down
15 changes: 13 additions & 2 deletions ui/src/transcoding/TranscodingEdit.js
@@ -1,9 +1,20 @@
import React from 'react'
import { TextInput, SelectInput, Edit, required, SimpleForm } from 'react-admin'
import {
TextInput,
SelectInput,
Edit,
required,
SimpleForm,
useTranslate,
} from 'react-admin'
import { Title } from '../common'

const TranscodingTitle = ({ record }) => {
return <Title subTitle={`Transcoding ${record ? record.name : ''}`} />
const translate = useTranslate()
const resourceName = translate('resources.transcoding.name', {
smart_count: 1,
})
return <Title subTitle={`${resourceName} ${record ? record.name : ''}`} />
}

const TranscodingEdit = (props) => (
Expand Down
7 changes: 6 additions & 1 deletion ui/src/transcoding/TranscodingList.js
Expand Up @@ -7,7 +7,12 @@ const TranscodingList = (props) => {
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
return (
<List
title={<Title subTitle={'Transcodings'} />}
title={
<Title
subTitle={'resources.transcoding.name'}
args={{ smart_count: 2 }}
/>
}
exporter={false}
{...props}
>
Expand Down
30 changes: 19 additions & 11 deletions ui/src/user/UserCreate.js
Expand Up @@ -7,19 +7,27 @@ import {
required,
email,
SimpleForm,
useTranslate,
} from 'react-admin'
import { Title } from '../common'

const UserCreate = (props) => (
<Create title={<Title subTitle={'Create User'} />} {...props}>
<SimpleForm redirect="list">
<TextInput source="userName" validate={[required()]} />
<TextInput source="name" validate={[required()]} />
<TextInput source="email" validate={[required(), email()]} />
<PasswordInput source="password" validate={[required()]} />
<BooleanInput source="isAdmin" defaultValue={false} />
</SimpleForm>
</Create>
)
const UserCreate = (props) => {
const translate = useTranslate()
const resourceName = translate('resources.user.name', { smart_count: 1 })
const title = translate('ra.page.create', {
name: `${resourceName}`,
})
return (
<Create title={<Title subTitle={title} />} {...props}>
<SimpleForm redirect="list">
<TextInput source="userName" validate={[required()]} />
<TextInput source="name" validate={[required()]} />
<TextInput source="email" validate={[required(), email()]} />
<PasswordInput source="password" validate={[required()]} />
<BooleanInput source="isAdmin" defaultValue={false} />
</SimpleForm>
</Create>
)
}

export default UserCreate
5 changes: 4 additions & 1 deletion ui/src/user/UserEdit.js
Expand Up @@ -8,11 +8,14 @@ import {
required,
email,
SimpleForm,
useTranslate,
} from 'react-admin'
import { Title } from '../common'

const UserTitle = ({ record }) => {
return <Title subTitle={`User ${record ? record.name : ''}`} />
const translate = useTranslate()
const resourceName = translate('resources.user.name', { smart_count: 1 })
return <Title subTitle={`${resourceName} ${record ? record.name : ''}`} />
}
const UserEdit = (props) => (
<Edit title={<UserTitle />} {...props}>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/user/UserList.js
Expand Up @@ -24,7 +24,9 @@ const UserList = (props) => {
return (
<List
{...props}
title={<Title subTitle={'Users'} />}
title={
<Title subTitle={'resources.user.name'} args={{ smart_count: 2 }} />
}
sort={{ field: 'userName', order: 'ASC' }}
exporter={false}
filters={<UserFilter />}
Expand Down

0 comments on commit ea1d534

Please sign in to comment.