Skip to content

Commit

Permalink
add a string directing to beta.apertium.org (#483)
Browse files Browse the repository at this point in the history
**Description:**
This PR addresses issue #361 and also builds upon and supersedes the
changes proposed in PR #422.

**Changes Made:**
- Modified `config.ts` by adding `showMoreLanguagesLink` and specified
its type as `boolean` in `types.ts`. Also, added `more_languages` to
`stringReplacements`.
- Modified `AboutModal.tsx` by conditionally rendering `more_languages`
based on the value of `shouldDisplayString`, either true or false.
- In `index.test.tsx`, modified a test to check if, when the About
dialog is opened and `showMoreLanguagesLink` is set to `true`, it should
render the `more_languages`. Similarly, when `showMoreLanguagesLink` is
set to `false` and the About dialog is opened, it should not render the
`more_languages`.
  • Loading branch information
satti-hari-krishna-reddy committed Jan 11, 2024
1 parent c8c7b20 commit 48c022c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export default {

stringReplacements: {
'{{maintainer}}': "<a href='https://wiki.apertium.org/wiki/Apertium' target='_blank' rel='noopener'>Apertium</a>",
'{{more_languages}}': "<a href='https://beta.apertium.org' rel='noreferrer' target='_blank'>beta.apertium.org</a>",
},
showMoreLanguagesLink: false,
} as Config;
3 changes: 3 additions & 0 deletions src/components/footer/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Modal, { ModalProps } from 'react-bootstrap/Modal';
import Col from 'react-bootstrap/Col';
import Row from 'react-bootstrap/Row';

import { ConfigContext } from '../../context';
import { useLocalization } from '../../util/localization';

import alicanteLogo from './img/logouapp.gif';
Expand All @@ -18,6 +19,7 @@ import mineturLogo from './img/logomitc120.jpg';
import prompsitLogo from './img/prompsit150x52.png';

const AboutModal = (props: ModalProps): React.ReactElement => {
const config = React.useContext(ConfigContext);
const { t } = useLocalization();

return (
Expand All @@ -28,6 +30,7 @@ const AboutModal = (props: ModalProps): React.ReactElement => {
<Modal.Body>
<p dangerouslySetInnerHTML={{ __html: t('What_Is_Apertium') }} />
<p dangerouslySetInnerHTML={{ __html: t('Maintainer') }} />
{config.showMoreLanguagesLink && <p dangerouslySetInnerHTML={{ __html: t('More_Languages') }} />}

<Row className="lead">
<Col md="6">
Expand Down
34 changes: 25 additions & 9 deletions src/components/footer/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import * as React from 'react';
import { getAllByRole, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import Config from '../../../../config';
import { ConfigContext } from '../../../context';
import { Config as ConfigType } from '../../../types';

import Footer from '..';

const renderFooter = () => {
const renderFooter = (config: Partial<ConfigType> = {}) => {
const wrapRef = React.createRef<HTMLDivElement>();
const pushRef = React.createRef<HTMLDivElement>();

render(
<>
<div ref={wrapRef}>
<div ref={pushRef} />
</div>
<Footer pushRef={pushRef} wrapRef={wrapRef} />
</>,
<ConfigContext.Provider value={{ ...Config, ...config }}>
<>
<div ref={wrapRef}>
<div ref={pushRef} />
</div>
<Footer pushRef={pushRef} wrapRef={wrapRef} />
</>
</ConfigContext.Provider>,
);
};

Expand All @@ -37,8 +43,18 @@ describe('Footer', () => {
});

describe('navigation buttons', () => {
it('opens about dialog', () => {
renderFooter();
it('opens about dialog and display show more languages link when showMoreLanguagesLink is set to true', () => {
renderFooter({ showMoreLanguagesLink: true });

userEvent.click(screen.getByRole('button', { name: 'About-Default' }));

expect(screen.getByRole('dialog').textContent).toMatchInlineSnapshot(
`"About_Apertium-Default×CloseWhat_Is_Apertium-DefaultApertium-DefaultMore_Languages-Default"`,
);
});

it('opens about dialog and does not display show more languages link when showMoreLanguagesLink is set to false', () => {
renderFooter({ showMoreLanguagesLink: false });

userEvent.click(screen.getByRole('button', { name: 'About-Default' }));

Expand Down
1 change: 1 addition & 0 deletions src/strings/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"Help_Improve": "Help us improve Apertium!",
"Contact_Us": "Feel free to contact us if you find a mistake, there's a project you would like to see us work on, or you would like to help out.",
"Maintainer": "This website is maintained by {{maintainer}}.",
"More_Languages": "Looking for more languages? Try {{more_languages}}.",
"About_Title": "About this website",
"Enable_JS_Warning": "This site only works with JavaScript enabled, if you cannot <a href='http://www.enable-javascript.com/' target='_blank' rel='noopener'>enable Javascript</a>, then try the <a href='http://traductor.prompsit.com' target='_blank' rel='noopener'>translators at Prompsit</a>.",
"Not_Found_Error": "<b>404 Error:</b> Sorry, that page doesn't exist anymore!",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export type Config = {

subtitle?: string;
subtitleColor?: string;
showMoreLanguagesLink: boolean;
};

0 comments on commit 48c022c

Please sign in to comment.