Skip to content

Commit

Permalink
Merge pull request #42 from LemonLzy/feature/locale
Browse files Browse the repository at this point in the history
Add: add random locale
  • Loading branch information
LemonLzy authored Jul 10, 2023
2 parents 55a4915 + 60dd426 commit 9f8a3e7
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ f.ticker_symbol()

f.tz_identifier()
# Asia/Baku

f.locale()
# zh-CN
```
2 changes: 2 additions & 0 deletions lfinancial/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from lfinancial.generators.contry import CountryGenerator
from lfinancial.generators.currency import CurrencyGenerator
from lfinancial.generators.document import IDCodeGenerator
from lfinancial.generators.locale import LocaleGenerator
from lfinancial.generators.mail import EmailGenerator
from lfinancial.generators.name import NameGenerator
from lfinancial.generators.phone import PhoneGenerator
Expand Down Expand Up @@ -33,6 +34,7 @@ def __init__(self):
"stock_exchange": StockGenerator(),
"ticker_symbol": StockGenerator(),
"tz_identifier": TimeZoneGenerator(),
"locale": LocaleGenerator(),
}

def register_generator(self, name, generator):
Expand Down
4 changes: 4 additions & 0 deletions lfinancial/financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def ticker_symbol(self, country=None):
def tz_identifier(self, country=None):
return self.__generate("tz_identifier", country)

def locale(self, country=None):
return self.__generate("locale", country)


if __name__ == '__main__':
f = Financial()
Expand All @@ -92,3 +95,4 @@ def tz_identifier(self, country=None):
print(f.stock_exchange())
print(f.ticker_symbol())
print(f.tz_identifier())
print(f.locale())
201 changes: 201 additions & 0 deletions lfinancial/generators/locale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import random


class LocaleGenerator:
"""
https://zh.wikipedia.org/wiki/%E5%8C%BA%E5%9F%9F%E8%AE%BE%E7%BD%AE
"""
locales = (
"af",
"af-ZA",
"am",
"am-ET",
"sq",
"ar",
"ar-AE",
"ar-BH",
"ar-DZ",
"ar-EG",
"ar-IQ",
"ar-JO",
"ar-KW",
"ar-LB",
"ar-LY",
"ar-MA",
"arn",
"arn-CL",
"ar-OM",
"ar-QA",
"ar-SA",
"ar-SY",
"ar-TN",
"ar-YE",
"as",
"as-IN",
"hy",
"az",
"az-Latn",
"az-Cyrl",
"az-Latn-AZ",
"az-Cyrl-AZ",
"ba",
"ba-RU",
"eu",
"be",
"be-BY",
"bg",
"bg-BG",
"bn",
"bg-BD",
"bg-IN",
"bo",
"bo-CN",
"bo",
"br-FR",
"bs",
"bs-Cyrl",
"bs-Cyrl-BA",
"bs-Latn",
"bs-Latn-BA",
"ca",
"ca-ES",
"zh",
"zh-CN",
"zh-CN_stroke",
"zh-Hans",
"zh-Hant",
"zh-HK",
"zh-HK_radstr",
"zh-MO",
"zh-MO_radstr",
"zh-MO_stroke",
"zh-SG",
"zh-SG_stroke",
"zh-TW",
"zh-TW",
"zh-TW_pronun",
"zh-TW_radstr",
"hr",
"CO",
"co-FR",
"CS",
"cs-CZ",
"cy",
"cy-GB",
"da",
"da-DK",
"nl-nl",
"nl-be",
"en-029",
"en-AU",
"en-BZ",
"en-CA",
"en-CB",
"en-IN",
"en-IE",
"en-JM",
"en-MY",
"en-NZ",
"en-PH",
"en-SG",
"en-ZA",
"en-TT",
"en-GB",
"en-US",
"en-ZW",
"et",
"fa",
"fi",
"fo.",
"fr-fr",
"fr-be",
"fr-ca",
"fr-lu",
"fr-ch",
"gd-ie",
"gd",
"de-DE",
"de-DE_phoneb",
"de-AT",
"de-LI",
"de-LU",
"de-CH",
"dsb",
"dsb_DE",
"dy",
"dv_MF",
"el",
"el-GR",
"he",
"hi",
"hu",
"js",
"id",
"it-it",
"it-ch",
"ja",
"ko",
"lv",
"lt",
"mk",
"ms-my",
"ms-bn",
"mt",
"mn",
"np-no",
"nn-no",
"pl",
"pt-pt",
"pt-br",
"rm",
"ro",
"ro-mo",
"ru",
"ru-mo",
"sa",
"sr-sp",
"sr-sp",
"tn",
"sl",
"sk",
"sb",
"es-es",
"es-ar",
"es-bo",
"es-cl",
"es-co",
"es-cr",
"es-do",
"es-ec",
"es-gt",
"es-hn",
"es-mx",
"es-ni",
"es-pa",
"es-pe",
"es-pr",
"es-py",
"es-SV",
"es-uy",
"es-ve",
"st",
"SW",
"sv-se",
"sv-fi",
"ta",
"tt",
"th",
"tr",
"ts",
"uk",
"ur",
"uz-uz",
"uz-uz",
"vi",
"xh",
"yi",
"zu",
)

def gen(self, *args, **kwargs):
return random.choice(self.locales)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='lfinancial',
version='0.2.5',
version='0.2.6',
author='zaneliu',
description='Generate financial test data',
long_description=long_description,
Expand Down

0 comments on commit 9f8a3e7

Please sign in to comment.