mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: Refresh translation override status when updating (#31233)
Translation overrides can be marked as "invalid interpolation keys" or "outdated" if the original translation is changed. We run a job every hour to check for this. We also have an admin problem check for it. The problem is we don't refresh this status when an admin updates the override. So even if the invalid keys are removed, the override will still show up under the "invalid" filter. There's a similar situation with the "outdated" status. The admin is shown a prompt which they can dismiss, which in turn updates the status, but updating the translation should also count as "addressing" it. This PR runs a refresh on the override status when updating.
This commit is contained in:
@ -17,11 +17,12 @@ RSpec.describe Jobs::CheckTranslationOverrides do
|
||||
end
|
||||
|
||||
it "marks translations with invalid interpolation keys" do
|
||||
invalid_translation.update_attribute("value", "Invalid %{foo}")
|
||||
|
||||
expect { described_class.new.execute({}) }.to change { invalid_translation.reload.status }.from(
|
||||
"up_to_date",
|
||||
).to("invalid_interpolation_keys")
|
||||
expect do
|
||||
invalid_translation.update_attribute("value", "Invalid %{foo}")
|
||||
described_class.new.execute({})
|
||||
end.to change { invalid_translation.reload.status }.from("up_to_date").to(
|
||||
"invalid_interpolation_keys",
|
||||
)
|
||||
end
|
||||
|
||||
it "marks translations that are outdated" do
|
||||
|
@ -352,7 +352,7 @@ RSpec.describe TranslationOverride do
|
||||
end
|
||||
end
|
||||
|
||||
describe "invalid_interpolation_keys" do
|
||||
describe "#invalid_interpolation_keys" do
|
||||
fab!(:translation) do
|
||||
Fabricate(
|
||||
:translation_override,
|
||||
@ -367,6 +367,45 @@ RSpec.describe TranslationOverride do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#refresh_status" do
|
||||
context "when fixing a translation with invalid interpolation keys" do
|
||||
fab!(:translation) do
|
||||
Fabricate(
|
||||
:translation_override,
|
||||
translation_key: "system_messages.welcome_user.subject_template",
|
||||
status: "invalid_interpolation_keys",
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
translation.update_attribute("value", "Hello, %{name}! Welcome to %{site_name}. %{foo}")
|
||||
end
|
||||
|
||||
it "refreshes to status to up to date" do
|
||||
expect {
|
||||
translation.update_attribute("value", "Hello, %{name}! Welcome to %{site_name}.")
|
||||
}.to change { translation.status }.from("invalid_interpolation_keys").to("up_to_date")
|
||||
end
|
||||
end
|
||||
|
||||
context "when updating a translation that has had the original updated" do
|
||||
fab!(:translation) do
|
||||
Fabricate(
|
||||
:translation_override,
|
||||
translation_key: "title",
|
||||
original_translation: "outdated",
|
||||
status: "outdated",
|
||||
)
|
||||
end
|
||||
|
||||
it "refreshes to status to up to date" do
|
||||
expect { translation.update_attribute("value", "Discourse") }.to change {
|
||||
translation.status
|
||||
}.from("outdated").to("up_to_date")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#message_format?" do
|
||||
subject(:override) { described_class.new(translation_key: key) }
|
||||
|
||||
|
Reference in New Issue
Block a user