igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

Use correct grammar for interval name and period #98

Closed igorsimb closed 7 months ago

igorsimb commented 8 months ago

Related to https://github.com/igorsimb/mp-monitor/issues/115

Currently we have this in create_scrape_interval_task view

# store 'scrape_interval_task' in session to display as context in item_list.html
request.session["scrape_interval_task"] = f"{scrape_interval_task.name} - {scrape_interval_task.interval}"

scrape_interval_task.interval displays the translated version, but case (падеж) is incorrect.

We can change it to this:

# store 'scrape_interval_task' in session to display as context in item_list.html
request.session["scrape_interval_task"] = f"{scrape_interval_task.name} - каждые {scrape_interval_task.interval.every} {scrape_interval_task.interval.period}"

This will show as the fullowing: "scrape_interval_task_admin - каждые 34 seconds", i.e.

A potential solution could be a util function with if-then statements to make sure everything is displayed in accordance with Russian grammar.

igorsimb commented 8 months ago

Also, should probably remove {scrape_interval_task.name} from request.session["scrape_interval_task"] Maybe in future we'll give user the ability to name the interval tasks when we have the ability to create more than one.

igorsimb commented 7 months ago

Code reponsible for the format is the __str__ method of IntervalSchedule class

    def __str__(self):
        readable_period = None
        if self.every == 1:
            for period, _readable_period in SINGULAR_PERIODS:
                if period == self.period:
                    readable_period = _readable_period.lower()
                    break
            return _('every {}').format(readable_period)
        for period, _readable_period in PERIOD_CHOICES:
            if period == self.period:
                readable_period = _readable_period.lower()
                break
        return _('every {} {}').format(self.every, readable_period)

Possible solution

class CustomIntervalSchedule(IntervalSchedule): def str(self):

Implement your custom logic for Russian translations here

    # You can access self.every and self.period for customization
    readable_period = self.get_russian_translation()  # Your translation function
    if self.every == 1:
        return _('every {}').format(readable_period.lower())
    return _('every {} {}').format(self.every, readable_period.lower())
igorsimb commented 7 months ago

As an example, see https://github.com/celery/django-celery-beat/pull/272/files Also check how django.contrib.humanize did their .po file for Russian