Opened 12 years ago
Last modified 10 years ago
#10757 new enhancement
Use language specific starting day for date picker
Reported by: | 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)
follow-up: 3 comment:1 by , 12 years ago
comment:2 by , 12 years ago
Cc: | added |
---|
comment:3 by , 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 , 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 , 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?
follow-ups: 7 13 comment:6 by , 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 (likeja.xml
) should be handled as territory001
: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?
follow-up: 8 comment:7 by , 12 years ago
Cc: | added |
---|
If Babel is not available
req.locale
isNone
, 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, butas
/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.
follow-up: 9 comment:8 by , 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
. Becauseiso8601
appears in onlyreq.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
comment:9 by , 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
comment:12 by , 12 years ago
Component: | general → i18n |
---|---|
Keywords: | userpreferences added |
Milestone: | → next-major-releases |
comment:13 by , 12 years ago
Actually, is
LOCALE_ALIASES
enough? (E.g.IN
is noted for Sunday, butas
/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!
comment:15 by , 10 years ago
Cc: | added; removed |
---|
comment:16 by , 10 years ago
Keywords: | preferences added; userpreferences removed |
---|
follow-up: 18 comment:17 by , 10 years ago
Cc: | 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
comment:18 by , 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'
follow-ups: 20 21 comment:19 by , 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?
comment:20 by , 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.
comment:21 by , 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…)
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.