Skip to content

Commit

Permalink
Fix language setting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jan 4, 2022
1 parent f8122ff commit 6accb48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions plugins/lab/fps_lab/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import json5
from pathlib import Path
import sys
from http import HTTPStatus
Expand All @@ -19,9 +20,10 @@
from .utils import get_federated_extensions


LOCALE = "en"

def init_router(router, redirect_after_root):
prefix_dir: Path = Path(sys.prefix)
LOCALE = "en"

extensions_dir = prefix_dir / "share" / "jupyter" / "labextensions"
federated_extensions, _ = get_federated_extensions(extensions_dir)
Expand Down Expand Up @@ -112,7 +114,7 @@ async def get_translation(
package = ep.load()
data = {}
for path in (
Path(package.__file__).parent / "locale" / "fr_FR" / "LC_MESSAGES"
Path(package.__file__).parent / "locale" / language / "LC_MESSAGES"
).glob("*.json"):
with open(path) as f:
data.update({path.stem: json.load(f)})
Expand Down Expand Up @@ -145,7 +147,7 @@ async def get_setting(
) as f:
schema = json.load(f)
key = f"{name1}:{name2}"
result = {
setting = {
"id": f"@jupyterlab/{key}",
"schema": schema,
"version": package["version"],
Expand All @@ -155,10 +157,11 @@ async def get_setting(
"created": None,
}
if user:
settings = json.loads(user.settings)
if key in settings:
result.update(settings[key])
return result
user_settings = json.loads(user.settings)
if key in user_settings:
setting.update(user_settings[key])
setting["settings"] = json5.loads(user_settings[key]["raw"])
return setting

@router.put(
"/lab/api/settings/@jupyterlab/{name0}:{name1}",
Expand Down Expand Up @@ -206,6 +209,7 @@ async def get_settings(user: User = Depends(current_user)):
}
if key in user_settings:
setting.update(user_settings[key])
setting["settings"] = json5.loads(user_settings[key]["raw"])
settings.append(setting)
return {"settings": settings}

Expand Down
1 change: 1 addition & 0 deletions plugins/lab/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install_requires =
fps-auth
aiofiles
babel
json5

[options.entry_points]
fps_router =
Expand Down

0 comments on commit 6accb48

Please sign in to comment.