Skip to content
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
30 changes: 6 additions & 24 deletions audformat/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing as typing

import iso639
from iso639.exceptions import InvalidLanguageValue
import iso3166
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -1288,32 +1289,13 @@ def map_language(language: str) -> str:
'eng'

"""
result = None

if len(language) == 2:
try:
result = iso639.languages.get(alpha2=language.lower())
except KeyError:
pass
elif len(language) == 3:
try:
result = iso639.languages.get(part3=language.lower())
except KeyError:
pass
else:
try:
result = iso639.languages.get(name=language.title())
except KeyError:
pass

if result is not None:
result = result.part3

if not result:
try:
return iso639.Lang(
language.title() if len(language) > 3 else language.lower()
).pt3
except InvalidLanguageValue:
raise ValueError(f"'{language}' is not supported by ISO 639-3.")

return result


def read_csv(
*args,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ requires-python = '>=3.9' # pandas >=2.1.0
dependencies = [
'audeer >=2.0.0',
'audiofile >=0.4.0',
'iso-639',
'iso639-lang',
'iso3166',
'oyaml',
'pandas >=2.1.0', # for pyarrow -> timedelta conversion
Expand Down