Skip to content

Commit 680f4fe

Browse files
authored
get_current_locale: fall back to DEFAULT_LOCALE when translation settings schema is not valid (#207)
- needed to fix final CI bug for jupyterlab/jupyterlab#10929
1 parent eae679e commit 680f4fe

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ docs/source/changelog.md
2424
# generated cli docs
2525
docs/source/api/app-config.rst
2626

27-
.vscode/
27+
# jetbrains IDE stuff
28+
*.iml
29+
.idea/
30+
31+
# ms IDE stuff
32+
*.code-workspace
33+
.history
34+
.vscode

jupyterlab_server/settings_handler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ def get(self, schema_name=""):
3535
"""Get setting(s)"""
3636
# Need to be update here as translator locale is not change when a new locale is put
3737
# from frontend
38-
translator.set_locale(self.get_current_locale())
38+
try:
39+
locale = self.get_current_locale()
40+
except web.HTTPError as e:
41+
# fallback in case of missing (404) or misshapen (500) translation schema
42+
locale = DEFAULT_LOCALE
43+
'Failed loading or validating translation settings schema'
44+
45+
translator.set_locale(locale)
3946

4047
result, warnings = get_settings(
4148
self.app_settings_dir,

jupyterlab_server/settings_utils.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
# Copyright (c) Jupyter Development Team.
44
# Distributed under the terms of the Modified BSD License.
5-
import json
6-
from jupyterlab_server.translation_utils import DEFAULT_LOCALE, L10N_SCHEMA_NAME, is_valid_locale
7-
import os
85
from glob import glob
9-
6+
import json
107
import json5
11-
from jsonschema import Draft4Validator as Validator
12-
from jsonschema import ValidationError
8+
from jsonschema import Draft4Validator as Validator, ValidationError
139
from jupyter_server.services.config.manager import ConfigManager, recursive_update
10+
import os
1411
from tornado import web
1512

1613
from .server import APIHandler, tz
14+
from .translation_utils import DEFAULT_LOCALE, L10N_SCHEMA_NAME, is_valid_locale
1715

1816
# The JupyterLab settings file extension.
1917
SETTINGS_EXTENSION = '.jupyterlab-settings'
@@ -436,14 +434,21 @@ def get_current_locale(self):
436434
-----
437435
If the locale setting is not available or not valid, it will default to jupyterlab_server.translation_utils.DEFAULT_LOCALE.
438436
"""
439-
settings, _ = get_settings(
440-
self.app_settings_dir,
441-
self.schemas_dir,
442-
self.settings_dir,
443-
schema_name=L10N_SCHEMA_NAME,
444-
overrides=self.overrides,
445-
labextensions_path=self.labextensions_path,
446-
)
437+
try:
438+
settings, _ = get_settings(
439+
self.app_settings_dir,
440+
self.schemas_dir,
441+
self.settings_dir,
442+
schema_name=L10N_SCHEMA_NAME,
443+
overrides=self.overrides,
444+
labextensions_path=self.labextensions_path,
445+
)
446+
except web.HTTPError as e:
447+
schema_warning = "Missing or misshappen translation settings schema:\n%s"
448+
self.log.warn(schema_warning % str(e))
449+
450+
settings = {}
451+
447452
current_locale = settings.get("settings", {}).get("locale", DEFAULT_LOCALE)
448453
if not is_valid_locale(current_locale):
449454
current_locale = DEFAULT_LOCALE

0 commit comments

Comments
 (0)