Skip to content

Commit

Permalink
翻訳ボタンを非表示にする設定項目を追加 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
MitarashiDango authored Feb 21, 2024
1 parent f05635b commit 7fbfb3e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/javascript/mastodon/components/status_content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PureComponent } from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';

import classnames from 'classnames';
import { Link, withRouter } from 'react-router-dom';
import { withRouter } from 'react-router-dom';
import Permalink from './permalink';

import ImmutablePropTypes from 'react-immutable-proptypes';
Expand All @@ -13,7 +13,7 @@ import { connect } from 'react-redux';
import ChevronRightIcon from '@/material-icons/400-24px/chevron_right.svg?react';
import { Icon } from 'mastodon/components/icon';
import PollContainer from 'mastodon/containers/poll_container';
import { autoPlayGif, languages as preloadedLanguages } from 'mastodon/initial_state';
import { autoPlayGif, languages as preloadedLanguages, hideTranslateButton } from 'mastodon/initial_state';

const MAX_HEIGHT = 706; // 22px * 32 (+ 2px padding at the top)

Expand Down Expand Up @@ -246,7 +246,7 @@ class StatusContent extends PureComponent {
const renderReadMore = this.props.onClick && status.get('collapsed');
const contentLocale = intl.locale.replace(/[_-].*/, '');
const targetLanguages = this.props.languages?.get(status.get('language') || 'und');
const renderTranslate = this.props.onTranslate && this.context.identity.signedIn && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('search_index').trim().length > 0 && targetLanguages?.includes(contentLocale);
const renderTranslate = !hideTranslateButton && this.props.onTranslate && this.context.identity.signedIn && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('search_index').trim().length > 0 && targetLanguages?.includes(contentLocale);

const content = { __html: statusContent ?? getStatusContent(status) };
const spoilerContent = { __html: status.getIn(['translation', 'spoilerHtml']) || status.get('spoilerHtml') };
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/mastodon/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @property {string} display_media
* @property {string} domain
* @property {boolean=} expand_spoilers
* @property {boolean} hide_translate_button
* @property {boolean} limited_federation_mode
* @property {string} locale
* @property {string | null} mascot
Expand Down Expand Up @@ -84,6 +85,7 @@ export const displayMedia = getMeta('display_media');
export const domain = getMeta('domain');
export const expandSpoilers = getMeta('expand_spoilers');
export const forceSingleColumn = !getMeta('advanced_layout');
export const hideTranslateButton = getMeta('hide_translate_button');
export const limitedFederationMode = getMeta('limited_federation_mode');
export const mascot = getMeta('mascot');
export const me = getMeta('me');
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/user/has_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@ def setting_webui_styles
def setting_reverse_nav
settings['web.mod_reverse_nav']
end

def setting_hide_translate_button
settings['web.hide_translate_button']
end
end
1 change: 1 addition & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class KeyError < Error; end
setting :mod_wider_column, default: false
setting :mod_webui_styles, default: 'default', in: %w(default compact legacy)
setting :mod_reverse_nav, default: false
setting :hide_translate_button, default: false
end

namespace :notification_emails do
Expand Down
37 changes: 22 additions & 15 deletions app/serializers/initial_state_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,7 @@ def meta
store = default_meta_store

if object.current_account
store[:me] = object.current_account.id.to_s
store[:unfollow_modal] = object_account_user.setting_unfollow_modal
store[:boost_modal] = object_account_user.setting_boost_modal
store[:delete_modal] = object_account_user.setting_delete_modal
store[:auto_play_gif] = object_account_user.setting_auto_play_gif
store[:display_media] = object_account_user.setting_display_media
store[:expand_spoilers] = object_account_user.setting_expand_spoilers
store[:reduce_motion] = object_account_user.setting_reduce_motion
store[:disable_swiping] = object_account_user.setting_disable_swiping
store[:advanced_layout] = object_account_user.setting_advanced_layout
store[:use_blurhash] = object_account_user.setting_use_blurhash
store[:use_pending_items] = object_account_user.setting_use_pending_items
store[:show_trends] = Setting.trends && object_account_user.setting_trends
store[:webui_styles] = object_account_user.setting_webui_styles
store[:wider_column] = object_account_user.setting_wider_column
store = store.merge(current_account_settings)
else
store[:auto_play_gif] = Setting.auto_play_gif
store[:display_media] = Setting.display_media
Expand Down Expand Up @@ -114,6 +100,27 @@ def default_meta_store
}
end

def current_account_settings
{
me: object.current_account.id.to_s,
unfollow_modal: object_account_user.setting_unfollow_modal,
boost_modal: object_account_user.setting_boost_modal,
delete_modal: object_account_user.setting_delete_modal,
auto_play_gif: object_account_user.setting_auto_play_gif,
display_media: object_account_user.setting_display_media,
expand_spoilers: object_account_user.setting_expand_spoilers,
reduce_motion: object_account_user.setting_reduce_motion,
disable_swiping: object_account_user.setting_disable_swiping,
advanced_layout: object_account_user.setting_advanced_layout,
use_blurhash: object_account_user.setting_use_blurhash,
use_pending_items: object_account_user.setting_use_pending_items,
show_trends: Setting.trends && object_account_user.setting_trends,
webui_styles: object_account_user.setting_webui_styles,
wider_column: object_account_user.setting_wider_column,
hide_translate_button: object_account_user.setting_hide_translate_button,
}
end

def object_account_user
object.current_account.user
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/settings/preferences/appearance/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,8 @@
.fields-group
= ff.input :'web.expand_content_warnings', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_expand_spoilers')

.fields-group
= ff.input :'web.hide_translate_button', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_hide_translate_button')

.actions
= f.button :button, t('generic.save_changes'), type: :submit
1 change: 1 addition & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ en:
setting_display_media_show_all: Show all
setting_expand_spoilers: Always expand posts marked with content warnings
setting_hide_network: Hide your social graph
setting_hide_translate_button: Hide translation button
setting_reduce_motion: Reduce motion in animations
setting_system_font_ui: Use system's default font
setting_theme: Site theme
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ ja:
setting_display_media_show_all: 表示
setting_expand_spoilers: 閲覧注意としてマークされた投稿を常に展開する
setting_hide_network: 繋がりを隠す
setting_hide_translate_button: 翻訳ボタンを非表示にする
setting_reduce_motion: アニメーションの動きを減らす
setting_system_font_ui: システムのデフォルトフォントを使う
setting_theme: サイトテーマ
Expand Down

0 comments on commit 7fbfb3e

Please sign in to comment.