Skip to content
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

tpl: Add localizedDate template function #2041

Closed
wants to merge 1 commit into from

Conversation

soundrussian
Copy link

@soundrussian soundrussian commented Apr 2, 2016

This adds a template function to implement date localization, as was discussed in issue #245. All credit should really go to @variadico , I've just created a pull request to learn myself some Go.

@CLAassistant
Copy link

CLAassistant commented Apr 2, 2016

CLA assistant check
All committers have signed the CLA.

@digitalcraftsman
Copy link
Member

Hi @soundrussian,

it's a good idea to implement such a template function, especially while looking at #1744.

The default locale is based on environment variables. However, if people want to change the locale, they can start Hugo like this.

We should find a workaround once we have i18n support as a feature. Inside the template we will have access to the locale of the current page. Depending on the locale visitors should see the date formatted respectively. But this seems only to be possible when we set / change the environment accordingly.

@variadico
Copy link

Actually, it is possible to set the locale during runtime by calling lctime.SetLocale.

lctime.SetLocale("es_MX")
fmt.Println(lctime.Strftime("%c", time.Now()))
// prints: lun 14 dic 2015 22:31:56 PST

From the readme.

@digitalcraftsman
Copy link
Member

My bad. Thanks for the correction. Anyhow, it's a powerful combination.

@bep
Copy link
Member

bep commented Apr 3, 2016

This one needs some thinking, the bigger picture and all.

@soundrussian
Copy link
Author

I've updated the code to set locale from languageCode instead of environment variable, this seems more user-friendly. There might be some differences though between the formats of languageCode and expected locale, which I tried to address, but I'm not sure how languageCode is used in the wild.

@digitalcraftsman
Copy link
Member

Could you also add a few words for the documentation? Take a look at the examples in docs/content/templates/functions.md.

Maybe it seems trivial but why I would use localizeDate instead of localizedDate as function name.

@soundrussian soundrussian force-pushed the master branch 4 times, most recently from bb794d0 to 72cb2f2 Compare April 3, 2016 15:52
tpl: use languageCode to set locale

Rename function to localizeDate

docs: Describe localizeDate template helper
@soundrussian
Copy link
Author

I agree that localizeDate is a better name, since it implies some action on the provided arguments. Changed the name and added extensive documentation.

@digitalcraftsman
Copy link
Member

bep: This one needs some thinking, the bigger picture and all.

How would you define the bigger picture? The multilingual feature should provide a frame. A more precise context about parts that need some thoughts could help.

I don't want to rush by adding this as a last-minute feature if we release the next version of Hugo soon. It's just a nice addition that fills a gap.

@moorereason
Copy link
Contributor

I don't like the strftime formatting. That's the bigger picture I'm concerned about. If this PR used Go time formats, I'd be on-board.

@bep
Copy link
Member

bep commented Sep 15, 2016

I don't like the strftime formatting. That's the bigger picture I'm concerned about.

That is an extremely narrow minded picture ... I don't see the bigger picture, but I'm hoping someone else, specialists outside this project, would paint it for me. We're in the process of pulling lots of small localize* into a fairly fragmented and hard to maintain set of functions; there are language rulesets, dictionaries etc. duplicated, most likely not complete (I notice some shortcomings in my own language) ...

We're not adding this in 0.17. What gets added is very hard to remove.

@variadico
Copy link

@moorereason, Go makes international dates literally impossible. That's why lctime exists.
https://github.com/variadico/lctime#the-problem-with-the-go-standard-library

This is a trade off between slightly more idiomatic code—and giving non-English users the luxury of dates.

@stale
Copy link

stale bot commented Dec 6, 2017

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 6, 2017
@stale stale bot closed this Dec 27, 2017
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants