GithubHelp home page GithubHelp logo

klen / asgi-babel Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 1.0 45 KB

Adds internationalization (i18n) support to ASGI applications (Asyncio/Trio)

License: MIT License

Makefile 12.04% Python 87.96%
i18n localization asgi asyncio trio asgi-toolkit curio

asgi-babel's Introduction

Hi there, I'm Kirill ๐Ÿ‘‹

  • ๐Ÿ”ญ Iโ€™m currently working on Muffin ecosystem
  • ๐ŸŒฑ Iโ€™m currently learning Rust
  • ๐Ÿ’ฌ Ask me about anything here
  • ๐Ÿ“ซ How to reach me: [email protected]
Anurag's github stats

asgi-babel's People

Contributors

klen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

frankie567

asgi-babel's Issues

Add support for lazy gettext functions variants

Hello there ๐Ÿ‘‹

When developing web apps, it's a common pattern to put translated strings in modules or class definitions. For example, with WTForms:

class RegistrationForm(Form):
    name = StringField(_('Name'))

At module import, the locale is not yet known, maybe messages are even not loaded. To circumvent this, frameworks usually come with "lazy" variants of functions which are interpolated only when rendering the final template, at a time where the locale is known.

Currently, asgi-babel only provides the "normal" gettext functions. It could be useful to have the lazy variants at hand in this context.

The implementation should be quite straightforward, as Babel conveniently bundles as LazyProxy class. It could look like this:

def gettext_lazy(string: str, domain: str = None, **variables):
    return support.LazyProxy(gettext, string, domain, **variables)

# ... and so on for `pgettext` and `npgettext`

I've tested it in one of my project, and it works well. Do you think it would be a useful addition? If so, I would be happy to propose a PR for this.

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.