-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2075 from tf/lang-switch
Add translations menu to default navigation bar
- Loading branch information
Showing
31 changed files
with
464 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...es/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry_translations.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
json.entry_translations do | ||
json.array!(entry.translations(-> { preload(:site) })) do |translation| | ||
json.(translation, :id, :locale) | ||
json.display_locale t('pageflow.public._language', locale: translation.locale) | ||
|
||
if translation.published_revision? | ||
json.url social_share_entry_url(translation) | ||
else | ||
json.url main_app.preview_admin_entry_path(translation) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
entry_types/scrolled/package/spec/widgets/defaultNavigation/TranslationsMenu-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import {TranslationsMenu} from 'widgets/defaultNavigation/TranslationsMenu'; | ||
|
||
import '@testing-library/jest-dom/extend-expect'; | ||
import {renderInEntry} from 'support'; | ||
|
||
describe('TranslationsMenu', () => { | ||
it('marks current page in rendered list of translations', async () => { | ||
const {getByRole} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
}, | ||
entryTranslations: [ | ||
{ | ||
id: 5, | ||
displayLocale: 'Deutsch', | ||
url: '/entry-de' | ||
}, | ||
{ | ||
id: 6, | ||
displayLocale: 'English', | ||
url: '/entry-en' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
expect(getByRole('link', {name: 'English'})).toHaveAttribute('href', '/entry-en'); | ||
expect(getByRole('listitem', {current: 'page'})).toHaveTextContent('Deutsch'); | ||
}); | ||
|
||
it('includes shortend uppercased locale in button', async () => { | ||
const {getByRole} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
locale: 'de-ch' | ||
}, | ||
entryTranslations: [ | ||
{ | ||
id: 5, | ||
displayLocale: 'Deutsch', | ||
url: '/entry-de' | ||
}, | ||
{ | ||
id: 6, | ||
displayLocale: 'English', | ||
url: '/entry-en' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
expect(getByRole('button')).toHaveTextContent(/^DE$/); | ||
}); | ||
|
||
it('renders nothing if no translations are present', async () => { | ||
const {container} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
locale: 'de-ch' | ||
}, | ||
entryTranslations: [] | ||
} | ||
}); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
entry_types/scrolled/package/src/entryState/entryTranslations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {useEntryStateConfig} from "./EntryStateProvider"; | ||
|
||
export function useEntryTranslations() { | ||
const config = useEntryStateConfig(); | ||
return config.entryTranslations; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.