Coverage for opt/mealie/lib/python3.12/site-packages/mealie/lang/providers.py: 87%
23 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
1from abc import abstractmethod 1a
2from functools import lru_cache 1a
3from pathlib import Path 1a
4from typing import Protocol 1a
6from fastapi import Header 1a
8from mealie.pkgs import i18n 1a
10CWD = Path(__file__).parent 1a
11TRANSLATIONS = CWD / "messages" 1a
14class Translator(Protocol): 1a
15 @abstractmethod 1a
16 def t(self, key, default=None, **kwargs) -> str: 1a
17 pass
20@lru_cache 1a
21def _load_factory() -> i18n.ProviderFactory: 1a
22 return i18n.ProviderFactory( 1b
23 directory=TRANSLATIONS,
24 fallback_locale="en-US",
25 )
28def local_provider(accept_language: str | None = Header(None)) -> Translator: 1a
29 factory = _load_factory() 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwb
30 accept_language = accept_language or "en-US" 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwb
31 return factory.get(accept_language) 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwb
34@lru_cache 1a
35def get_all_translations(key: str) -> dict[str, str]: 1a
36 factory = _load_factory()
37 return {locale: factory.get(locale).t(key) for locale in factory.supported_locales}