Passed
Push — main ( 9fd59f...62d5d3 )
by Jochen
04:53
created

with_locale()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
"""
2
byceps.announce.text_assembly._helpers
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from functools import wraps
10 1
from typing import Optional
11
12 1
from flask import current_app
13 1
from flask_babel import force_locale
14
15
16 1
def get_screen_name_or_fallback(screen_name: Optional[str]) -> str:
17
    """Return the screen name or a fallback value."""
18 1
    return screen_name if screen_name else 'Jemand'
19
20
21 1
def with_locale(handler):
22 1
    @wraps(handler)
23
    def wrapper(*args, **kwargs):
24 1
        locale = current_app.config['LOCALE']
25 1
        with force_locale(locale):
26 1
            return handler(*args, **kwargs)
27
28
    return wrapper
29