freeleaps-service-hub/infra/i18n/region_handler.py
2024-10-20 05:33:10 +00:00

20 lines
682 B
Python

from infra.models.constants import UserRegion
class RegionHandler:
def __init__(self):
self._zh_cn_patterns = [".cn", "cn.", "host"]
def detect_from_host(self, host: str) -> UserRegion:
# Now we set user preferred region based on host
for parttern in self._zh_cn_patterns:
if parttern in host.lower():
return UserRegion.ZH_CN
return UserRegion.OTHER
# async def get_user_region(self, user_id: str) -> UserRegion:
# user_profile = await BasicProfileDoc.find_one(
# BasicProfileDoc.user_id == user_id
# )
# return user_profile.region if user_profile else UserRegion.OTHER