This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
Status#translatable?
with language matrix in separate endpo…
…int (mastodon#24037)
- Loading branch information
Showing
19 changed files
with
164 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/controllers/api/v1/instances/translation_languages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Instances::TranslationLanguagesController < Api::BaseController | ||
skip_before_action :require_authenticated_user!, unless: :whitelist_mode? | ||
|
||
before_action :set_languages | ||
|
||
def show | ||
expires_in 1.day, public: true | ||
render json: @languages | ||
end | ||
|
||
private | ||
|
||
def set_languages | ||
if TranslationService.configured? | ||
@languages = Rails.cache.fetch('translation_service/languages', expires_in: 7.days, race_condition_ttl: 1.hour) { TranslationService.configured.languages } | ||
@languages['und'] = @languages.delete(nil) if @languages.key?(nil) | ||
else | ||
@languages = {} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
spec/controllers/api/v1/instances/translation_languages_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe Api::V1::Instances::TranslationLanguagesController do | ||
describe 'GET #show' do | ||
context 'when no translation service is configured' do | ||
it 'returns empty language matrix' do | ||
get :show | ||
|
||
expect(response).to have_http_status(200) | ||
expect(body_as_json).to eq({}) | ||
end | ||
end | ||
|
||
context 'when a translation service is configured' do | ||
before do | ||
service = instance_double(TranslationService::DeepL, languages: { nil => %w(en de), 'en' => ['de'] }) | ||
allow(TranslationService).to receive(:configured?).and_return(true) | ||
allow(TranslationService).to receive(:configured).and_return(service) | ||
end | ||
|
||
it 'returns language matrix' do | ||
get :show | ||
|
||
expect(response).to have_http_status(200) | ||
expect(body_as_json).to eq({ und: %w(en de), en: ['de'] }) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.