Skip to content

feat: add Persian (Farsi) runtime and CLI localization - #2115

Open
mjpt1 wants to merge 1 commit into
FoundationAgents:mainfrom
mjpt1:feat/persian-localization-code
Open

mjpt1 wants to merge 1 commit into
FoundationAgents:mainfrom
mjpt1:feat/persian-localization-code

Conversation

@mjpt1

@mjpt1 mjpt1 commented Jul 23, 2026

Copy link
Copy Markdown

Features

  • Add lightweight metagpt/locale/ module for CLI and human-interaction strings
  • Add --language fa CLI flag and METAGPT_LANG env var support
  • Document language field in config/config2.example.yaml
  • Improve RoleZero language detection for Persian/Farsi/فارسی with config fallback
  • Add Persian example in requirement analysis prompts
  • Add unit tests for locale normalization (tests/metagpt/test_locale.py)

Feature Docs

  • See companion docs PR for Persian README and install guide

Influence

  • Default language remains English; Persian is opt-in via config/CLI/env
  • No gettext/Babel — consistent with existing MetaGPT i18n approach
  • Part 2 of 2 for Persian localization (see issue Add Persian (Farsi) localization support #2113)

Result

  • tests/metagpt/test_locale.py covers Persian alias normalization and message lookup

Refs #2113

Other

  • Complements docs PR (README_FA + install guide)
  • Can be reviewed/merged independently after docs PR

Add metagpt/locale for CLI strings, --language fa / METAGPT_LANG support, config language docs, RoleZero Persian detection, requirement analysis example, and locale tests.

Refs FoundationAgents#2113
@mjpt1

mjpt1 commented Jul 23, 2026

Copy link
Copy Markdown
Author

Companion docs PR: #2114

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a lightweight runtime localization layer to MetaGPT to support Persian (Farsi) for CLI/user-facing strings, plus improved RoleZero language detection guidance and examples. This aligns with issue #2113’s “PR 2 — Runtime / CLI” scope (opt-in Persian via config/CLI/env, no gettext/Babel).

Changes:

  • Introduces metagpt/locale/ with message catalogs, language alias normalization, and a t() translation helper.
  • Localizes key CLI + human-interaction prompts, and adds --language / METAGPT_LANG plumbing plus config documentation.
  • Improves RoleZero language-detection prompt to recognize Persian/Farsi/فارسی, and adds unit tests for alias normalization and message lookup.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/metagpt/test_locale.py Adds unit tests for locale normalization + message lookup.
metagpt/utils/human_interaction.py Switches human-interaction prompts/logs to localized message keys.
metagpt/software_company.py Adds CLI --language support and localizes CLI help/errors/config init messages.
metagpt/roles/di/role_zero.py Adds default-language guidance + Persian fallback logic for language detection.
metagpt/prompts/di/role_zero.py Updates detection prompt to recognize Persian/Farsi/فارسی and accept a default language hint.
metagpt/locale/messages.py Defines message catalogs and normalize_language() alias mapping.
metagpt/locale/__init__.py Provides locale initialization + global language state and t() lookup.
metagpt/actions/analyze_requirements.py Adds a Persian example to requirement-analysis prompts.
config/config2.example.yaml Documents language field and Persian aliases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to +49
if language:
config.language = set_language(language)
else:
init_locale(config.language)

Comment on lines +210 to +217
default_language = self.config.language or "English"
detect_language_prompt = DETECT_LANGUAGE_PROMPT.format(
requirement=self.planner.plan.goal,
default_language=default_language,
)
self.respond_language = await self.llm.aask(detect_language_prompt)
if default_language == "Persian" and self.respond_language.strip().lower() in ("english", ""):
self.respond_language = "Persian"
Comment on lines +4 to +6
from metagpt.locale import init_locale, set_language, t
from metagpt.locale.messages import normalize_language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants