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

Get and similar functions don't always process formatting sequences #57

Open
bk2204 opened this issue Dec 14, 2021 · 1 comment
Open
Assignees
Labels
v2 Roadmap to v2.0.0 wontfix

Comments

@bk2204
Copy link

bk2204 commented Dec 14, 2021

Please describe your issue

Is this a bug, an improvement, a proposal or something else? Describe it.

This is a bug.

The Printf function used to format strings doesn't always invoke fmt.Sprintf. As a result, the expansion of %% sequences differs if there are arguments or not.

What's the expected behaviour, the current behaviour and the steps to reproduce it?

I expect that I can create a locale object, tr, and then do this:

a := tr.Get("My string with an escaped value: %%s")
fmt.Printf(a, "text")

And that it prints My string with an escaped value: text. I happen to need this because I have a map of integers to format strings, where the format strings contain %% sequences.

Unfortunately, the behavior is inconsistent, so things are only passed through fmt.Sprintf if there are arguments. This makes the behavior hard to reason about.

Comments

If there were separate functions to read strings that were formatted and ones that were not, this wouldn't be a problem.

@leonelquinteros
Copy link
Owner

Hi @bk2204 , totally understand your issue.
I think this is because of premature optimization on that method.

Let me give it a thought or two and get back with a proposed solution for it.

In the meanwhile, there may be some workarounds for it. I'm thinking on passing maybe a null or any placeholder value to the translation function, so you force the fmt.Sprintf call, like:

a := tr.Get("My string with an escaped value: %%s", null)
fmt.Printf(a, "text")

Should behave as you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 Roadmap to v2.0.0 wontfix
Projects
None yet
Development

No branches or pull requests

2 participants