Coverage for app / backend / src / tests / test_i18n.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-03 06:18 +0000

1import pytest 

2 

3from couchers.i18n.localize import get_main_i18next 

4 

5 

6@pytest.fixture(autouse=True) 

7def _(testconfig): 

8 pass 

9 

10 

11def test_translations_loaded(): 

12 """Test that translations are loaded from JSON files""" 

13 i18next = get_main_i18next() 

14 

15 # Should have at least English errors loaded 

16 en_lang = i18next.languages_by_code.get("en") 

17 assert en_lang is not None 

18 assert en_lang.strings_by_key.get("errors.account_not_found") is not None 

19 

20 # Other languages should also exist 

21 assert len(i18next.languages_by_code) > 1 

22 

23 

24def test_fallback_chain(): 

25 """Test that fallbacks are correctly set up""" 

26 i18next = get_main_i18next() 

27 

28 # Example: fr-CA should fallback to fr, which should fallback to en 

29 fr_CA = i18next.languages_by_code["fr-CA"] 

30 fr = i18next.languages_by_code["fr"] 

31 en = i18next.languages_by_code["en"] 

32 

33 assert fr_CA.fallbacks == [fr, en] 

34 assert fr.fallbacks == [en] 

35 assert en.fallbacks == [] 

36 

37 assert i18next.default_language == en