themsaid / laravel-langman

Language files manager in your artisan console.
MIT License
874 stars 163 forks source link

Purge unused strings #47

Open joelcuevas opened 8 years ago

joelcuevas commented 8 years ago

How about a command for purging unused strings in lang files?

There is a potential problem with trans('app.type_' . $type) kind of translations, as the user will create custom entries in the files... but, still, I think that a command like this would be useful.

Maybe all the custom strings could be placed in files that could be blacklisted from purging at config level.

@themsaid, have you thought about a feature like this?

themsaid commented 8 years ago

Regarding the command for purging strings, I'm not quite sure if we can consider all the cases to check for an unused translation line, do you have any ideas on how to guarantee?

joelcuevas commented 8 years ago

Not sure either, but thinking on my workflow:

Hypothetically I would blacklist on config/langman.php files like resources/lang/en/status.php where things like ticket_open should be. This kind of translations are the ones that I use with trans('status.ticket_' . $status). In this files we should never assume that a string is not longer used (because we don't know) and live with it.

With the rest of the files, I would simply search all the translations that do not have an entry on Manager::collectFromFiles result and remove them, maybe with a preview and a prompt.

If on your project you're unable to separate translation keys like the ones on the "status" example from the normal keys, well, maybe you are not a candidate for a "purge" command, and you should continue using the rest of the commands as usually.

Too drastical? Are you thinking on more scenarios?

themsaid commented 8 years ago

Well I assume such command can be useful if you know what you're doing :) If you can PR such thing I'd gladly consider merging.

joelcuevas commented 8 years ago

Perfect! I think I could have something by the next week for you to review.

themsaid commented 8 years ago

👍 :)

morksinaanab commented 7 years ago

Have you guys been able to add this? I haven't installed langman yet, but i was indeed looking for the feature to purge unused strings.

Isn't it something like:

  1. 'fake' remove all keys keep them in a map, 2 run the find missing translation keys function keep that in a map,
  2. remove all found in 2 from 1 > resulting in a list of unused keys to remove?

(probably what joelcuevas is referring to, and indeed variable ones are harder anyway, the would not pop up in step 2 then anyways)

If there isn't another package that has this, and you are not continuing on this, i might take a shot at it?

Gummibeer commented 6 years ago

Couldn't the variable Part be solved by a preg_match!? And Display all Keys that have no real usage but matched by a variable usage to the User.

muisit commented 4 years ago

100 implements a --unused flag for the Show command that can give you a list of all keys that are not actively found in your project files. You can use the Remove command to remove those keys.

You can then script this to filter the list of unused keys with a known list of keys to retain anyway and remove the rest.