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_description =
if category.description.present?
PostRawTranslator.new(text: category.description, target_locale:).translate
if category.description_excerpt.present?
PostRawTranslator.new(text: category.description_excerpt, target_locale:).translate
else
""
end

View File

@ -28,7 +28,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
end
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
describe ".localize" do
@ -42,7 +42,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
)
post_raw_translator_stub(
{
text: category.description,
text: category.description_excerpt,
target_locale: target_locale,
translated: translated_cat_desc,
},
@ -61,7 +61,7 @@ describe DiscourseAi::Translation::CategoryLocalizer do
{ text: category.name, target_locale:, translated: translated_cat_name },
)
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)
@ -86,7 +86,11 @@ describe DiscourseAi::Translation::CategoryLocalizer do
{ text: category.name, target_locale: "es", translated: translated_cat_name },
)
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)