This repository was archived by the owner on Oct 4, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathLanguageNotice.js
More file actions
89 lines (77 loc) · 2.69 KB
/
Copy pathLanguageNotice.js
File metadata and controls
89 lines (77 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* External dependencies */
import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
import { __, sprintf } from "@wordpress/i18n";
import interpolateComponents from "interpolate-components";
/* Internal dependencies */
import { makeOutboundLink } from "@yoast/helpers";
const YoastLanguageNotice = styled.p`
margin: 1em 0;
`;
const ChangeLanguageLink = makeOutboundLink( styled.a`
margin-left: 4px;
` );
/**
* Returns the LanguageNotice component.
*
* @param {Object} props The props for this language notice wrapper.
* @param {string} props.changeLanguageLink The URL where the language can be changed.
* @param {bool} props.canChangeLanguage Whether or not the language can be changed.
* @param {string} props.language The currently set language.
* @param {bool} props.showLanguageNotice Whether or not the language notice is shown.
*
* @returns {ReactElement} The LanguageNotice component.
*/
export default class LanguageNotice extends PureComponent {
/**
* Renders the language notice. Provides a link to a setting page if the currently set language can be changed.
* Provides a message to contact an administrator otherwise.
*
* @returns {ReactElement} The rendered language notice.
*/
render() {
const {
changeLanguageLink,
canChangeLanguage,
language,
showLanguageNotice,
} = this.props;
if ( ! showLanguageNotice ) {
return null;
}
// Determine the correct text.
/* Translators: %s expands to the actual language. */
let text = __( "Your site language is set to %s. ", "yoast-components" );
if ( ! canChangeLanguage ) {
/* Translators: %s expands to the actual language. */
text = __( "Your site language is set to %s. If this is not correct, contact your site administrator.", "yoast-components" );
}
// Replace the %s with a strong marked language.
text = sprintf( text, `{{strong}}${ language }{{/strong}}` );
// Replace the strong marking with an actual ReactComponent.
text = interpolateComponents( {
mixedString: text,
components: { strong: <strong /> },
} );
return (
<YoastLanguageNotice>
{ text }
{ canChangeLanguage && <ChangeLanguageLink href={ changeLanguageLink }>
{ __( "Change language", "yoast-components" ) }
</ChangeLanguageLink> }
</YoastLanguageNotice>
);
}
}
export const languageNoticePropType = {
changeLanguageLink: PropTypes.string.isRequired,
canChangeLanguage: PropTypes.bool,
language: PropTypes.string.isRequired,
showLanguageNotice: PropTypes.bool,
};
LanguageNotice.propTypes = languageNoticePropType;
LanguageNotice.defaultProps = {
canChangeLanguage: false,
showLanguageNotice: false,
};