discourse/plugins/discourse-ai/spec/lib/agents/locale_detector_spec.rb
Natalie Tay 7684b418ae
DEV: Also pass configured supported locales into the prompt for language detection (#40029)
Related:
https://meta.discourse.org/t/norwegian-is-identified-as-no-by-locale-detector-agent-content-localization-supported-locales-is-nb-no/402859

Norwegian posts get detected as `no` while sites set the target as
`nb_NO`. In this PR we'll appending whatever's in
content_localization_supported_locales (i.e. `Norwegian Bokmål: nb-NO`
in this case) to the prompt.
2026-05-14 21:15:26 +08:00

37 lines
1.3 KiB
Ruby
Vendored

# frozen_string_literal: true
describe DiscourseAi::Agents::LocaleDetector do
describe "#system_prompt" do
let(:prompt) { described_class.new.system_prompt }
context "when content_localization_supported_locales is blank" do
before { SiteSetting.content_localization_supported_locales = "" }
it "leaves the static block intact with no extra entries" do
expect(prompt).to include(
"- Korean: ko\n\nIf the language is not in this list, use the appropriate IETF language tag code.",
)
end
end
context "with obscure codes" do
before { SiteSetting.content_localization_supported_locales = "nb_NO|zh_TW" }
it "appends every recognisable code in hyphenated form" do
expect(prompt).to include(
"- Korean: ko\n- Norwegian Bokmål: nb-NO\n- Chinese: zh-TW\n\nIf the language is not in this list, use the appropriate IETF language tag code.",
)
expect(prompt).to include("- Norwegian Bokmål: nb-NO")
expect(prompt).to include("- Chinese: zh-TW")
end
end
context "when supported locales overlap with the static list" do
before { SiteSetting.content_localization_supported_locales = "ja" }
it "does not duplicate codes already listed" do
expect(prompt.scan(/^\s*- Japanese: ja\s*$/).size).to eq(1)
end
end
end
end