diff --git a/lib/ai_helper/assistant.rb b/lib/ai_helper/assistant.rb index 99af0d3d..aa360a7e 100644 --- a/lib/ai_helper/assistant.rb +++ b/lib/ai_helper/assistant.rb @@ -29,7 +29,9 @@ module DiscourseAi prompts.map do |prompt| if prompt.name == "translate" locale = user.effective_locale - locale_hash = LocaleSiteSetting.language_names[locale] + locale_hash = + LocaleSiteSetting.language_names[locale] || + LocaleSiteSetting.language_names[locale.split("_")[0]] translation = I18n.t( "discourse_ai.ai_helper.prompts.translate", diff --git a/spec/lib/modules/ai_helper/assistant_spec.rb b/spec/lib/modules/ai_helper/assistant_spec.rb index fd3f479c..83233116 100644 --- a/spec/lib/modules/ai_helper/assistant_spec.rb +++ b/spec/lib/modules/ai_helper/assistant_spec.rb @@ -59,6 +59,11 @@ RSpec.describe DiscourseAi::AiHelper::Assistant do ) end + it "does not raise an error when effective_locale does not exactly match keys in LocaleSiteSetting" do + SiteSetting.default_locale = "zh_CN" + expect { subject.available_prompts(user) }.not_to raise_error + end + context "when illustrate post model is enabled" do before do SiteSetting.ai_helper_illustrate_post_model = "stable_diffusion_xl"