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

Template execution consideration #88

Closed
dgricci opened this issue Feb 25, 2018 · 3 comments · Fixed by #92
Closed

Template execution consideration #88

dgricci opened this issue Feb 25, 2018 · 3 comments · Fixed by #92
Assignees
Milestone

Comments

@dgricci
Copy link

dgricci commented Feb 25, 2018

Hi,

First of all, thank you for this nice tool !

My use case :

  • use cobra and its templates ;
  • use go-i18n to have translation of the templates.

I am facing what follows with templates :

  1. in the toml files : the template contains client application functions : goi18n application fails to convert it the flat file into json because those client applications functions are not known at that moment ;
    • I have to write by my self the json files ;
  2. in my application, I just want to get the template as pass it to the client application for processing : again, it fails cause the Execute() function is called when getting the template and there is no arguments so far to make the execution correctly.
    • I don't known how to get this working in the end ...

Digging into the code, I must admit that the Execute() function on template is always called even if there is no arguments (https://github.com/nicksnyder/go-i18n/blob/master/i18n/translation/template.go#L37 called by https://github.com/nicksnyder/go-i18n/blob/master/i18n/bundle/bundle.go#L387).

Do you have any clue on how to manage this use case : let client application handle template execution ?

@nicksnyder
Copy link
Owner

I am not familiar with cobra, but you are correct that go-i18n does always execute the template (if the string contains at least one {{ in it).

text/template allows customizing the delimiter, so if you have access to the template from cobra then you can change the default delimiter there (and update your strings to use that delimiter).

go-i18n should ideally allow you to customize the delimiter too (but it doesn't currently). This would essentially allow you to disable templating in go-i18n strings by setting a delimiter that is never used.

@nicksnyder nicksnyder added this to the v2 milestone Apr 5, 2018
@nicksnyder nicksnyder mentioned this issue Apr 10, 2018
Merged
4 tasks
@nicksnyder
Copy link
Owner

nicksnyder commented Apr 10, 2018

v2 contains a proposal to fix this. See #92, more specifically https://sourcegraph.com/github.com/nicksnyder/go-i18n@v2-beta/-/blob/i18n/example_test.go#L126:6

@nicksnyder nicksnyder self-assigned this Apr 10, 2018
@nicksnyder
Copy link
Owner

I just tagged 2.0.0.beta.1. Please start using it and report any issues that you have.

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.

2 participants