New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return localized weekdays for wday() #401

Closed
alberthkcheng opened this Issue Apr 8, 2016 · 11 comments

Comments

Projects
None yet
3 participants
@alberthkcheng
Contributor

alberthkcheng commented Apr 8, 2016

wday() always returns English names of weekdays. I made the following changes using date_names_lang in readr, to overcome this. Is there solution exists without using readr?

Also, the same applies to month.

wday.numeric <- function (x, label = FALSE, abbr = TRUE, language="en") 
{
  if (!label) 
    return(x)
  if (abbr) {
    labels <- date_names_lang(language)$day_ab
  }
  else {
    labels <- date_names_lang(language)$day
  }
  ordered(x, levels = 1:7, labels = labels)
}

wday(ymd(160408),label=TRUE,language="ko")
# [1] 금
# Levels: 일 < 월 < 화 < 수 < 목 < 금 < 토
@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Apr 8, 2016

Member

Yes. It's relatively easy to implement. This applies to month as well.

Member

vspinu commented Apr 8, 2016

Yes. It's relatively easy to implement. This applies to month as well.

@vspinu vspinu modified the milestones: v1.6.0, v1.5.6 Apr 8, 2016

@vspinu vspinu modified the milestone: v1.6.0 Aug 17, 2016

@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Aug 18, 2016

Member

Where would you get the localisation databases from? I think it's better to use non-operating system sources so code works the same way across platforms.

Member

hadley commented Aug 18, 2016

Where would you get the localisation databases from? I think it's better to use non-operating system sources so code works the same way across platforms.

@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Aug 18, 2016

Member

You don't need a data base. I had in mind something along the following:

> enc2utf8(unique(format(lubridate:::.date_template, format = "%a@%A")))
[1] "Thu@Thursday"  "Mon@Monday"    "Tue@Tuesday"   "Sun@Sunday"    "Fri@Friday"    "Wed@Wednesday" "Sat@Saturday" 
Member

vspinu commented Aug 18, 2016

You don't need a data base. I had in mind something along the following:

> enc2utf8(unique(format(lubridate:::.date_template, format = "%a@%A")))
[1] "Thu@Thursday"  "Mon@Monday"    "Tue@Tuesday"   "Sun@Sunday"    "Fri@Friday"    "Wed@Wednesday" "Sat@Saturday" 
@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Aug 18, 2016

Member

Oh, so the user would supply the localisation date names, not a language name?

Member

hadley commented Aug 18, 2016

Oh, so the user would supply the localisation date names, not a language name?

@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Aug 18, 2016

Member

Yes. By default wday would return names in current locale using the trick above. The new argument locale will accept a valid locale name on user's OS, or a shortcut for 100 common languages such that wday(2, locale = "en") would also work.

Member

vspinu commented Aug 18, 2016

Yes. By default wday would return names in current locale using the trick above. The new argument locale will accept a valid locale name on user's OS, or a shortcut for 100 common languages such that wday(2, locale = "en") would also work.

@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Aug 18, 2016

Member

100 is a bit too much but a small data set of common 10-20 languages should be doable.

Member

vspinu commented Aug 18, 2016

100 is a bit too much but a small data set of common 10-20 languages should be doable.

@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Aug 18, 2016

Member

readr has 185 ;)

Member

hadley commented Aug 18, 2016

readr has 185 ;)

@vspinu vspinu closed this in 6c88890 Nov 20, 2016

alberthkcheng added a commit to alberthkcheng/lubridate that referenced this issue Jan 16, 2017

alberthkcheng added a commit to alberthkcheng/lubridate that referenced this issue Jan 16, 2017

@alberthkcheng

This comment has been minimized.

Show comment
Hide comment
@alberthkcheng

alberthkcheng Jan 16, 2017

Contributor

Thank you for the fix :)

The one in Korean is good now. There is still one issue:
For traditional chinese, the format are different from the one in readr (which is more commonly used in HK, etc)

# lubridate
> enc2utf8(unique(format(.date_template, format = format)))
 [1] "四@周四@ 1@1月@上午@"  "一@周一@ 2@2月@下午@"  "二@周二@ 3@3月@上午@"  "日@周日@ 4@4月@下午@" 
 [5] "五@周五@ 5@5月@上午@"  "二@周二@ 6@6月@下午@"  "五@周五@ 7@7月@上午@"  "三@周三@ 8@8月@下午@" 
 [9] "二@周二@ 9@9月@上午@"  "五@周五@10@10月@下午@" "二@周二@11@11月@上午@" "六@周六@12@12月@下午@"
