sppas 5.1.0

https://sppas.org/

Module sppas.core.coreutils

Class ISO639

Description

Manage language information based on ISO 639-3 codes.

This class provides a lookup table that maps ISO 639-3 codes to their corresponding ISO 639-1 codes and human-readable language names.

Example
 >>> iso = ISO639()
 >>> language_info = iso.get_language_info('eng')
 >>> language_info.iso639_1_code
 > 'en'
 >>> language_info.language_name
 > 'English'
 >>> iso.get_language_info('xyz')
 > Traceback (most recent call last):
 > ...
 > LanguageNotFoundError: Language code 'xyz' not found.

Public functions

get_language_info

Return the corresponding LanguageInfo object for a given ISO 639-3 code.

Parameters
  • iso6393code: (str) The 3-letter ISO 639-3 code for the language.
Returns
  • (LanguageInfo) The corresponding LanguageInfo object.
Raises
  • ValueError: If the provided ISO 639-3 code is not found in the lookup table.
View Source
@staticmethod
def get_language_info(iso639_3_code: str) -> LanguageInfo:
    """Return the corresponding LanguageInfo object for a given ISO 639-3 code.

        :param iso639_3_code: (str) The 3-letter ISO 639-3 code for the language.
        :return: (LanguageInfo) The corresponding LanguageInfo object.
        :raises: ValueError: If the provided ISO 639-3 code is not found in the lookup table.

        """
    iso639_3_code = iso639_3_code.lower()
    language_info = ISO639.LANGUAGES.get(iso639_3_code)
    if language_info is None:
        raise LanguageNotFoundError(iso639_3_code)
    return language_info