How to use the mimesis.locales.DEFAULT_LOCALE function in mimesis

To help you get started, we’ve selected a few mimesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / pytest-mimesis / pytest_mimesis.py View on Github external
def mimesis_locale():
    """Specifies which locale to use."""
    return DEFAULT_LOCALE
github pytest-dev / pytest-mimesis / tests / test_fixtures.py View on Github external
def test_locale(mimesis_locale, mimesis):
    assert mimesis_locale == DEFAULT_LOCALE
    assert mimesis.locale == DEFAULT_LOCALE
github lk-geimfari / mimesis / mimesis / providers / base.py View on Github external
    def _override_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        """Overrides current locale with passed and pull data for new locale.

        :param locale: Locale
        :return: Nothing.
        """
        self.locale = locale
        self.pull.cache_clear()
        self.pull()
github lk-geimfari / mimesis / mimesis / providers / base.py View on Github external
    def __init__(self, locale: str = locales.DEFAULT_LOCALE,
                 seed: Seed = None) -> None:
        """Initialize attributes for data providers.

        :param locale: Current locale.
        :param seed: Seed to all the random functions.
        """
        super().__init__(seed=seed)
        self._data: Dict[str, Any] = {}
        self._datafile = ''
        self._setup_locale(locale)
        self._data_dir = Path(__file__).parent.parent.joinpath('data')
github mimesis-lab / mimesis-factory / mimesis_factory.py View on Github external
from mimesis.schema import Field, Generic

_CacheKey = Tuple[str, Any]
_Providers = Iterable[Type[BaseProvider]]


class MimesisField(declarations.BaseDeclaration):
    """
    Mimesis integration with FactoryBoy starts here.

    This class provides common interface for FactoryBoy,
    but inside it has Mimesis generators.
    """

    _cached_instances: ClassVar[Dict[_CacheKey, Field]] = {}
    _default_locale: ClassVar[str] = locales.DEFAULT_LOCALE

    def __init__(
        self, field: str, locale: Optional[str] = None, **kwargs,
    ) -> None:
        """
        Creates a field instance.

        The created field is lazy. It also receives build time parameters.
        These parameters are not applied yet.

        Args:
            field: name to be passed to ``Field`` from ``Mimesis``.
            locale: locale to use. This parameter has the highest priority.
            kwargs: optional parameters that would be passed to ``Field``.

        """
github lk-geimfari / mimesis / mimesis / providers / base.py View on Github external
    def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        """Set up locale after pre-check.

        :param str locale: Locale
        :raises UnsupportedLocale: When locale is not supported.
        :return: Nothing.
        """
        if not locale:
            locale = locales.DEFAULT_LOCALE

        locale = locale.lower()
        if locale not in locales.SUPPORTED_LOCALES:
            raise UnsupportedLocale(locale)

        self.locale = locale
github lk-geimfari / mimesis / mimesis / providers / base.py View on Github external
def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        """Set up locale after pre-check.

        :param str locale: Locale
        :raises UnsupportedLocale: When locale is not supported.
        :return: Nothing.
        """
        if not locale:
            locale = locales.DEFAULT_LOCALE

        locale = locale.lower()
        if locale not in locales.SUPPORTED_LOCALES:
            raise UnsupportedLocale(locale)

        self.locale = locale