# readr
> locale("zh")
<locale>
Numbers:  123,456.78
Formats:  %Y%.%m%.%d / %H:%M
Timezone: UTC
Encoding: UTF-8
<date_names>
Days:   星期日 (周日), 星期一 (周一), 星期二 (周二), 星期三 (周三), 星期四 (周四), 星期五 (周五), 星期六
        (周六)
Months: 一月 (1月), 二月 (2月), 三月 (3月), 四月 (4月), 五月 (5月), 六月 (6月), 七月 (7月), 八月 (8月), 九月
        (9月), 十月 (10月), 十一月 (11月), 十二月 (12月)
AM/PM:  上午/下午

any idea @hadley @vspinu ?
I am willing to help to fix it if needed ;)

Contributor

alberthkcheng commented Jan 16, 2017

Thank you for the fix :)

The one in Korean is good now. There is still one issue:
For traditional chinese, the format are different from the one in readr (which is more commonly used in HK, etc)

# lubridate
> enc2utf8(unique(format(.date_template, format = format)))
 [1] "四@周四@ 1@1月@上午@"  "一@周一@ 2@2月@下午@"  "二@周二@ 3@3月@上午@"  "日@周日@ 4@4月@下午@" 
 [5] "五@周五@ 5@5月@上午@"  "二@周二@ 6@6月@下午@"  "五@周五@ 7@7月@上午@"  "三@周三@ 8@8月@下午@" 
 [9] "二@周二@ 9@9月@上午@"  "五@周五@10@10月@下午@" "二@周二@11@11月@上午@" "六@周六@12@12月@下午@"
# readr
> locale("zh")
<locale>
Numbers:  123,456.78
Formats:  %Y%.%m%.%d / %H:%M
Timezone: UTC
Encoding: UTF-8
<date_names>
Days:   星期日 (周日), 星期一 (周一), 星期二 (周二), 星期三 (周三), 星期四 (周四), 星期五 (周五), 星期六
        (周六)
Months: 一月 (1月), 二月 (2月), 三月 (3月), 四月 (4月), 五月 (5月), 六月 (6月), 七月 (7月), 八月 (8月), 九月
        (9月), 十月 (10月), 十一月 (11月), 十二月 (12月)
AM/PM:  上午/下午

any idea @hadley @vspinu ?
I am willing to help to fix it if needed ;)

@alberthkcheng

This comment has been minimized.

Show comment
Hide comment
@alberthkcheng

alberthkcheng Jan 16, 2017

Contributor

Also, AM/PM translated correctly in traditional chinese but not in Japanese and Korean.
The one in readr locale() are more completed for all the attributes.

Contributor

alberthkcheng commented Jan 16, 2017

Also, AM/PM translated correctly in traditional chinese but not in Japanese and Korean.
The one in readr locale() are more completed for all the attributes.

@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Jan 16, 2017

Member

Also, AM/PM translated correctly in traditional chinese but not in Japanese and Korean. The one in readr locale() are more completed for all the attributes.

I guess it's because readr is using its own data base for this. lubridate relies on system's libraries and compiles attributes like PM/AM on the fly. If thse are missing that probably means they are missing at system level.

Member

vspinu commented Jan 16, 2017

Also, AM/PM translated correctly in traditional chinese but not in Japanese and Korean. The one in readr locale() are more completed for all the attributes.

I guess it's because readr is using its own data base for this. lubridate relies on system's libraries and compiles attributes like PM/AM on the fly. If thse are missing that probably means they are missing at system level.

@alberthkcheng

This comment has been minimized.

Show comment
Hide comment
@alberthkcheng

alberthkcheng Jan 18, 2017

Contributor

I see. Thanks. Then I think let's leave it to #396 ... :)

Contributor

alberthkcheng commented Jan 18, 2017

I see. Thanks. Then I think let's leave it to #396 ... :)

vspinu added a commit that referenced this issue Jan 18, 2017

Merge pull request #508 from alberthkcheng/albert
[Fix #401 ext] Return localized labels in month
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment