hairyhenderson / gomplate

A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
https://gomplate.ca
MIT License
2.73k stars 187 forks source link

locale for time functions #381

Open make-github-pseudonymous-again opened 6 years ago

make-github-pseudonymous-again commented 6 years ago

Is it currently possible to format dates in, say, French, instead of English?

hairyhenderson commented 6 years ago

Hi @aureooms, thanks for logging this issue! Unfortunately right now gomplate just wraps Go's time package, which currently does not support any sort of localization.

However, there is a wrapper project https://github.com/goodsign/monday/ which I could add support for specifically translating dates & times.

Can I get some more information about your use case?

Are you wanting to be able to specify the language/locale in which to format the date, and/or are you wanting to have gomplate respect the LANG and LC_TIME environment variables?

make-github-pseudonymous-again commented 6 years ago

Well I guess usually you would want a single language per document so environment variables would be perfect. That is my use case. But we are never sure one day someone will want to format dates in different languages in the same document.

hairyhenderson commented 6 years ago

Ok, thanks. Environment variables are easier to support, since they don't involve changing or adding function signatures 😉

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment or this will be automatically closed in a few days.

gedw99 commented 11 months ago

@hairyhenderson this looks pretty cool.

https://github.com/goodsign/monday/ looks perfect.

I guess it never happened ?

hairyhenderson commented 11 months ago

@gedw99 No, this never got implemented. Can you elaborate on your use-case?

gedw99 commented 11 months ago

@gedw99 No, this never got implemented. Can you elaborate on your use-case?

Same as original Issue maker. The ability to convert Date and Time to different locales formats.

But also to convert to and from UTC other users locale time. This is for when you're hitting a DB that holds all data time values in UTC. SO its just converting the values, not the format.

Pretty standard stuff for any i18n situation. You typically first need to convert the data, and then convert the format ( for any gui ).

Is that clear ?

hairyhenderson commented 11 months ago

Thanks @gedw99.

In the very simple case of converting time zones, that's already supported with functions like time.ParseInLocation, and converting from some timezone to UTC can be done with the UTC function on the parsed time.Time value.

For converting from UTC to local time you can use Local, which uses the TZ environment variable to inform which zone to use.

Anyway, that brings us back to locale-specific formatting, which is of course not yet supported.

I'd be willing to review a PR to add support for it, but I don't have the bandwidth to work on it myself right now.

gedw99 commented 11 months ago

Thanks @hairyhenderson

I guess I should have looked harder at the docs.

Regarding a PR and the local-specific formatting, I guess we first need locale detection as an option, rather than the TZ environment variable.

https://github.com/gioui/gio-x/tree/main/pref/locale for example