Skip to main content

SQLAlchemy internationalisation

Project description

traduki: SQLAlchemy internationalisation

The traduki package provides internationalisation helper classes for SQLAlchemy-based projects.

https://api.travis-ci.org/paylogic/traduki.png https://img.shields.io/pypi/v/traduki.svg https://coveralls.io/repos/paylogic/traduki/badge.png?branch=master

Installation

pip install traduki

Usage

traduki usage example:

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

import traduki

def get_current_language():
    """Current language callback for our project."""
    return request.locale

def get_language_chain():
    """Language chain (fallback rule) callback for our project."""
    return {'*': request.locale}

i18n_attributes = traduki.initialize(Base, ['en', 'ru'], get_current_language, get_language_chain)

Session = sessionmaker(bind=engine)
sess = Session()

class MyModel(Base)

    title_id = i18n_attributes.i18n_column(nullable=False, unique=False)
    title = i18n_attributes.i18n_relation(title_id)
    """Title."""

my_object = MyModel()
my_object.title = {'en': 'English title', 'pt': 'Portugese title'}
sess.add(my_object)
sess.commit()

assert sess.refresh(my_object).title.get_dict() == {'en': 'English title', 'pt': 'Portugese title'}

Contact

If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.

License

This software is licensed under the MIT license

See License

© 2018 Paylogic International.

Changelog

1.2.0

  • Do not use deprecated AttributeExtension, use Attribute Events instead.

1.1.0

  • Use an OR operator for LIKE_OPS to find matches in all language columns.

1.0.1

  • Fix get_text_from_dict raising an exception when no language can be detected.

1.0.0

  • Initial public release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traduki-1.2.0.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file traduki-1.2.0.tar.gz.

File metadata

  • Download URL: traduki-1.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.16

File hashes

Hashes for traduki-1.2.0.tar.gz
Algorithm Hash digest
SHA256 521d24073de1769fdcd78d1611230f845f91c9b1c4a63d8e448db58ca7043e7b
MD5 b264c91c52bc022f4feaa76d5edf3fb8
BLAKE2b-256 765a2074ace042854d0f93b30249aca600eeb2a417da2965e2f84aa493fb90e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page