Skip to content

Commit

Permalink
Merge pull request #724 from berkmancenter/translations-in-db
Browse files Browse the repository at this point in the history
Move site language to database
  • Loading branch information
peter-hank authored Sep 21, 2022
2 parents f150648 + 34727d3 commit 5f80af4
Show file tree
Hide file tree
Showing 110 changed files with 839 additions and 676 deletions.
8 changes: 4 additions & 4 deletions app/helpers/notices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def iso_countries
end

def first_time_visitor_content
MarkdownParser.render(t('first_time_visitor'))
MarkdownParser.render(Translation.t('first_time_visitor'))
end

def label_for_url_input(url_type, notice)
Expand Down Expand Up @@ -89,7 +89,7 @@ def with_redacted_urls(text)
sanitized_text = ActionView::Base.full_sanitizer.sanitize(text)
redacted_text = sanitized_text.gsub(
%r{(http[s]?://[w]*[\.]*[^/|$]*)(\S*)},
'\1/[REDACTED]'
"\\1/#{Lumen::REDACTION_MASK}"
)

words_to_highlight = params[:term]&.split(' ') || []
Expand Down Expand Up @@ -151,7 +151,7 @@ def infringing_url_label(notice)
when ::CourtOrder
'Targeted URL'
when ::DataProtection, ::LawEnforcementRequest
'URL mentioned in request'
Translation.t('notice_show_works_law_enf_gov_infringing_url_label')
when ::Defamation
'Allegedly Defamatory URL'
when ::Counterfeit
Expand All @@ -166,7 +166,7 @@ def copyrighted_url_label(notice)
when ::DMCA, ::Other
'Original Work URL'
when ::LawEnforcementRequest
'URL of original work'
Translation.t('notice_show_works_law_enf_gov_copyrighted_url_label')
end
end

Expand Down
7 changes: 3 additions & 4 deletions app/models/defamation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Defamation < Notice
MASK = 'REDACTED'
REDACTION_REGEX = /google|youtube/i

define_elasticsearch_mapping(works: [:description])
Expand All @@ -16,15 +15,15 @@ def to_partial_path

def sender_name
if hide_identities?
MASK
Lumen::REDACTION_MASK
else
super
end
end

def principal_name
if hide_identities?
MASK
Lumen::REDACTION_MASK
else
super
end
Expand All @@ -46,7 +45,7 @@ def auto_redact

# Some submitters redact on their end using this phrase, let's avoid
# double-redaction
return if entity_name == '[REDACTED]'
return if entity_name == Lumen::REDACTION_MASK

instance_redactor = InstanceRedactor.new(
custom_redactors,
Expand Down
5 changes: 2 additions & 3 deletions app/models/other.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Other < Notice
MASK = 'REDACTED'
REDACTION_REGEX = /google|youtube/i

define_elasticsearch_mapping(works: [:description])
Expand All @@ -16,15 +15,15 @@ def to_partial_path

def sender_name
if hide_identities?
MASK
Lumen::REDACTION_MASK
else
super
end
end

def principal_name
if hide_identities?
MASK
Lumen::REDACTION_MASK
else
super
end
Expand Down
27 changes: 27 additions & 0 deletions app/models/translation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'validates_automatically'

class Translation < ApplicationRecord
include ValidatesAutomatically

validates :key, presence: true
validates_uniqueness_of :key

after_save do
self.class.load_all
end

@@translations = nil

def self.load_all
@@translations = Translation.all
end

def self.t(key)
@@translations
&.select { |translation| translation.key == key }
&.first
&.body
&.html_safe ||
''
end
end
18 changes: 8 additions & 10 deletions app/views/api_submitter_requests/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<% title 'Apply for submitter JS plugin access' %>
<% title Translation.t('api_submitter_widget_request_page_title') %>

<article class="api-submitter-access-request">
<section class="body">
<p>In order to use the submitter JS plugin you need to be verified and accepted.</p>
<p>Fill this simple form and wait for an email from us.</p>
<p>Integration documentation of the plugin is located here: <a href="https://github.com/berkmancenter/lumendatabase/blob/master/doc/submitter_javascript_widget.md" target="_blank">https://github.com/berkmancenter/lumendatabase/blob/master/doc/submitter_javascript_widget.md</a>.</p>
<%= Translation.t('api_submitter_widget_request_info') %>

<%= simple_form_for(@api_submitter_request) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<h3>General information</h2>
<%= f.input :email, label: 'Contact email address', hint: 'We will use this email address to contact you regarding your application.', required: true %>
<%= f.input :submissions_forward_email, label: 'Submissions forwarding email address', hint: 'We will send a copy of each submission to this email address.', required: true %>
<%= f.input :description, as: :text, label: 'Describe shortly your website/application', required: true %>
<h3><%= Translation.t('api_submitter_widget_request_general_information') %></h3>
<%= f.input :email, label: Translation.t('api_submitter_widget_request_contact_email'), hint: Translation.t('api_submitter_widget_request_contact_email_help_text'), required: true %>
<%= f.input :submissions_forward_email, label: Translation.t('api_submitter_widget_request_forward_email'), hint: Translation.t('api_submitter_widget_request_forward_email_help_text'), required: true %>
<%= f.input :description, as: :text, label: Translation.t('api_submitter_widget_request_description'), required: true %>

<h3>Your company/organization/personal data</h2>
<h3><%= Translation.t('api_submitter_widget_request_your_company') %></h3>
<div class="required">
<%= f.input :entity_name, label: 'Name', required: true %>
<%= f.input :entity_kind, label: 'Type', prompt: nil, collection: Entity::KINDS, required: true %>
Expand All @@ -39,7 +37,7 @@
</div>

<div class="form-actions">
<%= f.submit 'Submit' %>
<%= f.submit Translation.t('api_submitter_widget_request_submit') %>
</div>
<% end %>
</section>
Expand Down
2 changes: 1 addition & 1 deletion app/views/blog_entries/_comfy_archive.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% cache "blog_archive_#{params[:page]}" do %>
<% title 'Blog Archive' %>
<% title Translation.t('blog_archive_page_title') %>

<% blog_entries = blog_posts(@cms_site) %>

Expand Down
6 changes: 3 additions & 3 deletions app/views/blog_feed/index.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "Lumen Database Blog"
xml.author "Lumen Database"
xml.description "Lumen Database is an independent 3rd party research project studying cease and desist letters concerning online content."
xml.title Translation.t('blog_archive_xml_title')
xml.author Translation.t('blog_archive_xml_author')
xml.description Translation.t('blog_archive_xml_description')
xml.link "https://www.lumendatabase.org/"
xml.language "en"

Expand Down
3 changes: 1 addition & 2 deletions app/views/captcha_gateway/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<article class="captcha-gateway">
<section class="body">
<div class="main">
<h4>We need to check if you are a human, resolve the captcha and hit the submit button, please.</h4>
<h4>You will be then redirected to your destination page.</h4>
<%= Translation.t('captcha_gateway_info') %>

<form id="captcha-gateway-form" method="get">
<input type="hidden" name="destination" value="<%= params[:destination] %>">
Expand Down
2 changes: 1 addition & 1 deletion app/views/entities/_address.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span class="private">[Private]</span>
<span class="private"><%= Translation.t('notice_entity_private') %></span>
<span>
<%= [entity.city, entity.state, entity.zip, entity.country_code&.upcase].reject { |item| item&.blank? }.join (', ') %>
</span>
2 changes: 1 addition & 1 deletion app/views/entities/_entity.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h5><%= role %></h5>
<h6 class="entity-name">
<% if [:sender, :principal].include?(role.to_sym) && notice.hide_identities? %>
REDACTED
<%= Lumen::REDACTION_MASK %>
<% else %>
<%=
link_to(
Expand Down
2 changes: 1 addition & 1 deletion app/views/entities/_recipient.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= render 'entities/address', entity: entity %>

<% if date_sent(notice) != date_received(notice) %>
<span class="date received">Received on <%= date_received(notice) %></span>
<span class="date received"><%= Translation.t('notice_entity_recipient_received') %> <%= date_received(notice) %></span>
<% end %>
4 changes: 2 additions & 2 deletions app/views/entities/_sender.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if !notice.hide_identities? %>
<% if notice.on_behalf_of_principal? %>
<h6>
<span class="on_behalf_of">on behalf of</span>
<span class="on_behalf_of"><%= Translation.t('notice_entity_sender_behalf') %></span>
<%=
link_to(
notice.principal_name,
Expand All @@ -14,7 +14,7 @@
<% end %>

<% if date_sent(notice).present? %>
<span class="date sent">Sent on <%= date_sent(notice) %></span>
<span class="date sent"><%= Translation.t('notice_entity_sender_sent') %> <%= date_sent(notice) %></span>
<% end %>

<% if entity.country_code.present? %>
Expand Down
12 changes: 6 additions & 6 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
<h1><%= image_tag("logo_2x.png", :size=> "340x82") %></h1>
<%= render 'shared/search' %>
<div class="more-info">
<p class="about">The Lumen database collects and analyzes legal complaints and requests for removal of online materials, helping Internet users to know their rights and understand the law. These data enable us to study the prevalence of legal threats and let Internet users see the source of content removals.</p>
<p class="about"><%= Translation.t('home_about_text') %></p>
</div>
</section>

<div class="site-news">
<section class="recent-notices">
<h2>Recent Takedown Notices</h2>
<h2><%= Translation.t('home_recent_takedown_notices') %></h2>
<ol id="recent-notices">
<%= render partial: 'notice', collection: @notices %>
</ol>
<a href="notices_feed?format=rss"><%= image_tag("feed_icon.png", :size => "14x14") %></a>
</section>
<% cache( 'lumendatabase-tweets', expires_in: 5.minutes ) { %>
<% cache('lumendatabase-tweets', expires_in: 5.minutes ) { %>
<section class="tweets">
<h2>@lumendatabase on twitter</h2>
<a class="twitter-timeline" data-height="380" href="https://twitter.com/lumendatabase?ref_src=twsrc%5Etfw">Tweets by lumendatabase</a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<h2><%= Translation.t('home_lumendatabase_on_twitter') %></h2>
<a class="twitter-timeline" data-height="380" href="https://twitter.com/lumendatabase?ref_src=twsrc%5Etfw"><%= Translation.t('home_tweets_by_lumendatabase') %></a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</section>
<% } %>
<section class="news-snippets">
<h2>From the Blog</h2>
<h2><%= Translation.t('home_from_the_blog') %></h2>
<ol id="recent-blog-entries">
<%= render partial: 'blog_entry', collection: @blog_entries, cached: true %>
</ol>
Expand Down
15 changes: 5 additions & 10 deletions app/views/mailers/api_submitter_request_approved.text.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
Hi,

your submitter plugin access request has been approved.

Your plugin private key is: <%= @user.widget_public_key %>

You can use it to configure the plugin. Integration documentation of the plugin is located here: https://github.com/berkmancenter/lumendatabase/blob/master/doc/submitter_javascript_widget.md.

Thank you,
Lumen Database team
<%= format(
Translation.t('mailers_api_submitter_request_approved'),
widget_public_key: @user.widget_public_key
).html_safe
%>
9 changes: 1 addition & 8 deletions app/views/mailers/api_submitter_request_rejected.text.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
Hi,

your submitter plugin access request has been rejected.

If you want to appeal contact the Lumen staff at [email protected].

Thank you,
Lumen Database team
<%= Translation.t('mailers_api_submitter_request_rejected') %>
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
Hi,

You are getting this notification because documents have been updated for this notice: <%= @notice.title %>.

This is a single-use link: <%= notice_url(@notice, access_token: @token_url.token, host: Chill::Application.config.site_host) %>.

Using this link you can download the documents.

Be aware that you can use it for the next <%= pluralize(@hours_active, 'hour') %> only.

To disable notifications about document updates click here: <%= disable_documents_notification_token_url_url(@token_url, host: Chill::Application.config.site_host, token: @token_url.token) %>.

Thank you,
Lumen Database team
<%= format(
Translation.t('mailers_notice_file_uploads_notifications'),
single_use_link: notice_url(@notice, access_token: @token_url.token, host: Chill::Application.config.site_host),
time: pluralize(@hours_active, 'hour'),
disable_notification_link: disable_documents_notification_token_url_url(@token_url, host: Chill::Application.config.site_host, token: @token_url.token),
notice_title: @notice.title
).html_safe
%>
24 changes: 13 additions & 11 deletions app/views/mailers/send_new_url_confirmation.text.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Hi,

this is a single-use link you requested on the Lumen Database website: <%= notice_url(@notice, access_token: @token_url.token, host: Chill::Application.config.site_host) %>.

Using this link you can see full details of <%= notice_url(@notice, host: Chill::Application.config.site_host) %>.

Be aware that you can use it for the next <%= pluralize(@hours_active, 'hour') %> only.
<%= format(
Translation.t('mailers_new_token_url_part_1'),
single_use_link: notice_url(@notice, access_token: @token_url.token, host: Chill::Application.config.site_host),
normal_link: notice_url(@notice, host: Chill::Application.config.site_host),
time: pluralize(@hours_active, 'hour')
).html_safe
%>

<% if @token_url.documents_notification %>
To disable notifications about document updates click here: <%= disable_documents_notification_token_url_url(@token_url, host: Chill::Application.config.site_host, token: @token_url.token) %>.

<%= format(
Translation.t('mailers_new_token_url_part_2'),
disable_notifications_link: disable_documents_notification_token_url_url(@token_url, host: Chill::Application.config.site_host, token: @token_url.token)
)
%>
<% end %>
Thank you,
Lumen Database team
<%= Translation.t('mailers_new_token_url_part_3') %>
15 changes: 6 additions & 9 deletions app/views/mailers/yt_submission_confirmed.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Thank you for your recent submission to Lumen Database with subject "<%= @notice.subject %>".

You can link to the notice using the following URL: https://www.lumendatabase.org/notices/<%= @notice.id %>

At the moment, that is likely a placeholder page, but if the notice is annotated and published, the link will resolve to the published notice.

If you have any questions, please contact our team, [email protected].

Lumen Database
<%= format(
Translation.t('mailers_youtube_confirmation'),
subject: @notice.subject,
notice_id: @notice.id
).html_safe
%>
15 changes: 6 additions & 9 deletions app/views/mailers/yt_submission_confirmed.text.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Thank you for your recent submission to Lumen Database with subject "<%= @notice.subject %>".

You can link to the notice using the following URL: https://www.lumendatabase.org/notices/<%= @notice.id %>

At the moment, that is likely a placeholder page, but if the notice is annotated and published, the link will resolve to the published notice.

If you have any questions, please contact our team, [email protected].

Lumen Database
<%= format(
Translation.t('mailers_youtube_confirmation'),
subject: @notice.subject,
notice_id: @notice.id
).html_safe
%>
10 changes: 5 additions & 5 deletions app/views/media_mentions/search/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
</div>
<div class="media-mention-result-meta">
<% if result.author.present? %>
<div><label>Author</label> <%= result.author %></div>
<div><label><%= Translation.t('media_mentions_author') %></label> <%= result.author %></div>
<% end %>
<% if result.source.present? %>
<div><label>Source</label> <%= result.source %></div>
<div><label><%= Translation.t('media_mentions_source') %></label> <%= result.source %></div>
<% end %>
<% if result.document_type.present? %>
<div><label>Document Type</label> <%= result.document_type %></div>
<div><label><%= Translation.t('media_mentions_doc_type') %></label> <%= result.document_type %></div>
<% end %>
<% if result.date.present? %>
<div><label>Date Published</label> <%= result.date %></div>
<div><label><%= Translation.t('media_mentions_date_published') %></label> <%= result.date %></div>
<% end %>
<% if result.scale_of_mention.present? %>
<div><label>Scale of Mention</label> <%= result.scale_of_mention %></div>
<div><label><%= Translation.t('media_mentions_scale') %></label> <%= result.scale_of_mention %></div>
<% end %>
</div>
<% end %>
Loading

0 comments on commit 5f80af4

Please sign in to comment.