Skip to content

Conversation

Jarlskov
Copy link

Possible fix for #29

I'm not sure if the storage + storage_path approach is good, of if I should rather go for splitting the storage 'file' option into a 'public' and 'storage' option so the user can choose whether files should be written to 'public' so it can be included straight in the markup, or 'storage' for use in JS compilation.

@@ -42,8 +43,76 @@ public function fire()
throw new ConfigException('Please set the "locales" config! See https://github.com/andywer/laravel-js-localization#configuration');
}

MessageCachingService::refreshCache();
ConfigCachingService::refreshCache();
switch (Config::get('js-localization.storage')) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use the new methods generateMessagesFile and generateConfigFile here to refresh the cache data if Config::get('js-localization.storage') === 'file'. But the generated static files are not used for serving data via the HTTP service (and that would probably introduce a performance penalty).

This seems confusing, since the refresh command is for refreshing the service cache.

@andywer
Copy link
Owner

andywer commented Feb 10, 2017

Hey @Jarlskov! Thanks for your efforts :)

I am not sure about the approach of configuring + changing the refresh command (see my comment in the code diff).

Suggestion: Since the generation of the static files seems not so related to the refresh command (tell me if you see it differently 😉) I would think that adding a new command would be the most intuitive solution.

Like js-localization:export or something like that. It might trigger a refresh first and then create an up-to-date message and config file.

What do you think?

@Jarlskov
Copy link
Author

You got a good point.
I considered the command as a general refresh command, but reading the description again it actually says Refresh message cache.
I'll create a new command. That would also allow removing the storage setting, and hopefully, prevent any confusion regarding the current blade tags.

@Jarlskov
Copy link
Author

I've created a js-localization:export command for generating the static files.

@andywer
Copy link
Owner

andywer commented Feb 10, 2017

This looks better. Good job :)

I will leave some more comments on the code, but nothing major.

Copy link
Owner

@andywer andywer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review done. Just some minor changes that would make the code a bit better and might help the user.

*
* @param string $path
*/
public function generateMessagesFile($path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerns generateMessagesFile as well as generateConfigFile:
If the only parameter is $path I would expect that this path is supposed to be the output file path. But here it is the path to the output file's parent directory.

Suggestion: In both methods let $path be the output file path. Either have two config options for the two files or leave it as it is and just do the $path = Config::get('js-localization.storage_path') . 'messages' in the fire() method.

if (!is_dir($path)) {
mkdir($path, '0777', true);
}
$path = $path . 'messages';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just messages, not messages.js?

{
$config = ConfigCachingService::getConfigJson();
if ($config === '{}') {
return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we should at least log a warning or something, so if the user expected a config file to be created they at least know why it's not there (because no configuration values are marked for export).

* @param string $messages
* @return string
*/
protected function ensureBackwardsCompatibility($messages)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This backwards-compatibility hack is pretty old. I suppose we can drop it for the new feature.

@andywer
Copy link
Owner

andywer commented Feb 13, 2017

Awesome, @Jarlskov! 👍👍

Just one more thing (sorry!) that came to my mind when reading the new code:
The storage_path defaults to this package's directory. It's really hard to tell where the user will desire the newly created files to be written to.

Just an idea: How about passing the output directory as an argument to the export command? Might default to ./ (cwd).

@Jarlskov
Copy link
Author

I'm not sure about what you mean by the last comment. The storage_path should be where the user desires the files, no?

We could add a flag so you can add a path when you call the command, but I'm not sure why you would want to force it on each call, instead of allowing the user to set one path that's used every time. Or am I misunderstanding something?

@andywer
Copy link
Owner

andywer commented Feb 13, 2017

My line of thought was just:

As a user when I want to run the export command the very first time I might expect it to ask me where to export. Otherwise I will wonder where it wrote the files to and how I can change it. So we might need to print a hint how the output directory can be changed.

Might be easier to just let the user do ./artisan js-localization:export ../frontend/externals/, a ./artisan js-localization:export without parameters just shows how to use the command. It's also easier to trigger a test export when debugging without overriding the existing output files, for instance.

But it's just a fresh thought. So you feel setting it once in the config might nevertheless be preferrable?

@Jarlskov
Copy link
Author

Ok, I see the point. I'm just thinking that when you install the package, you have to open the config file, to specify what you want to export, so you already see the path in the config.

I should probably add something about it to the README, though, so it's documented.

@andywer
Copy link
Owner

andywer commented Feb 13, 2017

Good point as well :)

@Jarlskov
Copy link
Author

I've added usage instructions to the README.md :)

@andywer
Copy link
Owner

andywer commented Feb 13, 2017

Cool :)

Will review very soon. Sorry that it takes a bit longer, but I am spending some days with my girlfriend. Got more time in a few days 😉

@Jarlskov
Copy link
Author

No worries, enjoy your time with her! :-)
Thanks for the help so far, it's been a great learning experience!

@andywer
Copy link
Owner

andywer commented Feb 16, 2017

I just adapted the updated README a little bit: 60a85eb

Tell me if you are fine with it :)
Ready to merge when you are 😉

@Jarlskov
Copy link
Author

Looks good, thanks for fixing my horrible sub-heading :-)
I'm fine with it, so if it seems useful, I have no problem putting my name on it.

@andywer andywer merged commit be35ca1 into andywer:laravel-5 Feb 16, 2017
@Jarlskov Jarlskov deleted the allow-saving-to-disk branch February 16, 2017 13:42
stefanschindler added a commit to CampaigningSoftware/laravel-js-localization that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants