rmariuzzo / Laravel-JS-Localization

🌐 Convert your Laravel messages and consume them in the front-end!

Home Page:https://github.com/rmariuzzo/laravel-js-localization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get subfolder messages

Daviex opened this issue Β· comments

Hello.

I'm trying to get some languages texts from a subfolder.
The result message.js is creating the file correctly with the following code:

(function () {
    Lang = new Lang();
    Lang.setMessages({"en.javascript.datatables":{"emptyTable":"No data available in table"},"it.javascript.datatables":{"emptyTable":"Alcun dato disponibile"}});
})();

I checked over chrome console, and Lang has locale set to "it", so, I tried to do

Lang.get('javascript.datatables.emptyTable'); 

but it can't find nothing, in fact that string returns the pattern I wrote.
I'm executing wrongly the query for that string?

I also tried with a non subfolder file, and that worked perfectly...

Thanks

Hey @Daviex! Thanks for filing an issue I will check that issue later on the weekend, as I'm pretty busy with work and the ongoing ReactEurope event.

Ok @rmariuzzo, thank you. For now I resolved my problem by putting a main file into the lang folder and setting all the texts in there with sub keys, but I would like to use folders πŸ˜„

ps. Awesome library man πŸ”

Hey @rmariuzzo, did you had anytime to check over this thing?

Thanks

Hey man, did you had time to get a look at this?

Thanks

Ok thanks.

I tried to look over it, but really cound't find how to make it happen.

Any progress on this question ? It would be very nice to put JS translation in separate folder. In localization-hr.php configuration file I have following messages array:

 'messages' => [
    'js/config',
    'js/message',
    'js/page',
    'js/routes',
],

Tried Lang.get('js.config.key');, Lang.get('js/config.key'); and Lang.get('js:config.key'); but none works.

Thanks in advance and very nice package ;)

Thanks.

Hopes you can find a solution over this, for the time passed I used just a file in the root of the language folder, but a solution would be awesome :)

Another "hacky" solution to this is to create folder "lang-js" in "resources" folder.

And then when running npm and webpack mix, you can set source path:

const WebpackShellPlugin = require('webpack-shell-plugin');

mix.webpackConfig({
    plugins: [
        new WebpackShellPlugin({onBuildStart:['php artisan lang:js -c -s resources/lang-js'], onBuildEnd:[]})
    ]
});

I'm really sorry for the long wait. I'm still trying to balance my life after Hodgkin. From the original poster, I was able to get the expected message using:

Lang.get('javascript/datatables.emptyTable') // using `/` instead.

That's how it works on Laravel, therefore this work on Lang.js.

However, I will add a test for the / case into Lang.js repository.