Closed Xeroner closed 7 years ago
I wan't to import my translation, not build new one...
I am not sure if I get what your question is... You posted some JS snippet that is supposed to work.
What do you mean be "import, not build new one"?
How to import translations from resources/lang/en/all.php to .js file ?
See https://github.com/andywer/laravel-js-localization#configuration.
So if you use it like Lang::get('all.xy')
in PHP, then configure it like:
...
'messages' => [ 'all' ],
...
Hi @andywer ,
I have an Italian language folder in resources/lang.
I added the Italian to config file :
'locales' => ['en', 'it']
And added my translations into messages :
'messages' => [ 'test' ],
When I viewing the page in English everything works fine, when I switch to Italian I am getting error :
localization.js:1 Uncaught Error: No messages defined for locale: "it". Did you forget to enable it in the configuration?
I checked the message.js file and it doesn't contain the IT translations in.
Any ideas why ?
Hey! No, it's hard to say. Did you do a php artisan js-localization:refresh
?
@andywer, thanks for your reply.
I disabled the cache in config : 'disable_config_cache' => true
.
In case, I ran `php artisan js-localization:refresh too but no success.
Sorry, @hpolonkoev. Can't tell from here...
I let you know if I have another idea. Please let me/us know if you solve it :)
@andywer thanks anyway!
Hi, i use this config: `<?php
return [
/*
|--------------------------------------------------------------------------
| Define the languages you want exported messages for
|--------------------------------------------------------------------------
*/
'locales' => ['ru'],
/*
|--------------------------------------------------------------------------
| Define the messages to export
|--------------------------------------------------------------------------
|
| An array containing the keys of the messages you wish to make accessible
| for the Javascript code.
| Remember that the number of messages sent to the browser influences the
| time the website needs to load. So you are encouraged to limit these
| messages to the minimum you really need.
|
| Supports nesting:
| [ 'mynamespace' => ['test1', 'test2'] ]
| for instance will be internally resolved to:
| ['mynamespace.test1', 'mynamespace.test2']
|
*/
'messages' => [
'status'
],
/*
|--------------------------------------------------------------------------
| Set the keys of config properties you want to use in javascript.
| Caution: Do not expose any configuration values that should be kept privately!
|--------------------------------------------------------------------------
*/
'config' => [],
/*
|--------------------------------------------------------------------------
| Disables the config cache if set to true, so you don't have to
| run `php artisan js-localization:refresh` each time you change configuration files.
| Attention: Should not be used in production mode due to decreased performance.
|--------------------------------------------------------------------------
*/
'disable_config_cache' => true,
];`
but in section @yield('js-localization.head') in layout i have code: `
<script type="text/javascript">
Lang.setLocale("en");
</script>`
i fink, need ?
sorry ,my english) i hope u will understand me
Hey @kocapb.
I guess you are lacking a App::setLocale('ru')
in your PHP code. Does App::getLocale()
return the expected result?
thanks a lot, bug resolved
How to import translations from resources/lang/en/all.php ?
Lang.addMessages({ "en": { "partnership": "Create report", } }); Lang.setLocale("en"); console.log(Lang.get('partnership'));