docs/i18n_implementation_guide.md
This document captures the comprehensive scope and lessons learned from implementing Brazilian Portuguese (pt) internationalization throughout the Forem codebase, alongside existing English (en) and French (fr) translations.
config/locales/helpers/pt.yml - Helper translationsconfig/locales/helpers/en.yml - Updated to match structureconfig/locales/helpers/fr.yml - Updated to match structureconfig/locales/controllers/admin/pt.yml - Admin controller translationsconfig/locales/kaminari.pt.yml - Pagination translationsconfig/locales/liquid_tags/pt.yml - Liquid tag translationsconfig/locales/services/pt.yml - Service translationsconfig/locales/devise.fr.yml - Created missing French Devise fileapp/models/subforem.rb - Added default_locale attr_accessorapp/controllers/admin/subforems_controller.rb - Added locale parameter handlingapp/views/admin/subforems/_form.html.erb - Added locale picker dropdownapp/workers/subforems/create_from_scratch_worker.rb - Added locale parameterapp/services/ai/community_copy.rb - Added locale-specific promptsapp/services/ai/forem_tags.rb - Added locale-specific promptsapp/services/ai/about_page_generator.rb - Added locale-specific promptsspec/models/subforem_spec.rb - Updated method signaturesspec/requests/admin/subforems_spec.rb - Updated expectationsspec/requests/admin/subforems_about_page_spec.rb - Updated expectationsspec/workers/subforems/create_from_scratch_worker_spec.rb - Updated method callsbin/locale_file_lookup - Enhanced locale analysis toolbin/create_missing_locales - Created missing locale filesbin/fix_helpers_structure - Fixed nested structure issuesbin/add_missing_helper_keys - Added missing helper keysdocs/portuguese_internationalization_summary.md - Implementation summarydocs/locale_analysis.md - Locale coverage analysisdocs/README.md - Documentation indexIssue: 34 inconsistent interpolations found initially Root Cause: Portuguese translations missing interpolation variables present in English versions
Examples:
# β Wrong - Missing interpolation
pt: "Grupo criado com sucesso!"
en: "Successfully created group: %{group}"
# β
Correct - Matching interpolations
pt: "Grupo criado com sucesso: %{group}"
en: "Successfully created group: %{group}"
Lesson: Always ensure interpolation variables match exactly between locales.
Issue: Deeply nested structures caused test failures
Root Cause: Inconsistent nesting between en, fr, and pt files
Example:
# β Wrong - Inconsistent nesting
en:
helpers:
label:
video: "Video"
pt:
helpers:
settings_helper:
social_link_helper:
label:
video: "VΓdeo"
# β
Correct - Identical structure
en:
helpers:
label:
video: "Video"
pt:
helpers:
label:
video: "VΓdeo"
Lesson: Maintain identical YAML structure across all locale files.
Issue: Worker method signature changed from 5 to 6 parameters Impact: All tests calling the worker needed updates
Example:
# β Old signature
Subforems::CreateFromScratchWorker.perform_async(id, brain_dump, name, logo_url, bg_image_url)
# β
New signature
Subforems::CreateFromScratchWorker.perform_async(id, brain_dump, name, logo_url, bg_image_url, default_locale)
Lesson: When changing method signatures, update ALL related tests immediately.
Issue: Tests failed because mocked methods returned nil instead of expected values
Root Cause: Settings::Community.set_community_name mock didn't return the name
Example:
# β Wrong - Returns nil
allow(Settings::Community).to receive(:set_community_name)
# β
Correct - Returns expected value
allow(Settings::Community).to receive(:set_community_name).and_return(name)
Lesson: Ensure mocks return appropriate values, not just nil.
Issue: Locale files are scattered across multiple directories Structure:
config/locales/
βββ *.yml (main locale files)
βββ controllers/
β βββ admin/
β βββ api/
βββ helpers/
βββ liquid_tags/
βββ services/
βββ devise.*.yml
βββ kaminari.*.yml
βββ devise_invitable.*.yml
Lesson: Use the bin/locale_file_lookup tool to identify all files that need updates.
Issue: AI services needed locale-specific instructions
Solution: Added get_locale_instruction methods with specific language requirements
Example:
def get_locale_instruction
case @locale
when 'pt'
"LANGUAGE REQUIREMENT: Generate ALL content in Brazilian Portuguese..."
when 'fr'
"LANGUAGE REQUIREMENT: Generate ALL content in French..."
else
"LANGUAGE REQUIREMENT: Generate ALL content in English..."
end
end
Lesson: AI content generation requires explicit language instructions in prompts.
bin/locale_file_lookupbin/create_missing_localesbin/fix_helpers_structurebin/add_missing_helper_keysBefore starting any i18n work:
bin/locale_file_lookup to identify all affected filesi18n-tasks check-consistent-interpolationsbin/locale_file_lookup to identify scopei18n-tasks check-consistent-interpolationsbin/locale_file_lookup to understand scopeThis guide should be updated with each new i18n implementation to capture additional lessons learned and best practices.