-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial, working impl. of #128 (not hooked up)
This is a technically-working implementation of #128, which creates an object, exposed at runtime as lingua_franca.config, which descends from dict. More robust get/set methods to follow. The implementation is extensible to support full use of localization and 'full lang codes'. Either that or hooking it up to the functions will be next.
- Loading branch information
1 parent
eee9570
commit f473b80
Showing
5 changed files
with
75 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
### DO NOT CHANGE THIS IMPORT ORDER ### | ||
from .internal import get_active_langs, get_supported_locs, \ | ||
get_full_lang_code | ||
|
||
from .configuration import Config | ||
|
||
### END OF IMPORT ORDER ### | ||
|
||
from .internal import get_default_lang, set_default_lang, get_default_loc, \ | ||
get_active_langs, _set_active_langs, get_primary_lang_code, \ | ||
get_full_lang_code, resolve_resource_file, load_language, \ | ||
load_languages, unload_language, unload_languages, get_supported_langs | ||
_set_active_langs, get_primary_lang_code, resolve_resource_file, \ | ||
load_language, load_languages, unload_language, unload_languages, \ | ||
get_supported_langs | ||
|
||
|
||
from lingua_franca import config | ||
config = Config() |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import json | ||
from os import path | ||
|
||
from lingua_franca import get_active_langs, get_supported_locs, \ | ||
get_full_lang_code | ||
from lingua_franca.internal import UnsupportedLanguageError, resolve_resource_file | ||
|
||
default_global_values = \ | ||
{ | ||
'load_langs_on_demand': False | ||
} | ||
|
||
class LangConfig(dict): | ||
def __init__(self, lang_code): | ||
if lang_code not in get_supported_locs(): | ||
# DO NOT catch UnsupportedLanguageError! | ||
# If this fails, we want to crash. This can *only* result from | ||
# someone trying to override sanity checks upstairs. There are no | ||
# circumstances under which this should fail and allow the program | ||
# to continue. | ||
lang_code = get_full_lang_code(lang_code) | ||
|
||
|
||
resource_file = resolve_resource_file(f'text/{lang_code}/config.json') | ||
with open(resource_file, 'r', encoding='utf-8') as i_file: | ||
default_values = json.load(i_file) | ||
for k in default_values: | ||
self[k] = default_values[k] | ||
|
||
class Config(dict): | ||
def __init__(self): | ||
self['global'] = dict(default_global_values) | ||
for lang in get_active_langs(): | ||
''' | ||
TODO proper full loc support here will handle languages similarly to global: | ||
self['en']['universal'] for 'default' English config | ||
(all dialects if not overridden) | ||
self['en']['en-us'] for overrides specific to en-US | ||
self['en']['en-au'] for overrides specific to en-AU | ||
and so forth. | ||
''' | ||
if all((lang not in self.keys(), lang not in get_supported_locs())): | ||
self[lang] = {} | ||
self[lang]['universal'] = LangConfig(lang) | ||
# begin portion that will need to adapt for the todo above | ||
full_loc = lang if lang in get_supported_locs() else \ | ||
get_full_lang_code(lang) | ||
self[lang][full_loc] = LangConfig(lang) |
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,3 @@ | ||
{ | ||
"short_scale": true | ||
} |