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

timeago lang configuration #1563

Open
crownedgrouse opened this issue Mar 21, 2023 · 7 comments
Open

timeago lang configuration #1563

crownedgrouse opened this issue Mar 21, 2023 · 7 comments
Assignees
Labels
waiting-for-reply Question raised, need answer

Comments

@crownedgrouse
Copy link

Hi,
it is not clear how to configure 'timeago' language in revel, different from 'en'.
Code look to refer to a default language in Config, but no documentation about that.
Any clue ?

@notzippy notzippy self-assigned this Mar 21, 2023
@notzippy notzippy added the waiting-for-reply Question raised, need answer label Mar 21, 2023
@notzippy
Copy link
Collaborator

The source code should help with this.

@crownedgrouse
Copy link
Author

crownedgrouse commented Mar 21, 2023

Yes from what I understand, a second arg can specify lang,
but I still do not understand this , later in code :

lang, _ = Config.String(defaultLanguageOption)

BTW, documentation is missing on this.

@notzippy
Copy link
Collaborator

That only occurs if the language passed in is empty, so it would default to the global configuration value set in the config i18n.default_language. Which appears to be undocumented configuratuin option :-(

@crownedgrouse
Copy link
Author

Yes I tried to set to "fr" in Config, but instead to have
"about a second ago"
I got
"??? about a second ??? ??? ago ???"

I will try to dig further and propose a documentation if I understand what's going on ...

@notzippy
Copy link
Collaborator

Sounds like you are missing the french translations for about a second and ago. the way the function works is the configuration map timeAgoLangs caches the message translations for everything in the MessageFunc call

	timeAgoLangs[lang] = timeago.Config{
		PastPrefix:   "",
		PastSuffix:   " " + MessageFunc(lang, "ago"),
		FuturePrefix: MessageFunc(lang, "in") + " ",
		FutureSuffix: "",
		Periods: []timeago.FormatPeriod{
			{time.Second, MessageFunc(lang, "about a second"), MessageFunc(lang, "%d seconds")},
			{time.Minute, MessageFunc(lang, "about a minute"), MessageFunc(lang, "%d minutes")},
			{time.Hour, MessageFunc(lang, "about an hour"), MessageFunc(lang, "%d hours")},
			{timeago.Day, MessageFunc(lang, "one day"), MessageFunc(lang, "%d days")},
			{timeago.Month, MessageFunc(lang, "one month"), MessageFunc(lang, "%d months")},
			{timeago.Year, MessageFunc(lang, "one year"), MessageFunc(lang, "%d years")},
		},
		Zero:          MessageFunc(lang, "about a second"),
		Max:           73 * time.Hour,
		DefaultLayout: "2006-01-02",
	}

So you need to define in the french translation file what ago means and about a second and so on...

@crownedgrouse
Copy link
Author

OK, but by looking at timeago code, there is already a bunch of variables for several languages https://pkg.go.dev/github.com/xeonx/timeago#pkg-variables
So it is a pity having to set it, as code reading is required to list all strings to translate...

What about use those by default and set a config variable to fall back in current behavior?

@crownedgrouse
Copy link
Author

See PR #1564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-reply Question raised, need answer
Projects
None yet
Development

No branches or pull requests

2 participants