php-translation / symfony-bundle

Symfony integration for Translations
MIT License
327 stars 94 forks source link

Allow syncing the translations for a specific locale #405

Open nicwortel opened 4 years ago

nicwortel commented 4 years ago

I would like to be able to specify a locale when running bin/console translation:sync, so that I can push translations of our source language (English) to the remote storage (direction = up, so that existing translations in the remote storage will be overwritten) without changing any of the translations that are stored there for other languages.

The reason is that we commit our English translations (messages.en.xlf) in our repository and use them as our "source", while we gitignore all other translations and download them from Loco as part of our build process. We want to be able to change the English translations locally in our source code, commit those changes / merge them to master, and then let our CI pipeline push those changes to Loco, overwriting the English translations there. But we don't want to overwrite any changes to the translations for other locales that may have been made by translators in Loco.

Would you be open for a pull request that adds an optional locale argument to the translation:sync command, similar to the locale argument that can be passed to translation:extract? So when omitted the command will continue to work as it does now, but when you supply the locale argument only translations for that locale will be synchronized.

As far as I can see the required change would be limited to adding a $locale argument to the StorageService::sync() method, the StorageService::mergeUp() method and the StorageService::mergeDown() method. The mergeUp() method calls getCatalogues() on the CatalogueFetcher, which already supports a $locales array. The mergeDown() method calls StorageService::download(), where we could also add a $locale parameter to download only translations for a single locale.

welcoMattic commented 4 years ago

Hi! Your working case seems legit for legacy application that use language as source, and I guess that you are not alone with this case. The solution seems to me pretty nice because it cover another case, which is when you want to deploy your application as long as you're working an a new language implementation and want to avoid sync the WIP language translations. Here a $locales parameter would be nice to sync only passed locales.

@php-translation/deciders WDYT?

Nyholm commented 4 years ago

I like the feature. Isnt this very related to https://github.com/php-translation/symfony-bundle/pull/378?

I mean, could one use exportOptions to support this feature?