不确定这是否存在,是否可以使用 python Faker lib 生成随机语言环境? (https://faker.readthedocs.io/)。
最好有:生成支持的语言环境
解决方法:
>>> fake = Faker(["fr_FR", "it_IT", "de_DE"])
>>> fake.locales
['fr_FR', 'it_IT', 'de_DE']
>>> import random
>>> random.choices(fake.locales)[0]
de_DE
没什么新意,但更整洁:
import random
from faker import Faker
from faker.config import AVAILABLE_LOCALES
# Get a list of all available locales
available_locales = [local for local in AVAILABLE_LOCALES]
# Randomly select one locale
random_locale = random.choice(available_locales)
# Create a Faker instance with the random locale
fake = Faker(locale=random_locale)
我认为不可以。我之前已经阅读了另一项研究的完整
faker
文档,但从未找到任何方法来生成任何语言环境。