Giter VIP home page Giter VIP logo

sqlalchemy-i18n's Introduction

SQLAlchemy-i18n

Build Status Version Status Downloads

Internationalization extension for SQLAlchemy models.

Features

  • Stores translations in separate tables.
  • Reflects translation table structures based on parent model table structure.
  • Supports forcing of given locale.
  • Good performance (uses proxy dicts and other advanced SQLAlchemy concepts for performance optimization)

Basic Usage

Consider you have already defined SQLAlchemy connections and declarative base as follows:

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine(
    'postgres://postgres@localhost/sqlalchemy_i18n'
)
Base = declarative_base()

You only need to define two things, first you have to make the desired mapper translatable using make_translatable() function. Internally this function attaches two sqlalchemy event listeners for given mapper.

NOTICE: Calling make_translatable() for given mapper should happen only once per application.

from sqlalchemy_i18n import make_translatable

make_translatable(sa.orm.mapper)

Secondly you need to define translatable models. In the following example we add translatable Article model with two translatable properties (name and content).

import sqlalchemy as sa
from sqlalchemy_i18n import Translatable, translation_base


class Article(Base, Translatable):
    id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
    description = sa.Column(sa.UnicodeText)


class ArticleTranslation(translation_base(Article)):
    __tablename__ = 'article_translation'

    name = sa.Column(sa.Unicode(255))
    content = sa.Column(sa.UnicodeText)

Resources

sqlalchemy-i18n's People

Contributors

bpedman avatar kvesteri avatar lelit avatar pmarti avatar supervacuo avatar

Watchers

 avatar  avatar

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.