mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 07:38:29 +00:00
Starting i18n language file support
This commit is contained in:
@@ -7,7 +7,7 @@ from pydantic import BaseModel, Field, PrivateAttr, ValidationError, model_valid
|
||||
|
||||
class I18N(BaseModel):
|
||||
_translations: Dict[str, Dict[str, str]] = PrivateAttr()
|
||||
language_file: str = Field(
|
||||
language_file: Optional[str] = Field(
|
||||
default=None,
|
||||
description="Path to the translation file to load",
|
||||
)
|
||||
|
||||
40
tests/utilities/test_i18n.py
Normal file
40
tests/utilities/test_i18n.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
|
||||
from crewai.utilities.i18n import I18N
|
||||
|
||||
|
||||
def test_load_translation():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
assert i18n._translations is not None
|
||||
|
||||
|
||||
def test_slice():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
assert isinstance(i18n.slice("role_playing"), str)
|
||||
|
||||
|
||||
def test_errors():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
assert isinstance(i18n.errors("unexpected_format"), str)
|
||||
|
||||
|
||||
def test_tools():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
assert isinstance(i18n.tools("ask_question"), str)
|
||||
|
||||
|
||||
def test_retrieve():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
assert isinstance(i18n.retrieve("slices", "role_playing"), str)
|
||||
|
||||
|
||||
def test_retrieve_not_found():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_translation()
|
||||
with pytest.raises(Exception):
|
||||
i18n.retrieve("nonexistent_kind", "nonexistent_key")
|
||||
Reference in New Issue
Block a user