Skip to content

Commit

Permalink
get_current_locale: fall back to DEFAULT_LOCALE when translation …
Browse files Browse the repository at this point in the history
…settings schema is not valid (#207)

- needed to fix final CI bug for jupyterlab/jupyterlab#10929
  • Loading branch information
telamonian authored Sep 7, 2021
1 parent eae679e commit 680f4fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ docs/source/changelog.md
# generated cli docs
docs/source/api/app-config.rst

.vscode/
# jetbrains IDE stuff
*.iml
.idea/

# ms IDE stuff
*.code-workspace
.history
.vscode
9 changes: 8 additions & 1 deletion jupyterlab_server/settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ def get(self, schema_name=""):
"""Get setting(s)"""
# Need to be update here as translator locale is not change when a new locale is put
# from frontend
translator.set_locale(self.get_current_locale())
try:
locale = self.get_current_locale()
except web.HTTPError as e:
# fallback in case of missing (404) or misshapen (500) translation schema
locale = DEFAULT_LOCALE
'Failed loading or validating translation settings schema'

translator.set_locale(locale)

result, warnings = get_settings(
self.app_settings_dir,
Expand Down
33 changes: 19 additions & 14 deletions jupyterlab_server/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
from jupyterlab_server.translation_utils import DEFAULT_LOCALE, L10N_SCHEMA_NAME, is_valid_locale
import os
from glob import glob

import json
import json5
from jsonschema import Draft4Validator as Validator
from jsonschema import ValidationError
from jsonschema import Draft4Validator as Validator, ValidationError
from jupyter_server.services.config.manager import ConfigManager, recursive_update
import os
from tornado import web

from .server import APIHandler, tz
from .translation_utils import DEFAULT_LOCALE, L10N_SCHEMA_NAME, is_valid_locale

# The JupyterLab settings file extension.
SETTINGS_EXTENSION = '.jupyterlab-settings'
Expand Down Expand Up @@ -436,14 +434,21 @@ def get_current_locale(self):
-----
If the locale setting is not available or not valid, it will default to jupyterlab_server.translation_utils.DEFAULT_LOCALE.
"""
settings, _ = get_settings(
self.app_settings_dir,
self.schemas_dir,
self.settings_dir,
schema_name=L10N_SCHEMA_NAME,
overrides=self.overrides,
labextensions_path=self.labextensions_path,
)
try:
settings, _ = get_settings(
self.app_settings_dir,
self.schemas_dir,
self.settings_dir,
schema_name=L10N_SCHEMA_NAME,
overrides=self.overrides,
labextensions_path=self.labextensions_path,
)
except web.HTTPError as e:
schema_warning = "Missing or misshappen translation settings schema:\n%s"
self.log.warn(schema_warning % str(e))

settings = {}

current_locale = settings.get("settings", {}).get("locale", DEFAULT_LOCALE)
if not is_valid_locale(current_locale):
current_locale = DEFAULT_LOCALE
Expand Down

0 comments on commit 680f4fe

Please sign in to comment.