Ejemplo n.º 1
0
 def description(self, localized_names, babel_locale):
     # TODO: SH and PH
     set_locale(babel_locale)
     day_groups = []
     for group in consecutive_groups(sorted(self.selectors,
                                            key=WEEKDAYS.index),
                                     ordering=WEEKDAYS.index):
         group = list(group)
         if len(group) == 1:
             day_groups.append((group[0], ))
         else:
             day_groups.append((group[0], group[-1]))
     output = []
     for group in day_groups:
         if len(group) == 1:
             output.append(
                 _("on {weekday}").format(weekday=localized_names["days"][
                     WEEKDAYS.index(group[0])]))
         else:
             output.append(
                 _("from {weekday1} to {weekday2}").format(
                     weekday1=localized_names["days"][WEEKDAYS.index(
                         group[0])],
                     weekday2=localized_names["days"][WEEKDAYS.index(
                         group[1])]))
     holidays_description = {
         (True, True): _("on public and school holidays"),
         (True, False): _("on public holidays"),
         (False, True): _("on school holidays")
     }.get((self.PH, self.SH))
     if holidays_description:
         return babel.lists.format_list([holidays_description] + output,
                                        locale=babel_locale)
     else:
         return join_list(output, babel_locale)
Ejemplo n.º 2
0
 def description(self, localized_names, babel_locale):
     set_locale(babel_locale)
     rendered_selectors = [
         sel.description(localized_names, babel_locale)
         for sel in self.selectors
     ]
     return join_list(rendered_selectors, babel_locale)
 def description(self, localized_names, babel_locale):
     set_locale(babel_locale)
     if (
         isinstance(self.range_selectors, AlwaysOpenSelector) and
         self.time_selectors == [TIMESPAN_ALL_THE_DAY]
     ):
         return _("Open 24 hours a day and 7 days a week.")
     
     range_selectors_description = ', '.join(
         [
             sel.description(localized_names, babel_locale)
             for sel in self.range_selectors.selectors
         ]
     )
     if not range_selectors_description:
         range_selectors_description = _("every days")
     if not self.time_selectors:
         time_selectors_description = _("closed")
     else:
         time_selectors_description = join_list(
             [
                 timespan.description(localized_names, babel_locale)
                 for timespan in self.time_selectors
             ],
             babel_locale
         )
     full_description = _("{}: {}").format(
         range_selectors_description,
         time_selectors_description
     ) + '.'
     return full_description[0].upper() + full_description[1:]
Ejemplo n.º 4
0
 def description(self, localized_names, babel_locale):
     set_locale(babel_locale)
     output = []
     for year_range in self.rendering_data:
         if len(year_range) == 1:
             output.append(_("in {year}").format(year=year_range[0]))
         elif len(year_range) == 2:
             output.append(
                 _("from {year1} to {year2}").format(year1=year_range[0],
                                                     year2=year_range[1]))
         else:
             output.append(
                 _("from {year1} to {year2}, every {n} years").format(
                     year1=year_range[0],
                     year2=year_range[1],
                     n=year_range[2]))
     return join_list(output, babel_locale)
Ejemplo n.º 5
0
 def description(self, localized_names, babel_locale):
     set_locale(babel_locale)
     output = []
     for week_range in self.rendering_data:
         if len(week_range) == 1:
             output.append(_("in week {week}").format(week=week_range[0]))
         elif len(week_range) == 2:
             output.append(
                 _("from week {week1} to week {week2}").format(
                     week1=week_range[0], week2=week_range[1]))
         else:
             output.append(
                 _("from week {week1} to week {week2}, every {n} weeks").
                 format(week1=week_range[0],
                        week2=week_range[1],
                        n=week_range[2]))
     return join_list(output, babel_locale)
Ejemplo n.º 6
0
 def render_periods(self, join=True):
     """
     Returns a list of translated strings
     describing the opening periods of the day.
     """
     if self.opens_today():
         rendered_periods = [
             render_timespan(ts.timespan, self.locale)
             for ts in self.timespans
         ]
     else:
         closed_word = translate_open_closed(self.locale)[1]
         rendered_periods = [closed_word]
     if join:
         return join_list(rendered_periods, self.locale)
     else:
         return rendered_periods