Skip to content

FakerLibrary cannot be initialized with multiple locales #42

@jrfigura

Description

@jrfigura

Faker Library supports initialization with multiple locales:
from faker import Faker
fake = Faker(['it_IT', 'en_US', 'ja_JP'])
for _ in range(10):
print(fake.name())

Whenever I try to initialize library with multiple locales it fails with error:
Error in file '/app/robot/keywords/InventoryImportKeywords.robot': Initializing test library 'FakerLibrary' with arguments [ locale=['ja_JP', 'de_DE', 'en_US'] ] failed: AttributeError: 'list' object has no attribute 'replace'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/FakerLibrary/keywords.py", line 42, in init
self.fake = faker.factory.Factory.create(locale, providers)
File "/usr/local/lib/python3.8/site-packages/faker/factory.py", line 35, in create
locale = locale.replace('-', '
') if locale else DEFAULT_LOCALE

In factory.py file we always treat locale variable as a string with single argument and line:
locale = locale.replace('-', '_') if locale else DEFAULT_LOCALE
causes this issue

Would be super nice to have initialization with multiple locales implemented

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions