Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 56f025c

Browse files
authored
FIX: Localize description excerpts as they have limits (#1490)
1 parent 7357280 commit 56f025c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/translation/category_localizer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def self.localize(category, target_locale = I18n.locale)
1010

1111
translated_name = ShortTextTranslator.new(text: category.name, target_locale:).translate
1212
translated_description =
13-
if category.description.present?
14-
PostRawTranslator.new(text: category.description, target_locale:).translate
13+
if category.description_excerpt.present?
14+
PostRawTranslator.new(text: category.description_excerpt, target_locale:).translate
1515
else
1616
""
1717
end

spec/lib/translation/category_localizer_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def short_text_translator_stub(opts)
2828
end
2929

3030
fab!(:category) do
31-
Fabricate(:category, name: "Test Category", description: "This is a test category")
31+
Fabricate(:category, name: "Test Category", description: "This is a test category. " * 50)
3232
end
3333

3434
describe ".localize" do
@@ -42,7 +42,7 @@ def short_text_translator_stub(opts)
4242
)
4343
post_raw_translator_stub(
4444
{
45-
text: category.description,
45+
text: category.description_excerpt,
4646
target_locale: target_locale,
4747
translated: translated_cat_desc,
4848
},
@@ -61,7 +61,7 @@ def short_text_translator_stub(opts)
6161
{ text: category.name, target_locale:, translated: translated_cat_name },
6262
)
6363
post_raw_translator_stub(
64-
{ text: category.description, target_locale:, translated: translated_cat_desc },
64+
{ text: category.description_excerpt, target_locale:, translated: translated_cat_desc },
6565
)
6666

6767
res = localizer.localize(category, target_locale)
@@ -86,7 +86,11 @@ def short_text_translator_stub(opts)
8686
{ text: category.name, target_locale: "es", translated: translated_cat_name },
8787
)
8888
post_raw_translator_stub(
89-
{ text: category.description, target_locale: "es", translated: translated_cat_desc },
89+
{
90+
text: category.description_excerpt,
91+
target_locale: "es",
92+
translated: translated_cat_desc,
93+
},
9094
)
9195

9296
res = localizer.localize(category)

0 commit comments

Comments
 (0)