angular-translate/grunt-angular-translate

Support for ignore some 'unused' keys

Gotusso opened this issue · 6 comments

In our project sometimes we need to generate translation keys by concatenating strings.
If we don't use the option 'safeMode', those keys are removed.
The problem is that if we use it, those keys remains untouched but the unused keys (generated by typos or just not used) are not removed.

It would be really nice to have an option to avoid the removal of the 'unused' keys from a specific module, while keeping the behavior for the remaining modules untouched.

Hey @Gotusso
If I well got it, you want run extraction without delete existing keys into you json ?
The safeMode doesnt delete unused keys and doesnt update "valid" keys so I'll add an keepExtra option to update existing keys from extraction and keep extra keys in json file!

Sorry, I'm not sure about what do you mean with "update" keys. My use case is more o less this:

Javascript:

// Get some value from the server
var backendValue = 'bar'; 
// Get the translation and use it somewhere
$translate('foo.' + backendValue).then(function(value) {
    // ...
});
// 'fo' is a typo
$translate('fo.' + backendValue).then(function(value) {
    // ...
});

JSON before running the grunt task:

{
    "foo": {
        "bar": "Hello world!"
    },
    "bar": {
        "baz": "Unused translation"
    }
}

Expected JSON after running the grunt task:

{
    "foo": {
        "bar": "Hello world!"
    }
}

So I'm thinking about a configuration like this:

{
            namespace: true,
            safeMode: false,
            keepExtra: [
                'foo.**'
            ]
        }

And with that, the task could know that it must keep everything inside foo translations and work as usual for the rest.
What do you think?

If I well understand, you want ignore some pattern key to be able to write them down manually ?

Exactly

Okay @Gotusso i'll try to do the job

Thanks!