boxblinkracer / phpunuhi

PHPUnuhi - The easy composable framework to validate and manage translations
MIT License
72 stars 5 forks source link

Question about Shopware6 storage and project scope #47

Open mjosef89 opened 2 months ago

mjosef89 commented 2 months ago

Hi there,

first of all, thanks for this nice framework and sorry for the wall of text. I have looked at this specifically with a focus on Shopware 6 entities and have a few questions/remarks.

1) There are problems with null-values when using the "shopware6" format . However, these can always occur, e.g. if a product only have minimal data yet. From my point of view, this is a bug, or am I missing something?

Fatal error: Uncaught TypeError: PHPUnuhi\Bundles\Storage\Shopware6\Service\TranslationLoader::isBinary(): Argument #1 ($str) must be of type string, null given, called in /app/vendor/boxblinkracer/phpunuhi/src/Bundles/Storage/Shopware6/Service/TranslationLoader.php on line 167 and defined in /app/vendor/boxblinkracer/phpunuhi/src/Traits/BinaryTrait.php:38

I haven't tested it extensively yet, but it seems to be sufficient to convert null values to empty strings at this point.

2) If the "translate" command is called with the option "--source", an attempt is still made to translate missing translations of the source language itself. However, this will always fail in this case as $existingData = $set->findAnyExistingTranslation($currentID, $sourceLocale); will throw a TranslationNotFoundException.

If the source language is not skipped in the loop, if a text is missing you get an error message for each of the other languages plus additionally for the source language. I think this is unnecessary and the source language could be skipped in this case.

3) My intended use is mainly related to the translation of missing texts from Shopware entities. In my opinion, however, the logic here should be able to deviate from the usual snippets.

Using the product entity as an example: Based on the table structure, there are already fixed fields that Shopware supplies, but it may be that some of them are not needed in a project. Others could be optional and only be filled for some products.

As long as something is not available in the main language of the shop, it should not be considered "missing" in my case.

I would like the following behavior for shopware entities when the "translate" command is executed with option "--source":

If a value is missing in the "--source" language e.g. "description" skip it. Otherwise try to translate if for all other languages where a translation is missing.

As far as I could tell after trying around a bit, this does not seem to be possible at the moment, as the processing is always independent of the source (storage) and this special case for Shopware entities can therefore not be implemented without further ado.

The framework could certainly be extended in this regard, but I am unsure whether its a good idea to bend the framework in this direction, so I wanted to ask whats your opinion is about this use-case.

mjosef89 commented 1 month ago

Update

1) Has been fixed in the meantime 3) I have created a PR with a first rough approach on how to solve this

boxblinkracer commented 1 month ago

thanks for this @mjosef89 i've continued in the PR

i think thats the last thing of the issue text in here right?

mjosef89 commented 1 month ago

i think thats the last thing of the issue text in here right?

Yes thats right