apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.8k stars 13.87k forks source link

Issues with Language Settings in Superset: Configuration Not Saved, Partial Translations, and Redirects #30334

Open aprendizlaura opened 1 month ago

aprendizlaura commented 1 month ago

I am experiencing multiple issues related to the language settings in Superset:

  1. Partial Translations and Incorrect Translations: While testing different languages, I noticed that not all parts of Superset are translated when switching from English to another language. This issue is compounded by incorrect translations, such as those shown in the attached image, where both ascending and descending order options are labeled as "orden descendente" in Spanish. This forces me to revert to English to differentiate between options. I would prefer that parts of Superset remain untranslated rather than being mistranslated. Captura de pantalla 2024-09-19 103056
  2. Language Configuration Not Saved: When changing the language settings in Superset, the changes are not saved upon closing and reopening the application. For example, if the default language is English and I change it to Spanish, Superset reverts back to English after restarting. Additionally, if I open Superset in a different browser after setting it to Spanish, it also defaults back to English. This becomes problematic when multiple users are involved. If User 1 prefers Spanish and User 2 prefers English, only one default language can be set, requiring one user to change the language every time they log in. The expected behavior is that once a user changes the language setting, it should persist across sessions.
  3. Redirect to Homepage: When changing the language, Superset redirects the user to the homepage, regardless of the current page. Although I understand that a restart might be necessary for language changes to take effect, it would be more user-friendly if the user remained on the page they were working on after the restart.
dosubot[bot] commented 1 month ago

I found some similar issues and discussions that might help address the problems you're facing with language settings in Superset:

  1. Partial and Incorrect Translations:

  2. Language Configuration Not Saved:

    • Language preferences are stored in the session under the key "locale", defaulting to "en" if not set. This means the language setting is not persistent across different sessions or browsers [4].
    • To make language settings persistent, you might need to implement backend changes to save the language preference in the user profile or a database.
  3. Redirect to Homepage:

    • The current implementation for handling language changes involves reloading the page, which causes a redirect to the homepage. This is done through a language picker dropdown in the frontend [5].

Suggested Solutions:

  1. Partial and Incorrect Translations:

    • Ensure that the BABEL_DEFAULT_LOCALE is set correctly and that the LANGUAGES dictionary is populated with the supported languages and their respective flags and names.
    • Verify that the translation files (.po, .mo, .json) are correctly updated and placed in the appropriate directory.
    # Babel config for translations
    BABEL_DEFAULT_LOCALE = "en"
    BABEL_DEFAULT_FOLDER = "superset/translations"
    LANGUAGES = {
       "en": {"flag": "us", "name": "English"},
       "es": {"flag": "es", "name": "Spanish"},
       "it": {"flag": "it", "name": "Italian"},
       "fr": {"flag": "fr", "name": "French"},
       "zh": {"flag": "cn", "name": "Chinese"},
       "zh_TW": {"flag": "tw", "name": "Traditional Chinese"},
       "ja": {"flag": "jp", "name": "Japanese"},
       "de": {"flag": "de", "name": "German"},
       "pt": {"flag": "pt", "name": "Portuguese"},
       "pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
       "ru": {"flag": "ru", "name": "Russian"},
       "ko": {"flag": "kr", "name": "Korean"},
       "sk": {"flag": "sk", "name": "Slovak"},
       "sl": {"flag": "si", "name": "Slovenian"},
       "nl": {"flag": "nl", "name": "Dutch"},
       "uk": {"flag": "uk", "name": "Ukranian"},
    }
  2. Language Configuration Not Saved:

    • Modify the backend to save the language preference in the user profile or a database, ensuring it persists across sessions and browsers.
  3. Redirect to Homepage:

    • Update the frontend logic to reload the page without redirecting to the homepage. This might involve modifying the language change handler to retain the current page URL.
    // Example: Retain current page after language change
    $('#language-picker a').click(function (ev) {
     ev.preventDefault();
     SupersetClient.get({
       url: ev.currentTarget.href,
       parseMethod: null,
     }).then(() => {
       window.location.reload(true); // true to force reload from server
     });
    });

By implementing these changes, you can address the issues of partial and incorrect translations, unsaved language configurations, and homepage redirects in Superset.

To continue talking to Dosu, mention @dosu.

Suvendu-UI commented 1 month ago

is this issue resolved?

aprendizlaura commented 1 month ago

@Suvendu-UI No, it hasn't been resolved. The issue that concerns me the most is the first one, and even with the configuration that Dosu suggested (which I already had because I read other threads), it still works partially.

rusackas commented 1 month ago

Partial translations are not considered bugs, as we'll be chasing that down approximately forever. If you'd like to contribute or fix translations, we encourage you to edit the .po files and open a PR with your changes.

rusackas commented 1 month ago

I haven't looked much at the other two issues, but the second one sounds legit, and maybe you can set a cookie or use localstorage to resolve this. The third, I believe, is a duplicated of another open issue. If you or I find that, we might want to close this as a duplicate... I'd encourage you to file issues separately for reasons like this :)

aprendizlaura commented 1 month ago

@rusackas Great! I’ll keep that in mind for next time and present the issues separately. Since they all relate to a common theme, I thought it made sense to present them together, but now that you mention it, you’re absolutely right to address them separately. Going back to the topic of partial translations, it’s not really the main issue I see. The bigger problem, in my opinion, is incorrect translations. As I’ve attached in the image, you can see that for ascending and descending order, it shows the same text for both, in this case, descending order. I’ve found myself more than once having to change the language because the translation wasn’t correct. What I mean is, partial translations seem great to me, and actually, being in English right now seems the most optimal at this stage of the language development.

Thank you so much, as always, for your responses!

SBIN2010 commented 1 month ago

aprendizlaura I suggest this option, it suits me, maybe it will suit you too. This solves the problem with redirection and language change Add it to config.py:

class SupersetIndexView(IndexView):   
    @expose("/lang/<string:locale>")
    def patch_flask_locale(self, locale):
        from flask import redirect, request, session
        referrer = request.headers.get("Referer")
        session["locale"] = locale
        return redirect(referrer)

FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"
rusackas commented 1 month ago

@aprendizlaura I have no idea how many incorrect translations there might be in Superset, but @mistercrunch and I are interested in making the experience of contributing/mantaining these translations easier.

We're trying to find ways for both people and AI to fill in the blanks and make corrections, so we hope to follow up there in the future. For now, if you're able to open a PR with these changes (just find the string and change it in the relevant .po file) that would be helpful and appreciated.