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

I18n tracking : manually mark an item as being used #549

Open
Systho opened this issue Sep 26, 2024 · 5 comments
Open

I18n tracking : manually mark an item as being used #549

Systho opened this issue Sep 26, 2024 · 5 comments

Comments

@Systho
Copy link

Systho commented Sep 26, 2024

Is your feature request related to a problem? Please describe.

I am using i18n-js for expsing a subset of my i18n keys to my javascript code.
Those keys are never used by any ruby code but I would like to report from javascript when a key (or a set of keys) are used.

I can easily make an API controller or a Channel for this and send a message from javascript but then I do not know how to tell Coverband to mark it.

According to this file I would be inclined to use Coverband.configuration.translations_tracker.track_key(flat_key) but this does not really feel like a public API

How can I do this ?

Describe the solution you'd like
In the best ever world, I wish the railtie would register a (safe) way to notify Coverband that a key has been used.
But in a more realistic world, I would love to a have public API available for marking a key as used (and possibly other entrypoint into Coverband )

Describe alternatives you've considered

  • Using Coverband.configuration.translations_tracker.track_key(flat_key) : feels like using a private API
  • fiddle manually with Redis : sounds like an even more terrible idea in terms of maintenance and leaking abstractions

Additional context

I could easily tune something for my use case, but I thought that I might not be the only one with this need

@danmayer
Copy link
Owner

I believe you can use the ignore config to match your translation keys...

https://github.com/danmayer/coverband/blob/main/lib/coverband/collectors/abstract_tracker.rb#L130

try adding a string that would be a regex to some keys you want to ignore and let me know if that works @Systho

@Systho
Copy link
Author

Systho commented Oct 25, 2024

Oh but I do not want to ignore anything, more like the opposite.

I actually want to track usage of keys in javascript, but since I'm not going through I18n.t(....) I need another mechanism to warn Coverband that a keys is actively used.

My point is to detect dead keys among the ones used in JS.

@danmayer
Copy link
Owner

danmayer commented Oct 29, 2024

hmm so if you are doing this manually ignore just means we won't try to report it as dead...but I get that isn't what you are looking for.

I guess if you are looking for a programmatic way to do this you mean you want to dynamically call something that will mark the translation key? So from your controller take a param then call track on it...

This is an example for the view tracker, but as you mentioned in the considered alternatives, i think calling track_key is the best.

> Coverband.configuration.view_tracker.track_key(identifier: "/home/danmayer/projects/coverband_rails_example/app/views/books/_form.html.erb") 

Coverband.configuration.view_tracker.save_report                                                                              => #<Set: {}>

not sure what else you would be looking for other than the track_key method, if you have something else in mind for the interface let me know.

@Systho
Copy link
Author

Systho commented Oct 29, 2024

Would you consider making Coverband.track_key() a public facade method which would encapsulate the technical implementation ?

Calling Coverband.configuration.view_tracker.track_key really feels like my code know too much about Coverband and would break if you ever decide to refactor any internal aspect of your code.

@danmayer
Copy link
Owner

I could do something like that but it would likely have to at least specify the view_tracker vs i18n or others trackers. that could be by method name or something like a type:

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

No branches or pull requests

2 participants