Skip to content

Commit

Permalink
Update server.py to accept IETF BCP 47 language tags (#1399), closes #…
Browse files Browse the repository at this point in the history
…1352.

* Update server.py to accept local languages such as es-419
* Regression test for #1352.

Ref: https://en.wikipedia.org/wiki/IETF_language_tag

---------

Co-authored-by: Mathijs de Bruin <[email protected]>
  • Loading branch information
erauld and dokterbob authored Oct 10, 2024
1 parent 15c1691 commit 988eea6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 988eea6

Please sign in to comment.