[Glitch] Add ability to translate server rules

Port 8c51a8ba94 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire
2025-05-21 13:54:12 +02:00
parent c7dfb84b12
commit 7dfa5d6d1b
2 changed files with 16 additions and 9 deletions

View File

@@ -44,6 +44,7 @@ const severityMessages = {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
server: state.getIn(['server', 'server']), server: state.getIn(['server', 'server']),
locale: state.getIn(['meta', 'locale']),
extendedDescription: state.getIn(['server', 'extendedDescription']), extendedDescription: state.getIn(['server', 'extendedDescription']),
domainBlocks: state.getIn(['server', 'domainBlocks']), domainBlocks: state.getIn(['server', 'domainBlocks']),
}); });
@@ -91,6 +92,7 @@ class About extends PureComponent {
static propTypes = { static propTypes = {
server: ImmutablePropTypes.map, server: ImmutablePropTypes.map,
locale: ImmutablePropTypes.string,
extendedDescription: ImmutablePropTypes.map, extendedDescription: ImmutablePropTypes.map,
domainBlocks: ImmutablePropTypes.contains({ domainBlocks: ImmutablePropTypes.contains({
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
@@ -114,7 +116,7 @@ class About extends PureComponent {
}; };
render () { render () {
const { multiColumn, intl, server, extendedDescription, domainBlocks } = this.props; const { multiColumn, intl, server, extendedDescription, domainBlocks, locale } = this.props;
const isLoading = server.get('isLoading'); const isLoading = server.get('isLoading');
return ( return (
@@ -168,12 +170,15 @@ class About extends PureComponent {
<p><FormattedMessage id='about.not_available' defaultMessage='This information has not been made available on this server.' /></p> <p><FormattedMessage id='about.not_available' defaultMessage='This information has not been made available on this server.' /></p>
) : ( ) : (
<ol className='rules-list'> <ol className='rules-list'>
{server.get('rules').map(rule => ( {server.get('rules').map(rule => {
<li key={rule.get('id')}> const text = rule.getIn(['translations', locale, 'text']) || rule.get('text');
<div className='rules-list__text'>{rule.get('text')}</div> const hint = rule.getIn(['translations', locale, 'hint']) || rule.get('hint');
{rule.get('hint').length > 0 && (<div className='rules-list__hint'>{rule.get('hint')}</div>)} return (
</li> <li key={rule.get('id')}>
))} <div className='rules-list__text'>{text}</div>
{hint.length > 0 && (<div className='rules-list__hint'>{hint}</div>)}
</li>
)})}
</ol> </ol>
))} ))}
</Section> </Section>

View File

@@ -12,6 +12,7 @@ import Option from './components/option';
const mapStateToProps = state => ({ const mapStateToProps = state => ({
rules: state.getIn(['server', 'server', 'rules']), rules: state.getIn(['server', 'server', 'rules']),
locale: state.getIn(['meta', 'locale']),
}); });
class Rules extends PureComponent { class Rules extends PureComponent {
@@ -19,6 +20,7 @@ class Rules extends PureComponent {
static propTypes = { static propTypes = {
onNextStep: PropTypes.func.isRequired, onNextStep: PropTypes.func.isRequired,
rules: ImmutablePropTypes.list, rules: ImmutablePropTypes.list,
locale: PropTypes.string,
selectedRuleIds: ImmutablePropTypes.set.isRequired, selectedRuleIds: ImmutablePropTypes.set.isRequired,
onToggle: PropTypes.func.isRequired, onToggle: PropTypes.func.isRequired,
}; };
@@ -34,7 +36,7 @@ class Rules extends PureComponent {
}; };
render () { render () {
const { rules, selectedRuleIds } = this.props; const { rules, locale, selectedRuleIds } = this.props;
return ( return (
<> <>
@@ -49,7 +51,7 @@ class Rules extends PureComponent {
value={item.get('id')} value={item.get('id')}
checked={selectedRuleIds.includes(item.get('id'))} checked={selectedRuleIds.includes(item.get('id'))}
onToggle={this.handleRulesToggle} onToggle={this.handleRulesToggle}
label={item.get('text')} label={item.getIn(['translations', locale, 'text']) || item.get('text')}
multiple multiple
/> />
))} ))}