Closed alanondra closed 3 years ago
The Matice object is globally available on the client side in the browser,
I think in the next versions, i'll make it available in the 'window' object directly,
The Matice object is globally available on the client side in the browser,
Unless I'm trying to bundle it with the rest of my JS, in which case neither import
nor require
can pull it in.
For comparison the Ziggy package also does this.
You can bundle matice.js which is the js part of the package. But you should not bundle the generated translations. The Matice object just contains translations that are used by the matice.js package.. Think that matice_translations.js instead of being a js file could be a json
, yml
or a simple text file which contains the translations.
To bundle matice.js, run: npm install matice
then import and use:
// app.js
import {__, trans, transChoice, setLocale, locales, getLocale} from "matice"
Hi! Is it ok for you?,
The NPM package still depends on the variable from this feature existing. This isn't resolved.
Hi! Is it ok for you?,
I believe alanondra is right; I'm having the same issue. Without the
export { Matice };
and a subsequent window.Matice = Matice;
I just can't get it to work. Keep getting the error:
ReferenceError: Matice is not defined
This is a pain cause I have to manually edit the .js every time the translations change...
The Matice object is globally available on the client side in the browser,
Where is this in the code? I can't locate it anywhere.
It's not available anywhere. It has to be added to the Command that generates the code. There's literally no point to building this functionality if this extra line is not added.
I was personally trying to use it so I could build it into my application's minified JS file the same way I'm currently doing it with the aforementioned routing package Ziggy.
I am not certain why this issue is closed. Having the same problem Laravel 9 & Inertiajs.
I solved it by adding in my service provider
Event::listen(function (CommandFinished $event) {
if($event->command == 'matice:generate') {
file_put_contents(config('matice.generate_translations_path'), PHP_EOL . 'export { Matice };', FILE_APPEND);
}
});
@ahmeddabak can you open a PR?
Expected behavior
The the line below as per documentation would appear at the end of the generated translations file:
Current behavior
This line is missing from the
\Genl\Matice\Commands\TranslationsGeneratorCommand::handle()
method. As a result this line would have to be manually entered every time if one is to compile the resultant file as part of their JS deployment.Versions