Skip to content

Commit

Permalink
fix frontend chocking on missing json file
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 18, 2024
1 parent f631a1f commit e90e52d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export default class Translator {
locale: Locale;

constructor(config: TranslatorConfig = {}) {
console.log('config', config);
const { languagePack = DEFAULT_LANGUAGE_PACK } = config;
this.i18n = new UntypedJed(languagePack) as Jed;
//console.log('this.i18n', this.i18n);

Check failure on line 52 in superset-frontend/packages/superset-ui-core/src/translation/Translator.ts

View workflow job for this annotation

GitHub Actions / frontend-build

Expected exception block, space or tab after '//' in comment
this.locale = this.i18n.options.locale_data.superset[''].lang as Locale;
}

Expand Down
13 changes: 11 additions & 2 deletions superset/translations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
# specific language governing permissions and limitations
# under the License.
import json
import logging
import os
from typing import Any, Optional

logger = logging.getLogger(__name__)

# Global caching for JSON language packs
ALL_LANGUAGE_PACKS: dict[str, dict[str, Any]] = {"en": {}}

Expand All @@ -35,11 +38,17 @@ def get_language_pack(locale: str) -> Optional[dict[str, Any]]:
pack = ALL_LANGUAGE_PACKS.get(locale)
if not pack:
filename = DIR + f"/{locale}/LC_MESSAGES/messages.json"
if not locale or locale == "en":
# Forcing a dummy, quasy-empty language pack for English since the file
# in the en directory is contains data with empty mappings
filename = DIR + "/empty_language_pack.json"
try:
with open(filename, encoding="utf8") as f:
pack = json.load(f)
ALL_LANGUAGE_PACKS[locale] = pack or {}
except Exception: # pylint: disable=broad-except
# Assuming english, client side falls back on english
pass
logger.error(
"Error loading language pack for, falling back on en %s", locale
)
pack = get_language_pack("en")
return pack

0 comments on commit e90e52d

Please sign in to comment.