I encountered an inconsistency in Django’s translation system while working with multilingual support. Specifically, when calling get_language_info('iw'), Django raises a KeyError: unknown language code iw. However, when checking the same language code using check_for_language('iw'), it returns True. This behavior suggests a potential bug or inconsistency in language code handling.
Steps to Reproduce:
-
Ensure Django is installed and configured for translations.
-
Add multiple language codes to
LANGUAGESinsettings.py. -
Run the following Python code in the Django shell:
from django.utils.translation import get_language_info, check_for_language print(check_for_language('iw')) # Returns True print(get_language_info('iw')) # Raises KeyError
Expected Behavior:
Both get_language_info('iw') and check_for_language('iw') should be consistent. Since check_for_language('iw') returns True, get_language_info('iw') should return relevant language metadata instead of raising a KeyError.
Actual Behavior:
check_for_language('iw')returnsTrue, indicating that ‘iw’ is a recognized language code.get_language_info('iw')raises aKeyError, suggesting the language code is not recognized.
Environment Details:
- Django Version: Django 5.0
- Python Version: Python 3.12.0
- Operating System: windows
Additional Notes:
- The ISO 639-1 standard previously used ‘iw’ for Hebrew, but it has since been replaced by ‘he’.
- Django may be internally using ‘he’ instead of ‘iw’, causing this mismatch.
- If Django officially supports ‘iw’,
get_language_info()should handle it correctly.
Suggested Fix:
- Ensure that
get_language_info()recognizes ‘iw’ as an alias for ‘he’. - If ‘iw’ is deprecated,
check_for_language()should returnFalsefor consistency.