-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify locale handling by using lowercase strings everywhere (#768)
* simplify locale handling by using lowercase strings everywhere * add test for version string * remove guard clause * poetry is now complaining about missing project.name in CI * update lockfile * force a refresh of the lockfile
- Loading branch information
1 parent
fe91f3e
commit 01b49c5
Showing
16 changed files
with
1,269 additions
and
1,221 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
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[project] | ||
name = "modelbench" | ||
requires-python = ">=3.10, !=3.12.5, <3.13" | ||
|
||
[tool.poetry] | ||
|
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Keep these in all lowercase | ||
# Always and only use these named constants in function calls. | ||
# They are meant to simplify the Locale(enum) and prevent case errors. | ||
EN_US = "en_us" | ||
FR_FR = "fr_fr" | ||
ZH_CN = "zh_cn" | ||
HI_IN = "hi_in" | ||
DEFAULT_LOCALE = "en_us" | ||
|
||
# add the other languages after we have official and practice prompt sets | ||
LOCALES = (EN_US, FR_FR) | ||
|
||
|
||
def is_valid(locale: str) -> bool: | ||
return locale in LOCALES | ||
|
||
|
||
def display_for(locale: str) -> str: | ||
chunks = locale.split("_") | ||
try: | ||
assert len(chunks) == 2 | ||
display = f"{chunks[0].lower()}_{chunks[1].upper()}" | ||
except: | ||
display = locale | ||
return display | ||
|
||
|
||
def bad_locale(locale: str) -> str: | ||
return f"You requested \"{locale}.\" Only {', '.join(LOCALES)} (in lowercase) are supported." | ||
|
||
|
||
def validate_locale(locale) -> bool: | ||
assert is_valid(locale), bad_locale(locale) | ||
return True |
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.