speaklater


Namespeaklater JSON
Version 1.3 PyPI version JSON
download
home_pagehttp://github.com/mitsuhiko/speaklater
Summaryimplements a lazy string for python useful for use with gettext
upload_time2012-07-01 18:01:30
maintainerNone
docs_urlNone
authorArmin Ronacher
requires_pythonNone
licenseUNKNOWN
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            speaklater
~~~~~~~~~~

A module that provides lazy strings for translations.  Basically you
get an object that appears to be a string but changes the value every
time the value is evaluated based on a callable you provide.

For example you can have a global `lazy_gettext` function that returns
a lazy string with the value of the current set language.

Example:

>>> from speaklater import make_lazy_string
>>> sval = u'Hello World'
>>> string = make_lazy_string(lambda: sval)

This lazy string will evaluate to the value of the `sval` variable.

>>> string
lu'Hello World'
>>> unicode(string)
u'Hello World'
>>> string.upper()
u'HELLO WORLD'

If you change the value, the lazy string will change as well:

>>> sval = u'Hallo Welt'
>>> string.upper()
u'HALLO WELT'

This is especially handy when combined with a thread local and gettext
translations or dicts of translatable strings:

>>> from speaklater import make_lazy_gettext
>>> from threading import local
>>> l = local()
>>> l.translations = {u'Yes': 'Ja'}
>>> lazy_gettext = make_lazy_gettext(lambda: l.translations.get)
>>> yes = lazy_gettext(u'Yes')
>>> print yes
Ja
>>> l.translations[u'Yes'] = u'Si'
>>> print yes
Si

Lazy strings are no real strings so if you pass this sort of string to
a function that performs an instance check, it will fail.  In that case
you have to explicitly convert it with `unicode` and/or `string` depending
on what string type the lazy string encapsulates.

To check if a string is lazy, you can use the `is_lazy_string` function:

>>> from speaklater import is_lazy_string
>>> is_lazy_string(u'yes')
False
>>> is_lazy_string(yes)
True

New in version 1.2: It's now also possible to pass keyword arguments to
the callback used with `make_lazy_string`.
            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/mitsuhiko/speaklater",
    "name": "speaklater",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Armin Ronacher",
    "author_email": "armin.ronacher@active-4.com",
    "download_url": "https://files.pythonhosted.org/packages/11/92/5ae1effe0ccb8561c034a0111d53c8788660ddb7ed4992f0da1bb5c525e5/speaklater-1.3.tar.gz",
    "platform": "UNKNOWN",
    "description": "speaklater\n~~~~~~~~~~\n\nA module that provides lazy strings for translations.  Basically you\nget an object that appears to be a string but changes the value every\ntime the value is evaluated based on a callable you provide.\n\nFor example you can have a global `lazy_gettext` function that returns\na lazy string with the value of the current set language.\n\nExample:\n\n>>> from speaklater import make_lazy_string\n>>> sval = u'Hello World'\n>>> string = make_lazy_string(lambda: sval)\n\nThis lazy string will evaluate to the value of the `sval` variable.\n\n>>> string\nlu'Hello World'\n>>> unicode(string)\nu'Hello World'\n>>> string.upper()\nu'HELLO WORLD'\n\nIf you change the value, the lazy string will change as well:\n\n>>> sval = u'Hallo Welt'\n>>> string.upper()\nu'HALLO WELT'\n\nThis is especially handy when combined with a thread local and gettext\ntranslations or dicts of translatable strings:\n\n>>> from speaklater import make_lazy_gettext\n>>> from threading import local\n>>> l = local()\n>>> l.translations = {u'Yes': 'Ja'}\n>>> lazy_gettext = make_lazy_gettext(lambda: l.translations.get)\n>>> yes = lazy_gettext(u'Yes')\n>>> print yes\nJa\n>>> l.translations[u'Yes'] = u'Si'\n>>> print yes\nSi\n\nLazy strings are no real strings so if you pass this sort of string to\na function that performs an instance check, it will fail.  In that case\nyou have to explicitly convert it with `unicode` and/or `string` depending\non what string type the lazy string encapsulates.\n\nTo check if a string is lazy, you can use the `is_lazy_string` function:\n\n>>> from speaklater import is_lazy_string\n>>> is_lazy_string(u'yes')\nFalse\n>>> is_lazy_string(yes)\nTrue\n\nNew in version 1.2: It's now also possible to pass keyword arguments to\nthe callback used with `make_lazy_string`.",
    "bugtrack_url": null,
    "license": "UNKNOWN",
    "summary": "implements a lazy string for python useful for use with gettext",
    "version": "1.3",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "http://github.com/mitsuhiko/speaklater"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11925ae1effe0ccb8561c034a0111d53c8788660ddb7ed4992f0da1bb5c525e5",
                "md5": "e8d5dbe36e53d5a35cff227e795e8bbf",
                "sha256": "59fea336d0eed38c1f0bf3181ee1222d0ef45f3a9dd34ebe65e6bfffdd6a65a9"
            },
            "downloads": -1,
            "filename": "speaklater-1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e8d5dbe36e53d5a35cff227e795e8bbf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3582,
            "upload_time": "2012-07-01T18:01:30",
            "upload_time_iso_8601": "2012-07-01T18:01:30.306401Z",
            "url": "https://files.pythonhosted.org/packages/11/92/5ae1effe0ccb8561c034a0111d53c8788660ddb7ed4992f0da1bb5c525e5/speaklater-1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2012-07-01 18:01:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mitsuhiko",
    "github_project": "speaklater",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "speaklater"
}
        
Elapsed time: 0.67940s