-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add support for concat expressions in HBS files #483
Add support for concat expressions in HBS files #483
Conversation
8e4f1f7
to
26b2a29
Compare
I've actually always liked the fact that {{t (if @isEditing "actions.save" "actions.publish")}} or {{if @isEditing (t "actions.save") (t "actions.publish")}} Seem like much better ways of writing this to me. But, I understand that this tool is not a linter, so these changes probably make sense? |
Good point, I actually agree that my example is easier to read without the However, we also have places where the translation keys are longer and where it makes more sense to not duplicate the entire key, and I can imagine that more codebases have similar use cases. As I was already a bit familiar with the code after my other 2 PRs, I considered adding support for it here, so maybe it can still be a nice addition 🙂 |
26b2a29
to
6902edb
Compare
3c457f9
to
b7f8bc5
Compare
Hmm this one i'm a little conflicted on, while i think it is helpful to have this as im sure they are plenty of people that do it and it will be helpful for them as they wouldn't need to whitelist anything. But we are not able to support dynamic concatenation e.g. "string" + variable and i feel like having this change may make people attempt it and have the expectation that it should work. I'll have a little think about this one and get back to you early next week. One small thing about the actual changes, for completeness would you also have this for js concatenation? I'd assume this doesnt work for js as it stands |
Yeah, the dynamic concatenation is indeed something that this doesn't support. However, I did make sure that it is recognized, in which case the entire expression is ignored, so this might open up opportunities to try and notify/hint about their existence. About the JS concatenation, I didn't run into these cases in our codebase, so I haven't looked at it. I'm not sure how often this occurs though, and if it occurs, I don't know if only the ternary When you have time to have a look, then looking at the test cases might be a good start, as that clearly indicates what it actually supports then. |
b7f8bc5
to
040a9cb
Compare
040a9cb
to
ec41a75
Compare
@Mikek2252 in #514 I've added support to detect dynamic translations, which showcases the usefulness of this PR. With that in mind, would you have time to look at this PR 🙏 ? |
Hey sorry, i had a thought about this, would it be okay to make this "opt in" using the config file, that way it would discourage people from using unless they have a specific need for it |
That sounds reasonable 👍 In order to detect dynamic translations properly it's best to have this enabled though, but I've built that opt-in too, so I can also include the About the name, something like |
ec41a75
to
a326070
Compare
@Mikek2252 I've added the configuration option to make it opt-in, including a section on it in the Readme, curious what you think 👍 . |
@Mikek2252 any chance that you can have a look at this? |
@robinborst95 Hi thanks for this i will merge this and create a release, sorry i have been away a lot the last few weeks and havent had much time for open source |
After adding support for (in-repo) addons, I noticed that dynamically constructed translations were not recognized. In HBS files this is usually done with the
concat
helper, which is often just a combination of strings literals and if expressions (e.g.{{t (concat "actions." (if @isEditing "save" "publish"))}}
), and this PR adds support for that.Note that like my 2 other PRs, I haven't added
tests or(self-review) comments yet, I'll do that when this gets a chance of being actually merged. Edit: I added tests that contain some examples of what this PR actually adds support for.