Skip to content

Commit

Permalink
Add Polish to language selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Nov 3, 2023
1 parent 03e83e4 commit b0b164a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
25 changes: 22 additions & 3 deletions src/app/components/language-selector/language-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import './language-selector.scss';
// You can't use a variable for id
const languageFromLocale = {
en: () => <FormattedMessage id="en" defaultMessage="English" />,
es: () => <FormattedMessage id="es" defaultMessage="Spanish" />
es: () => <FormattedMessage id="es" defaultMessage="Spanish" />,
pl: () => <FormattedMessage id="pl" defaultMessage="Polish" />
};

const polishSite = 'https://openstax.pl/podreczniki';

const NoLanguage = () => null;

export function useLanguageText(locale) {
Expand All @@ -29,6 +32,16 @@ export function LanguageLink({locale, slug}) {
const LanguageText = useLanguageText(locale);
const href = slug ? `/subjects/${slug}/` : locale;

// Magic: handle Polish specially
if (locale === 'pl') {
return (
// eslint-disable-next-line react/jsx-no-target-blank
<a href={polishSite} target="_blank">
<LanguageText />
</a>
);
}

return (
<a href={href} onClick={onClick}>
<LanguageText />
Expand Down Expand Up @@ -59,11 +72,17 @@ export function LanguageSelectorWrapper({children}) {
);
}

export default function LanguageSelector({LeadIn, otherLocales, LinkPresentation=LanguageLink}) {
export default function LanguageSelector({
LeadIn, otherLocales=[], LinkPresentation=LanguageLink, addPolish=false
}) {
const {language} = useLanguageContext();
const LanguageText = useLanguageText(language);

if (!otherLocales || otherLocales.length < 1) {
if (addPolish) {
otherLocales.push('pl');
}

if (otherLocales.length < 1) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
align-items: center;
column-gap: 1rem;
display: flex;
line-height: 1.9rem;

@include wider-than($tablet-max) {
justify-content: center;
Expand Down
16 changes: 11 additions & 5 deletions src/app/components/shell/header/menus/main-menu/main-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ function SubjectsMenu() {
/>
))}
{pathname.startsWith('/details/books') ? null : (
<LanguageSelectorWrapper>
<FormattedMessage id='view' defaultMessage='View' />{' '}
<LanguageLink locale={otherLocale} />
</LanguageSelectorWrapper>
)}
<React.Fragment>
<LanguageSelectorWrapper>
<FormattedMessage id='view' defaultMessage='View' />{' '}
<LanguageLink locale={otherLocale} />
</LanguageSelectorWrapper>
<LanguageSelectorWrapper>
<FormattedMessage id='view' defaultMessage='View' />{' '}
<LanguageLink locale='pl' />
</LanguageSelectorWrapper>
</React.Fragment>
)}
{language === 'en' ? <React.Fragment><hr /><K12MenuItem /></React.Fragment> : null}
</Dropdown>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ export default {
en: 'English',
es: 'Spanish',
and: 'and',
pl: 'Polish',
option: 'option',
options: 'options',
fewer: 'fewer',
more: 'more',
pageAvailableIn: 'This page is available in',
bookAvailableIn: 'This textbook is available in',
weHaveBooksIn: 'We have textbooks in',
weAlsoHave: 'We also have books in',
getTheBook: 'Get the book',
summary: 'Summary',
recommended: 'Recommended',
Expand Down
2 changes: 2 additions & 0 deletions src/app/lang/es.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default {
en: 'inglés',
es: 'español',
pl: 'polaco',
and: 'y',
option: 'opción',
options: 'opciones',
Expand All @@ -9,6 +10,7 @@ export default {
pageAvailableIn: 'Esta página está disponible en',
bookAvailableIn: 'Este libro de texto está disponible en',
weHaveBooksIn: 'Tenemos libros de texto en',
weAlsoHave: 'También tenemos libros en',
getTheBook: 'Obtener el libro',
summary: 'Resumen',
recommended: 'Recomendado',
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/subjects/new/language-selector-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import LanguageSelector from '~/components/language-selector/language-selector';
import {FormattedMessage} from 'react-intl';

export default function LanguageSelectorSection({otherLocales}) {
export default function LanguageSelectorSection(props) {
return (
<section className='language-selector-section'>
<div className='content'>
<LanguageSelector LeadIn={LeadIn} otherLocales={otherLocales} />
<LanguageSelector LeadIn={LeadIn} {...props} />
</div>
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/subjects/new/specific/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function useContextValue(slug) {

const {subjects, title} = data;

if (subjects && title) {
if (subjects && title && subjects[title]) {
return Object.entries(subjects[title].categories);
}
console.warn('Specific subjects and title need to be defined');
Expand Down
15 changes: 15 additions & 0 deletions src/app/pages/subjects/new/specific/translation-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,26 @@ export default function TranslationSelector({
otherLocales={otherLocales}
LinkPresentation={LinkPresentation}
/>
<div className='language-selector'>
<span>
<PolishLeadIn />{' '}
<LanguageLink locale='pl' slug='' />
</span>
</div>
</div>
</section>
);
}

function PolishLeadIn() {
return (
<FormattedMessage
id='weAlsoHave'
defaultMessage='We also have books in'
/>
);
}

function LeadIn() {
return (
<FormattedMessage
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/subjects/new/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function SubjectsPage() {
<JITLoad
importFn={importLanguageSelector}
otherLocales={otherLocales}
addPolish={true}
/>
<JITLoad importFn={importSubjectsListing} />
<JITLoad importFn={importTutorAd} />
Expand Down

0 comments on commit b0b164a

Please sign in to comment.