Skip to content

Commit

Permalink
🌐 add Bundle::translate() (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dathix authored Jan 25, 2024
1 parent 07a7797 commit 4d264ae
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Roots/Acorn/Assets/Concerns/Enqueuable.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ public function localize($name, $object)
return $this;
}

/**
* Add script translations to be used by the bundle
*
* @param string $domain
* @param string $path
* @return $this
*/
public function translate($domain = null, $path = null)
{
$domain ??= wp_get_theme()->get('TextDomain');
$path ??= lang_path();

$this->js()->keys()->each(function ($handle) use ($domain, $path) {
wp_set_script_translations("{$this->id}/{$handle}", $domain, $path);
});

return $this;
}

/**
* Merge two or more arrays.
*
Expand Down

0 comments on commit 4d264ae

Please sign in to comment.