generated from geoadmin/template-service-flask
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
PB-227: Helptext translations
- Loading branch information
Showing
13 changed files
with
1,981 additions
and
2 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,55 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
from flask import abort | ||
|
||
from app.settings import DESCRIPTION_FOLDER | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_icon_set_description(icon_set=''): | ||
''' | ||
Return json containing the description in all available languages for all icons of the | ||
provided icon set | ||
''' | ||
path = find_descripton_file(icon_set) | ||
if not os.path.isfile(path): | ||
return None | ||
|
||
with open(path, encoding='utf-8') as f: | ||
icon_set_descriptions = json.load(f) | ||
|
||
return icon_set_descriptions | ||
|
||
|
||
def get_icon_description(icon_name='', icon_set=''): | ||
''' | ||
Return json containing the description in all available languages for an icon in the specified | ||
icon set | ||
''' | ||
path = find_descripton_file(icon_set) | ||
if not os.path.isfile(path): | ||
return None | ||
|
||
with open(path, encoding='utf-8') as f: | ||
df = json.load(f) | ||
|
||
try: | ||
icon_description = df[icon_name] | ||
except KeyError: | ||
logger.error("Description for icon not found: %s", icon_name) | ||
abort(404, "Description for icon not found") | ||
|
||
return icon_description | ||
|
||
|
||
def find_descripton_file(icon_set): | ||
''' | ||
Return file path of description file if it exists or False in case it doesn't | ||
''' | ||
path = os.path.abspath(os.path.join(DESCRIPTION_FOLDER, icon_set)) + '-dictionary.json' | ||
if os.path.isfile(path): | ||
return path | ||
return False |
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
Oops, something went wrong.