YuriyKrasilnikov commented on code in PR #37790: URL: https://github.com/apache/superset/pull/37790#discussion_r2779278149
########## superset/localization/api.py: ########## @@ -0,0 +1,108 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""REST API for content localization configuration.""" + +import logging + +from flask import current_app, Response +from flask_appbuilder.api import expose, protect, safe + +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP +from superset.extensions import event_logger +from superset.localization.schemas import AvailableLocalesResponseSchema +from superset.views.base_api import BaseSupersetApi, statsd_metrics + +logger = logging.getLogger(__name__) + +DEFAULT_LOCALE = "en" + + +def get_available_locales_data() -> dict[str, list[dict[str, str]] | str]: + """ + Build available locales response data from Flask config. + + Reads LANGUAGES and BABEL_DEFAULT_LOCALE from current_app.config + and transforms to response format. + + Returns: + Dict with 'locales' list and 'default_locale' string. + """ + languages: dict[str, dict[str, str]] = current_app.config.get("LANGUAGES", {}) + default_locale = current_app.config.get("BABEL_DEFAULT_LOCALE", DEFAULT_LOCALE) + + # Transform dict to sorted list + locales = [ + {"code": code, "name": meta["name"], "flag": meta["flag"]} + for code, meta in sorted(languages.items()) Review Comment: False positive. `LANGUAGES` is a standard Flask-Babel config with a well-documented format — every entry is `{"flag": str, "name": str}` (see `config.py:421-436`, 15 entries, all identical structure). Direct key access `meta["name"]` is intentional — fail-fast on misconfiguration rather than silently returning fallback values. If someone breaks the `LANGUAGES` format, the entire Flask-Babel layer (locale selection, UI translations) breaks too, not just this endpoint. Adding `.get()` with defaults would mask config errors instead of surfacing them. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
