Refer to main.js using wp_enqueue_script in a custom plugin file

Hi everyone!
Reading this posts I didn’t find a solution for my problem so I’m opening another thread :slight_smile:

I actually created a plugin where I store all of my custom functions like custom post type, filters, taxonomies etc to keep the function.php clean. What I need to to do is to create a function & action with a wp_enqueue_script because I need to create a js variable based on some php function ( I’m using WPML for making sage multilanguage and I need to pass the value of the current language to js because I need it to use for load more posts via ajax, but I need to detect in which language).
As far as I understood, if you use the action in the app/setup

add_action('wp_enqueue_scripts', function () {
  wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
  wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
}, 100);

the paths are handled by the assets.json file in the dist (somehow).
The problem is how to do a wp_enqueue_script from a file in the plugin folder.
How can I point to the right file / path?
Am I complicating everything and there is a smarter / leaner solution or a better place?
Thanks in advance. :heart: :heart:

EDIT:
Something like this will be fine, if I replicate it in a custom plugin. I tried this snippet in the setup.php for testing and if works.

add_action('wp_enqueue_scripts', function () {
  wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
  wp_localize_script(
    'sage/main.js',
    'icl_lang',
    apply_filters( 'wpml_current_language', NULL )
  );
}, 100);