Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel integration #1247

Merged
merged 194 commits into from
Jul 5, 2021
Merged

Babel integration #1247

merged 194 commits into from
Jul 5, 2021

Conversation

kdmukai
Copy link
Collaborator

@kdmukai kdmukai commented Jun 22, 2021

Note: New pip requirement pip install Flask-Babel but I need info on how to generate a new requirements.txt that will include the hashes.

Overview: Babel will attempt to find a translation for a given wrapped string in the target language. If an entry is not found or is left blank, Babel will just return the English text. So even if there are large holes in the translation file for a target language, we won't have any broken functionality. The worst-case scenario is that the user gets English text, which is no worse than what they're seeing now.

See the new babel/README.md for most of the details.

Key changes:

  • config.py: Defines the supported LANGUAGES.
  • server.py: Defines a SpecterFlask class so we can add some locale-handling methods to the Flask app. Handles locale auto-detection. New endpoint to make explicit language selections. Initializes Babel to the app instance.
  • helpers.py, devices.py: Multi-language support for BIP39 mnemonic wordlists. The library we're using already has all of the wordlists for other languages that are defined in BIP39. Wraps calls to Mnemonic so it can be initialized with the selected language.
  • babel/README.md: docs to guide volunteer translators as well as explain to devs how to wrap strings in various situations and how to generate and compile the translation files.
  • Tons and tons of string wrapping: Three main techniques used:
    from flask_babel import lazy_gettext as _
    before = "Hello, World!"
    after = _("Hello, World!")
    
    before = f"Hello, {user.name}!"
    after = _("Hello, {}!").format(user.name)
    
    # template code
    <div>Welcome!</div>
    <div>{{ _("Welcome!") }}</div>
    
    Note: using lazy_gettext everywhere rather than deciding between it and gettext. There are some pitfalls when using gettext that are solved by lazy_gettext and I don't see a downside to just always using lazy_gettext.
  • language_select.jinja and language_js.jinja: template includes to add the language selection droplist anywhere in the UI. Currently on the main landing page and in Settings.

Misc:

  • config.py: Explicitly forcing FLASK_ENV=development when using the DevelopmentConfig
  • wallets.py: Two routes were checking for POST when the route decorator could just be updated to limit to that method. jsonify used in place of manually constructed json responses to be more pythonic.

This is still very much a draft as I'm rushing to get this PR out for everyone to take a look (i.e. not my ideal level of self-scrutiny). There are bound to be some sloppy text wrapping mistakes that still need to be caught.

kdmukai and others added 30 commits March 22, 2021 11:27
Started the translation process using Poedit. Lines
First modification (only adding one line here) using Poedit and following the translation steps given by kdmukai.

If everything is working well here I am ready to start translating.
kdmukai and others added 29 commits July 2, 2021 12:27
Russian translation 30% complete
Slowly but surely
Update messages.po at 60% - updated
@ben-kaufman ben-kaufman merged commit 4143cb8 into cryptoadvance:master Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet