andywer / laravel-js-localization

Simple, ease-to-use and flexible package for the Laravel web framework. Allows you to use localized messages of the Laravel webapp (see `resources/lang` directory) in your Javascript code.
MIT License
143 stars 51 forks source link

Unable to get translation to work (question on how this supposed to work) #69

Closed huangism closed 4 years ago

huangism commented 4 years ago

I am asking this because there is no explanation/example on how it actually works

I am using laravel 5.7

line in composer "andywer/js-localization": "dev-laravel-5"

in my messages.php I have 'test' => 'frtest' in lang/fr_FR folder

in js-localization.php file I have : 'locales' => [ 'en_US', 'en_AU', 'fr_FR', 'ja_JP' ], 'messages' => [ 'test' ], 'disable_config_cache' => true, the rest are all default

in my js file I am trying to use Lang.get( 'messages.test' ) or I tried Lang.get( 'test' )

This just returns the key messages.test or test

I don't know what I am doing wrong, I couldn't find any full examples on how this works so now I am stuck. Can anyone tell me how this thing actually works?

andywer commented 4 years ago

Sorry for the super late reply, but please refer to the README.

messages is supposed to be an object, not an array. Then it's Lang.get('test') 😉