From afe1cc13693b18f5648c3e5e42a95db02b50407b Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Tue, 31 Oct 2023 14:47:02 -0500 Subject: [PATCH] Add Polish to language selectors For: https://github.com/openstax/openstax.org/issues/2349 --- .../language-selector/language-selector.js | 25 ++++++++++++++++--- .../language-selector/language-selector.scss | 1 - .../shell/header/menus/main-menu/main-menu.js | 16 ++++++++---- src/app/lang/en.js | 2 ++ src/app/lang/es.js | 2 ++ .../subjects/new/language-selector-section.js | 4 +-- .../pages/subjects/new/specific/context.js | 2 +- .../new/specific/translation-selector.tsx | 15 +++++++++++ src/app/pages/subjects/new/subjects.js | 1 + 9 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/app/components/language-selector/language-selector.js b/src/app/components/language-selector/language-selector.js index 82ec53d97..bb3c7fa91 100644 --- a/src/app/components/language-selector/language-selector.js +++ b/src/app/components/language-selector/language-selector.js @@ -8,9 +8,12 @@ import './language-selector.scss'; // You can't use a variable for id const languageFromLocale = { en: () => , - es: () => + es: () => , + pl: () => }; +const polishSite = 'https://openstax.pl/podreczniki'; + const NoLanguage = () => null; export function useLanguageText(locale) { @@ -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 + + + + ); + } + return ( @@ -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; } diff --git a/src/app/components/language-selector/language-selector.scss b/src/app/components/language-selector/language-selector.scss index f3c65cda0..ddb10be61 100644 --- a/src/app/components/language-selector/language-selector.scss +++ b/src/app/components/language-selector/language-selector.scss @@ -4,7 +4,6 @@ align-items: center; column-gap: 1rem; display: flex; - line-height: 1.9rem; @include wider-than($tablet-max) { justify-content: center; diff --git a/src/app/components/shell/header/menus/main-menu/main-menu.js b/src/app/components/shell/header/menus/main-menu/main-menu.js index 5a238fb62..c695cba01 100644 --- a/src/app/components/shell/header/menus/main-menu/main-menu.js +++ b/src/app/components/shell/header/menus/main-menu/main-menu.js @@ -77,11 +77,17 @@ function SubjectsMenu() { /> ))} {pathname.startsWith('/details/books') ? null : ( - - {' '} - - - )} + + + {' '} + + + + {' '} + + + + )} {language === 'en' ?
: null} ); diff --git a/src/app/lang/en.js b/src/app/lang/en.js index b8404c466..3e8742e8c 100644 --- a/src/app/lang/en.js +++ b/src/app/lang/en.js @@ -2,6 +2,7 @@ export default { en: 'English', es: 'Spanish', and: 'and', + pl: 'Polish', option: 'option', options: 'options', fewer: 'fewer', @@ -9,6 +10,7 @@ export default { 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', diff --git a/src/app/lang/es.js b/src/app/lang/es.js index 4d08391b9..bb55db180 100644 --- a/src/app/lang/es.js +++ b/src/app/lang/es.js @@ -1,6 +1,7 @@ export default { en: 'inglés', es: 'español', + pl: 'polaco', and: 'y', option: 'opción', options: 'opciones', @@ -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', diff --git a/src/app/pages/subjects/new/language-selector-section.js b/src/app/pages/subjects/new/language-selector-section.js index 9cb8da780..ba2ff4e8e 100644 --- a/src/app/pages/subjects/new/language-selector-section.js +++ b/src/app/pages/subjects/new/language-selector-section.js @@ -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 (
- +
); diff --git a/src/app/pages/subjects/new/specific/context.js b/src/app/pages/subjects/new/specific/context.js index cf67f961e..f64c36c52 100644 --- a/src/app/pages/subjects/new/specific/context.js +++ b/src/app/pages/subjects/new/specific/context.js @@ -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'); diff --git a/src/app/pages/subjects/new/specific/translation-selector.tsx b/src/app/pages/subjects/new/specific/translation-selector.tsx index 6785724e2..777eed57f 100644 --- a/src/app/pages/subjects/new/specific/translation-selector.tsx +++ b/src/app/pages/subjects/new/specific/translation-selector.tsx @@ -45,11 +45,26 @@ export default function TranslationSelector({ otherLocales={otherLocales} LinkPresentation={LinkPresentation} /> +
+ + {' '} + + +
); } +function PolishLeadIn() { + return ( + + ); +} + function LeadIn() { return (