1111 <a href="https://github.com/justbetter/statamic-entry-translator"><img src="https://img.shields.io/packagist/dt/justbetter/statamic-entry-translator?color=blue&style=flat-square" alt="Total downloads"></a>
1212</p >
1313
14- Automatically translate the content of Statamic entries using translation services.
14+ Automatically translate the content of Statamic entries and global sets using translation services.
1515
1616## Features
1717
18- This package provides a seamless way to translate Statamic entries to different sites and locales using translation services.
18+ This package provides a seamless way to translate Statamic entries and global sets to different sites and locales using translation services.
1919
2020Features:
2121
22- - Translate entries to multiple sites/locales
22+ - Translate entries and global sets to multiple sites/locales
2323- Support for DeepL translation service
2424- Queue-based translation processing
2525- Configurable field exclusions
2626- Handles nested fields, replicators, and fieldset imports
27- - Statamic CP action for easy translation
27+ - Statamic CP actions for easy entry and global set translation
2828- Only translates localizable fields
29- - Automatically creates localizations if they don't exist
29+ - Automatically creates entry localizations if they don't exist
3030
3131> Also check out our other [ Statamic packages] ( https://github.com/justbetter?q=statamic ) !
3232
@@ -104,13 +104,24 @@ return [
104104
105105### Using the Statamic CP Action
106106
107+ #### Entries
108+
1071091 . Navigate to your entries in the Statamic Control Panel
1081102 . Select one or more entries you want to translate
1091113 . Click on the "Actions" dropdown
1101124 . Select "Translate Content"
1111135 . Choose the target sites you want to translate to
1121146 . Click "Run"
113115
116+ #### Global Sets
117+
118+ 1 . Navigate to your global sets in the Statamic Control Panel
119+ 2 . Select a global set you want to translate
120+ 3 . Click on the "Actions" dropdown
121+ 4 . Select "Translate Content"
122+ 5 . Choose the target sites you want to translate to, or select "All sites"
123+ 6 . Click "Run"
124+
114125The translations will be queued and processed asynchronously.
115126
116127### Programmatic Usage
@@ -143,23 +154,63 @@ $sites = Site::all()->filter(fn($site) => $site->handle() !== $entry->site()->ha
143154TranslateEntries::translateEntries($entry, $sites);
144155```
145156
157+ ### Translating Global Sets
158+
159+ To translate a global set to a single site:
160+
161+ ``` php
162+ use JustBetter\EntryTranslator\Facades\TranslateGlobalSet;
163+ use Statamic\Facades\GlobalSet;
164+ use Statamic\Facades\Site;
165+
166+ $globalSet = GlobalSet::find('settings');
167+ $sourceSite = Site::get('en');
168+ $targetSite = Site::get('nl');
169+
170+ TranslateGlobalSet::translate($globalSet, $sourceSite, $targetSite);
171+ ```
172+
173+ To translate a global set to multiple sites:
174+
175+ ``` php
176+ use JustBetter\EntryTranslator\Facades\TranslateGlobalSets;
177+ use Statamic\Facades\GlobalSet;
178+ use Statamic\Facades\Site;
179+
180+ $globalSet = GlobalSet::find('settings');
181+ $sourceSite = Site::get('en');
182+ $targetSites = Site::all()->filter(fn ($site) => $site->handle() !== $sourceSite->handle());
183+
184+ TranslateGlobalSets::translateGlobalSets($globalSet, $sourceSite, $targetSites);
185+ ```
186+
146187### Using Jobs Directly
147188
148189You can dispatch translation jobs directly:
149190
150191``` php
151192use JustBetter\EntryTranslator\Jobs\TranslateEntryJob;
193+ use JustBetter\EntryTranslator\Jobs\TranslateGlobalSetJob;
152194use Statamic\Facades\Entry;
195+ use Statamic\Facades\GlobalSet;
153196use Statamic\Facades\Site;
154197
155198$entry = Entry::find('entry-id');
156199$targetSite = Site::get('en');
157200
158201TranslateEntryJob::dispatch($entry, $targetSite);
202+
203+ $globalSet = GlobalSet::find('settings');
204+ $sourceSite = Site::get('en');
205+ $targetSite = Site::get('nl');
206+
207+ TranslateGlobalSetJob::dispatch($globalSet, $sourceSite, $targetSite);
159208```
160209
161210## How It Works
162211
212+ ### Entries
213+
1632141 . The package identifies all localizable fields in the entry's blueprint
1642152 . Fields that are excluded (by handle or type) are filtered out
1652163 . The source entry's data is extracted for the localizable fields
@@ -168,7 +219,17 @@ TranslateEntryJob::dispatch($entry, $targetSite);
1682196 . The translated content is merged with the original entry data
1692207 . The localized entry is saved
170221
222+ ### Global Sets
223+
224+ 1 . The package loads the global set variables for the source and target sites
225+ 2 . The package identifies all localizable fields in the global set blueprint
226+ 3 . Fields that are excluded (by handle or type) are filtered out
227+ 4 . The source global variables are translated by the configured translation service
228+ 5 . The translated content is merged with the original source data
229+ 6 . The target site's global variables are saved quietly
230+
171231The package handles:
232+
172233- Nested fields (fields within fields)
173234- Replicator fields
174235- Fieldset imports
@@ -186,11 +247,12 @@ namespace App\Translators;
186247use JustBetter\EntryTranslator\Translators\BaseTranslator;
187248use Illuminate\Support\Collection;
188249use Statamic\Entries\Entry;
250+ use Statamic\Globals\Variables;
189251use Statamic\Sites\Site;
190252
191253class MyCustomTranslator extends BaseTranslator
192254{
193- public function translate(Entry $source, Collection $localisableFields, Site $site): array
255+ public function translate(Entry|Variables $source, Collection $localisableFields, Site $site): array
194256 {
195257 // Your translation logic here
196258 // Return an array of translated data
0 commit comments