-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from pyinat/i18n
Add support for displaying and searching common names for configured locale
- Loading branch information
Showing
12 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"af": "Afrikaans", "ar": "\u0627\u0644\u0639\u0631\u0628\u064a\u0629", "be": "\u0431\u0435\u043b\u0430\u0440\u0443\u0441\u043a\u0430\u044f", "bg": "\u0431\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438", "br": "brezhoneg", "ca": "catal\u00e0", "cs": "\u010de\u0161tina", "da": "dansk", "de": "Deutsch", "el": "\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac", "en": "English", "eo": "esperanto", "es": "espa\u00f1ol", "et": "eesti", "eu": "euskara", "fa": "\u0641\u0627\u0631\u0633\u06cc", "fi": "suomi", "fil": "Filipino", "fr": "fran\u00e7ais", "gl": "galego", "haw": "\u02bb\u014clelo Hawai\u02bbi", "he": "\u05e2\u05d1\u05e8\u05d9\u05ea", "hr": "hrvatski", "hu": "magyar", "id": "Indonesia", "it": "italiano", "ja": "\u65e5\u672c\u8a9e", "ka": "\u10e5\u10d0\u10e0\u10d7\u10e3\u10da\u10d8", "kk": "\u049b\u0430\u0437\u0430\u049b \u0442\u0456\u043b\u0456", "kn": "\u0c95\u0ca8\u0ccd\u0ca8\u0ca1", "ko": "\ud55c\uad6d\uc5b4", "lb": "L\u00ebtzebuergesch", "lt": "lietuvi\u0173", "lv": "latvie\u0161u", "mi": "M\u0101ori", "mk": "\u043c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0438", "mr": "\u092e\u0930\u093e\u0920\u0940", "nb": "norsk bokm\u00e5l", "nl": "Nederlands", "oc": "occitan", "pl": "polski", "pt": "portugu\u00eas", "ro": "rom\u00e2n\u0103", "ru": "\u0440\u0443\u0441\u0441\u043a\u0438\u0439", "sat": "\u1c65\u1c5f\u1c71\u1c5b\u1c5f\u1c72\u1c64", "si": "\u0dc3\u0dd2\u0d82\u0dc4\u0dbd", "sk": "sloven\u010dina", "sl": "sloven\u0161\u010dina", "sq": "shqip", "sr": "\u0441\u0440\u043f\u0441\u043a\u0438", "sv": "svenska", "sw": "Kiswahili", "th": "\u0e44\u0e17\u0e22", "tr": "T\u00fcrk\u00e7e", "uk": "\u0443\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430", "vi": "Ti\u1ebfng Vi\u1ec7t", "zh": "\u4e2d\u6587", "zh-CN": "\u4e2d\u6587 (\u7b80\u4f53, \u4e2d\u56fd)"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# flake8: noqa: F401 | ||
from naturtag.utils.i18n import read_locales | ||
from naturtag.utils.image_glob import get_valid_image_paths | ||
from naturtag.utils.thumbnails import generate_thumbnail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Internationalization utilities""" | ||
import json | ||
import sqlite3 | ||
from logging import getLogger | ||
|
||
from naturtag.constants import DB_PATH, LOCALES_PATH, PathOrStr | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def get_locales(db_path: PathOrStr = DB_PATH) -> dict[str, str]: | ||
"""Get all locale codes represented in the FTS table and their localised names""" | ||
from babel import Locale, UnknownLocaleError | ||
|
||
with sqlite3.connect(db_path) as conn: | ||
results = conn.execute('SELECT DISTINCT(language_code) from taxon_fts').fetchall() | ||
locales = sorted([r[0] for r in results if r[0]]) | ||
|
||
locale_dict = {} | ||
for locale in locales: | ||
try: | ||
locale_dict[locale] = Locale.parse(locale.replace('-', '_')).display_name | ||
except UnknownLocaleError as e: | ||
logger.warning(e) | ||
|
||
locale_dict.pop('und') # "Undefined"; seems to be a mix of languages | ||
return locale_dict | ||
|
||
|
||
def write_locales(db_path: PathOrStr = DB_PATH): | ||
locale_dict = get_locales(db_path) | ||
with open(LOCALES_PATH, 'w') as f: | ||
f.write(json.dumps(locale_dict)) | ||
|
||
|
||
def read_locales() -> dict[str, str]: | ||
try: | ||
with open(LOCALES_PATH) as f: | ||
return json.loads(f.read()) | ||
except IOError as e: | ||
logger.warning(e) | ||
return {'en': 'English'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters