Edgewall Software
Modify

Opened 12 years ago

Last modified 10 years ago

#10757 new enhancement

Use language specific starting day for date picker

Reported by: framay <franz.mayer@…> Owned by:
Priority: normal Milestone: next-major-releases
Component: i18n Version: 0.13dev
Severity: normal Keywords: preferences
Cc: Jun Omae, Ryan J Ollos, leho@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

It would be nice, if the date picker introduced with ticket #10245 would use the language specific starting day of a week.

In Germany for example the starting day of a week is Monday (and not Sunday, like in US).

Alternatively it could be a user-specific preference.

Attachments (0)

Change History (20)

comment:1 by Ryan J Ollos <ryano@…>, 12 years ago

I had been following that ticket, and thought they had that issue worked out. I never tried it since my language is US/En, but it looks like it should be getting it from the locale. See comment:43:ticket:10245.

comment:2 by Ryan J Ollos <ryano@…>, 12 years ago

Cc: ryano@… added

in reply to:  1 comment:3 by framay <franz.mayer@…>, 12 years ago

Replying to Ryan J Ollos <ryano@…>:

I had been following that ticket, and thought they had that issue worked out. I never tried it since my language is US/En, but it looks like it should be getting it from the locale. See comment:43:ticket:10245.

I tried as stated in comment:44:ticket:10245: I changed my date format settings to iso8601, but that didn't work either.

As stated in comment:43:ticket:10245 it seems that Trac tries to read the territory of the locale to set the first_week_day; but where can you set the territory in Trac? You can only set the language, can't you?

comment:4 by Peter Suter, 12 years ago

I think the territory can sometimes be set as part of the language, e.g. "English (United States)" or "español (Argentina)".

I also suspect the territory workaround for Japan is the problem here.

comment:5 by Jun Omae, 12 years ago

Another workaround at [7018f4b2/jomae.git], which maps the lang to lang-territory using babel.core.LOCALE_ALIASES for "first week day". Using the patch, start day of date picker will be Monday for de locale. Sunday for ja locale.

Thoughts?

Last edited 12 years ago by Jun Omae (previous) (diff)

comment:6 by Peter Suter, 12 years ago

(Sorry, I somehow missed your reply before now. Thanks for looking into this.)

If Babel is not available req.locale is None, right? So get_first_week_day_jquery_ui returns before babel.core.LOCALE_ALIASES and babel.Locale are accessed. It may be helpful to make this explicit in get_first_week_day_jquery_ui somehow.

What's actually the root problem? If I understand correctly:

  • CLDR specifies the first day of the week for certain territories, and Monday as a fallback for the rest of the world (territory code 001):
              <firstDay day="mon"  territories="001" />
              <firstDay day="fri"  territories="MV" />
              <firstDay day="sat"  territories="AF BH DJ DZ EG ER ET IQ IR JO KE KW LY MA OM QA SA SD SO TN YE" />
              <firstDay day="sun"  territories="AS AZ BW CA CN FO GE GL GU HK IE IL IN IS JM JP KG KR LA MH MN MO MP MT NZ PH PK SG SY TH TT TW UM US UZ VI ZW" />
    
    
  • And Babel imports that data:
            for elem in supelem.findall('firstDay'):
                territories = elem.attrib['territories'].split()
                if territory in territories or any([r in territories for r in regions]):
                    week_data['first_day'] = weekdays[elem.attrib['day']]
    
    while assuming locale files without territory (like ja.xml) should be handled as territory 001:
            territory = None
            elem = tree.find('.//identity/territory')
            if elem is not None:
                territory = elem.attrib['type']
            else:
                territory = '001' # world
    

If this is wrong, should the improved logic using LOCALE_ALIASES rather be added to Babel?

Actually, is LOCALE_ALIASES enough? (E.g. IN is noted for Sunday, but as / as_IN has no alias defined.)


By the way, shouldn't ISO 8601 (with or without Babel) use Monday?

in reply to:  6 ; comment:7 by Jun Omae, 12 years ago

Cc: Jun Omae added

If Babel is not available req.locale is None, right?

Right. If no Babel, first_day is always Sunday.

What's actually the root problem? If I understand correctly: …

Your understanding is right.

If this is wrong, should the improved logic using LOCALE_ALIASES rather be added to Babel?

Yah, it would be nice to add to Babel the mechanism which maps lang to lang-territory. refs babel:#26. However, I don't want depend on a new Babel release for Trac 1.0….

Actually, is LOCALE_ALIASES enough? (E.g. IN is noted for Sunday, but as / as_IN has no alias defined.)

Ok, understood. It is enough for ja locale, but NOT enough for other locales. (e.g. Sunday for fr-CA, Monday for fr-FR).

By the way, shouldn't ISO 8601 (with or without Babel) use Monday?

No, it depends on user's locale, req.locale. Because iso8601 appears in only req.lc_time.

I think, complete solution is first-week-day setting in user preferences.

in reply to:  7 ; comment:8 by Peter Suter, 12 years ago

Replying to jomae:

However, I don't want depend on a new Babel release for Trac 1.0….

OK, agreed.

By the way, shouldn't ISO 8601 (with or without Babel) use Monday?

No, it depends on user's locale, req.locale. Because iso8601 appears in only req.lc_time.

But ISO 8601 defines Monday to be the first day of the week. So we should maybe use, e.g.:

        def get_first_week_day_jquery_ui(req): 
            """Get first week day for jQuery date picker""" 
            if req.lc_time == 'iso8601':
                return 1 # Monday
            locale = req.locale
            if not locale: 
                return 0 # Sunday 
            if not locale.territory and locale.language in LOCALE_ALIASES: 
                locale = Locale.parse(LOCALE_ALIASES[locale.language]) 
            return (locale.first_week_day + 1) % 7 

in reply to:  8 comment:9 by Jun Omae, 12 years ago

Replying to psuter:

But ISO 8601 defines Monday to be the first day of the week. So we should maybe use, e.g.: …

I certainly think so, according to http://en.wikipedia.org/wiki/ISO_8601. Refreshed repos:jomae.git:ticket10757/locale-aliases (diff).

I would like to apply the workaround and leave as open this ticket for "first week day in user-preferences". Thoughts? TODO

Last edited 12 years ago by Christian Boos (previous) (diff)

comment:10 by Peter Suter, 12 years ago

Looks good to me, thanks!

comment:11 by Jun Omae, 12 years ago

Applied the workaround in [11149].

comment:12 by Jun Omae, 12 years ago

Component: generali18n
Keywords: userpreferences added
Milestone: next-major-releases

in reply to:  6 comment:13 by Jun Omae, 11 years ago

Actually, is LOCALE_ALIASES enough? (E.g. IN is noted for Sunday, but as / as_IN has no alias defined.)

In [11776], search in req.languages before using LOCALE_ALIASES. In this case, it would good to add as-IN to preferred language in the browser's settings.

The discussion at th:#8175. Thanks to Steffen!

Last edited 11 years ago by Jun Omae (previous) (diff)

comment:15 by Ryan J Ollos, 10 years ago

Cc: Ryan J Ollos added; ryano@… removed

comment:16 by Ryan J Ollos, 10 years ago

Keywords: preferences added; userpreferences removed

comment:17 by lkraav <leho@…>, 10 years ago

Cc: leho@… added

I'm still not sure what's going on here. If my system has LANG=et_EE.utf8, why isn't this respected? (latest 1.1.2beta)

00:29:55 Trac[main] DEBUG: Negotiated locale: None -> en_US

in reply to:  17 comment:18 by Jun Omae, 10 years ago

Replying to lkraav <leho@…>:

I'm still not sure what's going on here. If my system has LANG=et_EE.utf8, why isn't this respected? (latest 1.1.2beta)

00:29:55 Trac[main] DEBUG: Negotiated locale: None -> en_US

It seems that Babel is used. If Babel is used, Trac doesn't respect libc locale. Also, the libc locale always returns Monday for first day of week with any locales.

>>> from locale import setlocale, LC_ALL
>>> from datetime import datetime
>>> setlocale(LC_ALL, 'en_US.UTF8')
'en_US.UTF8'
>>> for _ in xrange(7): datetime(1999, 8, 1 + _).strftime('%Y-%m-%d / %w %W')
...
'1999-08-01 / 0 30'
'1999-08-02 / 1 31'
'1999-08-03 / 2 31'
'1999-08-04 / 3 31'
'1999-08-05 / 4 31'
'1999-08-06 / 5 31'
'1999-08-07 / 6 31'
>>> setlocale(LC_ALL, 'de_DE.UTF8')
'de_DE.UTF8'
>>> for _ in xrange(7): datetime(1999, 8, 1 + _).strftime('%Y-%m-%d / %w %W')
...
'1999-08-01 / 0 30'
'1999-08-02 / 1 31'
'1999-08-03 / 2 31'
'1999-08-04 / 3 31'
'1999-08-05 / 4 31'
'1999-08-06 / 5 31'
'1999-08-07 / 6 31'
Last edited 10 years ago by Jun Omae (previous) (diff)

comment:19 by lkraav <leho@…>, 10 years ago

Yes, Babel is installed now, but only because datepicker set first day as Sunday even before when I didn't have Babel installed. Looked at datefmt.py, saw some stuff being completely skipped without Babel, so I am now trying with Babel.

With no Babel, I was looking at data with TracDeveloperPlugin, req.locale was None, req.lc_time was None.

Now with Babel, locale is being shown as en_US, I guess due to browser settings, but Language tab also shows Message catalogs have not been compiled.. Trac is right, I didn't do that step. Does this possibly turn off some further locale mechanisms?

In theory, I don't want translated messages, but I do want localized date and currency. My system actually has LANG=et_EE.utf8 LC_MESSAGES=en_US.utf8 to achieve this on cmdline level.

Any thoughts on how to proceed to getting first of all the datepicker to show Monday first?

in reply to:  19 comment:20 by Jun Omae, 10 years ago

Replying to lkraav <leho@…>:

In theory, I don't want translated messages, but I do want localized date and currency. My system actually has LANG=et_EE.utf8 LC_MESSAGES=en_US.utf8 to achieve this on cmdline level.

Currently, locales for messages and date/time cannot separately be configured. If you want the feature, please create a new ticket.

Any thoughts on how to proceed to getting first of all the datepicker to show Monday first?

IMO, I have no plan to change it because libc doesn't have portable APIs which retrieves first day of week from the libc locale.

in reply to:  19 comment:21 by anonymous, 10 years ago

Replying to lkraav <leho@…>:

Any thoughts on how to proceed to getting first of all the datepicker to show Monday first?

You can use iso8601 (in user preferences date format or default_date_format) to get Monday first. (Of course then you also get other ISO 8601 features. I personally like them, but you may not…)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.