Skip to content

Commit

Permalink
replace iso-639 with iso639-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
ramppdev committed Sep 14, 2024
1 parent 5a8f650 commit 7b802c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
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

0 comments on commit 7b802c6

Please sign in to comment.