appswithlove / statamic-one-click-content-translation

Translate your content in statamic with one click
https://statamic.com/addons/awl/deepl
5 stars 2 forks source link

Feature Request: Ability to translate an entire entry on save #44

Closed mgtcampbell closed 4 months ago

mgtcampbell commented 5 months ago

Hi there,

Wondering if there's any plans to allow a whole page to be translated at once, instead of field by field.

Further to that would be the ability to set this to automatically happen for any pages in other languages on Save.

Example:

We have a client with a multisite who is saying it would still be too much manual work to click on the translate button on every language version every time they make a small udpate.

I understand this is far beyond the current scope so just interested to know if it's something that's being considered.

Cheers Mark

OleksiiBrylin commented 4 months ago

Having it done automatically seems to be a bigger task to handle different cases and problems. We are not planning to make this function in next 3-6 months

mgtcampbell commented 4 months ago

Thanks @OleksiiBrylin - appreciate this is a much tougher task.

In the meantime I have done some work on an attempt to do this myself and it has presented some unique challenges for sure.

OleksiiBrylin commented 4 months ago

one of the possible solution can be - to find, translate and replace text strings directly in .md files by regular expression. It will not cover all cases like stored in DB data, or some uniq cases of some projects. But it can perfectlly make simple entry translations.

        $regexp = '/(title|text|caption|date|content): ([\"]([\s\S\n]+?)[\"]|[\']([\s\S\n]+?)[\']|([\s\S]+?)\n)/';
        preg_match_all($regexp, file_get_contents($filePath), $matches, PREG_SET_ORDER, 0);

        foreach ($matches as $key => $text) {
mgtcampbell commented 4 months ago

Thank you, that's super helpful - not an approach I had considered.

To start I was pulling the Statamic Entry model and then getting the json for the content via the $entry->data(); method... but the issue there is that it's hard to tell within the json data which parts are actual text entries vs just other text within the json data as it doesn't make any mention of field type.

I also tried pulling $entry->blueprint()->fields()->all(); to cross reference the field types, however since I am importing a number of field types this only returns the name of the import, not the field types within that input.

I'll look into your suggestion of pulling from the markdown files directly instead.