'Gutenberg custom block inheritance for duplication

I've been designing custom Gutenberg blocks. The problem I'm now running into is the amount of duplication settings (attributes with their own control fields) I have. I figured I'd put these in their own JavaScript files and import them. Like so:

import { getHeadingSettings } from "../settings/heading";

This works just fine except for translating the wp.i18n entries inside the import. I can't seem to properly enqueue these scripts or translate them with wp_enqueue_script() and wp_set_script_translations().

wp_enqueue_script( "test-settings-heading", TEST_THEME_URL . "/includes/gutenberg/settings/heading.js", array( "wp-i18n" ) );
wp_set_script_translations( "test-settings-heading", "test-theme", TEST_THEME_PATH . "/languages" );

So my question is: is there a better way to solve this kind of duplication, or perhaps does someone know how I can use wp_set_script_translations() on my imported files?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source