mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
The content localization feature we have (e.g. on meta) currently assumes that everyone has set their user preferences language to a language that we support. If Eleni sets Greek as her Interface language, it is a non-supported language. Posts written in Chinese or French will remain in Chinese or French, as there is no Greek translation. The commit shows Eleni localized posts in English (i.e. site default locale) when a post is written in a different language. A site setting `content_localization_use_default_locale_when_unsupported` is default true and introduced.
49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe BasicPostSerializer do
|
|
describe "#name" do
|
|
fab!(:user)
|
|
fab!(:post) { Fabricate(:post, user: user, cooked: "Hur dur I am a cooked raw") }
|
|
let(:serializer) { BasicPostSerializer.new(post, scope: Guardian.new, root: false) }
|
|
let(:json) { serializer.as_json }
|
|
|
|
it "returns the name it when `enable_names` is true" do
|
|
SiteSetting.enable_names = true
|
|
expect(json[:name]).to be_present
|
|
end
|
|
|
|
it "doesn't return the name it when `enable_names` is false" do
|
|
SiteSetting.enable_names = false
|
|
expect(json[:name]).to be_blank
|
|
end
|
|
|
|
describe "#cooked" do
|
|
it "returns the post's cooked" do
|
|
expect(json[:cooked]).to eq(post.cooked)
|
|
end
|
|
|
|
describe "localizations" do
|
|
it "returns the localized cooked" do
|
|
SiteSetting.content_localization_enabled = true
|
|
Fabricate(:post_localization, post: post, cooked: "X", locale: "ja")
|
|
I18n.locale = "ja"
|
|
post.update!(locale: "en")
|
|
|
|
expect(json[:cooked]).to eq("X")
|
|
end
|
|
|
|
it "returns the site default locale cooked when no exact match found and `content_localization_use_default_locale_when_unsupported` is true" do
|
|
SiteSetting.content_localization_enabled = true
|
|
SiteSetting.content_localization_use_default_locale_when_unsupported = true
|
|
SiteSetting.default_locale = "el"
|
|
|
|
Fabricate(:post_localization, post:, cooked: "site default cooked", locale: "el")
|
|
I18n.locale = "ja"
|
|
post.update!(locale: "en")
|
|
|
|
expect(json[:cooked]).to eq("site default cooked")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|