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

Cound you export this function or when translation has error get the original value #289

Closed
kumfo opened this issue Dec 5, 2022 · 7 comments · Fixed by #317
Closed

Cound you export this function or when translation has error get the original value #289

kumfo opened this issue Dec 5, 2022 · 7 comments · Fixed by #317

Comments

@kumfo
Copy link

kumfo commented Dec 5, 2022

code:

func (l *Localizer) getMessageTemplate(id string, defaultMessage *Message) (language.Tag, *MessageTemplate, error) {

repeat issue:
#275 (comment)

language.yaml:

base:
  foo: "foo {{ bar }} "

when I want to translate base.foo, it will be get error tips: function "bar" not defined.
I wish the key base.foo is exists, I'll get the string value foo {{ bar }} for translate result,and the err tip. if the key is not exists, I'll get the err and empty result.

@nicksnyder
Copy link
Owner

If you set the Funcs field of LocalizeConfig then go-i18n can execute the template correctly: https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/localizer.go#L70

Does that solve your problem?

@kumfo
Copy link
Author

kumfo commented Dec 6, 2022

If you set the Funcs field of LocalizeConfig then go-i18n can execute the template correctly: https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/localizer.go#L70

Does that solve your problem?

Sorry, I don't want to implement the Funcs, but I just want to cooperate with the frontend for international template rendering.

@nicksnyder
Copy link
Owner

What are you going to do with the "foo {{ bar }} " template once you have it?

@kumfo
Copy link
Author

kumfo commented Dec 6, 2022

What are you going to do with the "foo {{ bar }} " template once you have it?

frontend render the template like this: {{ number }} years ago, it can be rendered 10 years ago.
but now I have to use golang to render the template consistent with the frontend, because I need adapt to the adjustment of SEO.

so I want to use the same set of configurations.

@kumfo
Copy link
Author

kumfo commented Dec 6, 2022

I think that if can't parse functions should be returned the original result more reasonable.

of course, the error message is also returned, in this way, I can handle the translated strings according to my own ideas.

@nohajc
Copy link

nohajc commented Jan 27, 2024

I have a similar problem and I've submitted a PR #316 which makes it possible to just disable template processing completely.

I think it would make the library much more flexible in many real-world scenarios.

@nicksnyder
Copy link
Owner

With 2.4.0 there is now a way to disable template parsing. Check out the release notes for more info.

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

Successfully merging a pull request may close this issue.

3 participants