[WIP] Html lang on statuses (#2297)
* Add html lang attributes around statuses * Remove urls from language detection
This commit is contained in:
parent
67dea31b0f
commit
629d35e6f5
|
@ -9,11 +9,19 @@ class LanguageDetector
|
|||
end
|
||||
|
||||
def to_iso_s
|
||||
WhatLanguage.new(:all).language_iso(text) || default_locale.to_sym
|
||||
WhatLanguage.new(:all).language_iso(text_without_urls) || default_locale.to_sym
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def text_without_urls
|
||||
text.dup.tap do |new_text|
|
||||
URI.extract(new_text).each do |url|
|
||||
new_text.gsub!(url, '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def default_locale
|
||||
account&.user&.locale || I18n.default_locale
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
%p{ style: 'margin-bottom: 0' }<
|
||||
%span.p-summary>= "#{status.spoiler_text} "
|
||||
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
|
||||
%div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
|
||||
%div.e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
|
||||
|
||||
|
||||
- unless status.media_attachments.empty?
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
%p{ style: 'margin-bottom: 0' }<
|
||||
%span.p-summary>= "#{status.spoiler_text} "
|
||||
%a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
|
||||
%div.e-content{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
|
||||
%div.e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status)
|
||||
|
||||
- unless status.media_attachments.empty?
|
||||
.status__attachments
|
||||
|
|
|
@ -23,6 +23,18 @@ describe LanguageDetector do
|
|||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
describe 'because of a URL' do
|
||||
it 'uses default locale when sent just a URL' do
|
||||
string = 'http://example.com/media/2kFTgOJLXhQf0g2nKB4'
|
||||
wl_result = WhatLanguage.new(:all).language_iso(string)
|
||||
expect(wl_result).not_to eq :en
|
||||
|
||||
result = described_class.new(string).to_iso_s
|
||||
|
||||
expect(result).to eq :en
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an account' do
|
||||
it 'uses the account locale when present' do
|
||||
user = double(:user, locale: 'fr')
|
||||
|
|
Loading…
Reference in New Issue