FIX: Localize description excerpts as they have limits (#1490)

This commit is contained in:
Natalie Tay 2025-07-08 10:36:41 +08:00 committed by GitHub
parent 7357280e88
commit 56f025cf44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -10,8 +10,8 @@ module DiscourseAi
translated_name = ShortTextTranslator.new(text: category.name, target_locale:).translate translated_name = ShortTextTranslator.new(text: category.name, target_locale:).translate
translated_description = translated_description =
if category.description.present? if category.description_excerpt.present?
PostRawTranslator.new(text: category.description, target_locale:).translate PostRawTranslator.new(text: category.description_excerpt, target_locale:).translate
else else
"" ""
end end

View File

@ -28,7 +28,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
end end
fab!(:category) do fab!(:category) do
Fabricate(:category, name: "Test Category", description: "This is a test category") Fabricate(:category, name: "Test Category", description: "This is a test category. " * 50)
end end
describe ".localize" do describe ".localize" do
@ -42,7 +42,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
) )
post_raw_translator_stub( post_raw_translator_stub(
{ {
text: category.description, text: category.description_excerpt,
target_locale: target_locale, target_locale: target_locale,
translated: translated_cat_desc, translated: translated_cat_desc,
}, },
@ -61,7 +61,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
{ text: category.name, target_locale:, translated: translated_cat_name }, { text: category.name, target_locale:, translated: translated_cat_name },
) )
post_raw_translator_stub( post_raw_translator_stub(
{ text: category.description, target_locale:, translated: translated_cat_desc }, { text: category.description_excerpt, target_locale:, translated: translated_cat_desc },
) )
res = localizer.localize(category, target_locale) res = localizer.localize(category, target_locale)
@ -86,7 +86,11 @@ describe DiscourseAi::Translation::CategoryLocalizer do
{ text: category.name, target_locale: "es", translated: translated_cat_name }, { text: category.name, target_locale: "es", translated: translated_cat_name },
) )
post_raw_translator_stub( post_raw_translator_stub(
{ text: category.description, target_locale: "es", translated: translated_cat_desc }, {
text: category.description_excerpt,
target_locale: "es",
translated: translated_cat_desc,
},
) )
res = localizer.localize(category) res = localizer.localize(category)