Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update server.py to accept local languages such as es-419 #1399

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ async def oauth_azure_hf_callback(


_language_pattern = (
"^[a-zA-Z]{2,3}(-[a-zA-Z]{2,3})?(-[a-zA-Z]{2,8})?(-x-[a-zA-Z0-9]{1,8})?$"
"^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,3})?(-[a-zA-Z0-9]{2,8})?(-x-[a-zA-Z0-9]{1,8})?$"
)


Expand Down
12 changes: 12 additions & 0 deletions backend/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def test_project_translations_invalid_language(
assert not mock_load_translation.called


def test_project_translations_bcp47_language(
test_client: TestClient, mock_load_translation: Mock
):
"""Regression test for https://github.com/Chainlit/chainlit/issues/1352."""

response = test_client.get("/project/translations?language=es-419")
assert response.status_code == 200
assert "translation" in response.json()
mock_load_translation.assert_called_once_with("es-419")
mock_load_translation.reset_mock()


@pytest.fixture
def mock_get_current_user():
"""Override get_current_user() dependency."""
Expand Down
Loading