Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

Using mldbc with different variants of a same language

This article uses the lino_book.projects.de_BE project to test and document the support for Multilingual database content with different variants of a same language on a same Site.

We have two variants of German in languages: "normal" ('de') and "Belgian" ('de_BE'):

from lino.projects.std.settings import *


class Site(Site):

    languages = 'en de de-be'

    demo_fixtures = ['demo']

    def get_installed_plugins(self):
        yield super(Site, self).get_installed_plugins()
        yield 'lino_book.projects.de_BE'

    def setup_menu(self, user_type, main):
        m = main.add_menu("master", "Master")
        m.add_action('de_BE.Expressions')
        super(Site, self).setup_menu(user_type, main)


SITE = Site(globals())

The models.py file defines a single model:

from lino.api import dd, _
from lino.utils.mldbc.mixins import BabelDesignated


class Expression(BabelDesignated):

    class Meta:
        verbose_name = _('Expression')
        verbose_name_plural = _('Expressions')


class Expressions(dd.Table):
    model = Expression
    column_names = 'id designation *'

The model inherits from BabelNamed.

We wrote a Python fixture with some differences between those two languages.

# -*- coding: UTF-8 -*-
from __future__ import unicode_literals

from lino.api import dd
from lino_book.projects.de_BE.models import Expression


def O(fr, en, de, de_BE):
    return Expression(
        **dd.babelkw('designation', de=de, de_BE=de_BE, en=en, fr=fr))


def objects():
    yield O("l'atelier", "the workshop", "die Werkstatt", "das Atelier")

To verify whether it worked as expected, we ask Lino to show us the Expressions table:

>>> rt.show('de_BE.Expressions')
==== ============================ ============================ =================================
 ID   Designation                  Designation (de)             Designation (de-be)
---- ---------------------------- ---------------------------- ---------------------------------
 1    the workshop                 die Werkstatt                das Atelier
 2    the lorry                    der Lastwagen                der Camion
 3    the folder                   der Ordner                   die Farde
 4    the fridge                   der Kühlschrank              der Frigo
 5    That's what it depends on.   Darauf kommt es an.          Darauf kommt es sich an.
 6    It's about health.           Es geht um die Gesundheit.   Es geht sich um die Gesundheit.
==== ============================ ============================ =================================

See also

  • lino.core.site.Site.get_language_info()