Skip to content

Conversation

@sajjadhossainshohag
Copy link
Contributor

@sajjadhossainshohag sajjadhossainshohag commented Dec 10, 2024

Hey @QuentinGab,

I made a few things. Review this and if any changes are needed, you can change it.

  • I moved the default cache path to the storage folder for better alignment with Laravel conventions.
  • Added progress bar and improved messages

@sajjadhossainshohag sajjadhossainshohag changed the title Default cache path moved in storage folder Refactor Command: Align Cache Path with Laravel Conventions & Add Progress Bar with Improved Messaging Dec 10, 2024
@sajjadhossainshohag sajjadhossainshohag changed the title Refactor Command: Align Cache Path with Laravel Conventions & Add Progress Bar with Improved Messaging Refactor: Align cache path with Laravel conventions and add progress bar with improved message Dec 10, 2024
@QuentinGab
Copy link
Contributor

Thx for the PR! I'm going to look at it this week

Copy link
Contributor

@QuentinGab QuentinGab left a comment

Choose a reason for hiding this comment

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

Replacing base_path with storage_path is ok.
But I'm not gonna merge the progress part cause it will just make it less performant

{
Translator::clearCache();

info('Cache cleared');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why note prompt info function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before:

image

Now:

image

For more highlighting the message.

Comment on lines 92 to 103
private function syncMissingKeysWithProgress($translator, string $locale, array $missing): void
{
$progress = progress(label: 'Syncing...', steps: count($missing));
$progress->start();

foreach ($missing as $key => $value) {
$translator->setTranslation($locale, $key, null);
$progress->advance();
}

$progress->finish();
$this->components->info(count($missing) . ' missing keys have been synced.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Using progress is not really relevant here because setTranslations will add all missing translations in a single write. Doing a for-loop will just make it less performant.

Copy link
Contributor Author

@sajjadhossainshohag sajjadhossainshohag Dec 17, 2024

Choose a reason for hiding this comment

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

I know that, but installing the package in my big project took a lot of time. So, that's why I added a progress bar for knowing about progress.

We can show progress bar with the option, like --without-progress or with-progress. Please let me know your opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood, but the part taking time is getMissingTranslations not setTranslations.
I should certainly add a progress callback to getMissingTranslations so it could be displayed it the terminal. I'm gonna look at it this week, thx for the feedback!

Copy link
Contributor

@QuentinGab QuentinGab left a comment

Choose a reason for hiding this comment

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

Until I implement a progress callback, I'm gonna keep MissingCommand like it is.
Could you remove your change on the file?

Comment on lines 92 to 103
private function syncMissingKeysWithProgress($translator, string $locale, array $missing): void
{
$progress = progress(label: 'Syncing...', steps: count($missing));
$progress->start();

foreach ($missing as $key => $value) {
$translator->setTranslation($locale, $key, null);
$progress->advance();
}

$progress->finish();
$this->components->info(count($missing) . ' missing keys have been synced.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Understood, but the part taking time is getMissingTranslations not setTranslations.
I should certainly add a progress callback to getMissingTranslations so it could be displayed it the terminal. I'm gonna look at it this week, thx for the feedback!

@sajjadhossainshohag
Copy link
Contributor Author

sajjadhossainshohag commented Dec 17, 2024

@QuentinGab Removed my changes,

@sajjadhossainshohag sajjadhossainshohag changed the title Refactor: Align cache path with Laravel conventions and add progress bar with improved message Refactor: Align cache path with Laravel conventions Dec 17, 2024
@QuentinGab QuentinGab merged commit dffaec3 into ElegantEngineeringTech:main Dec 17, 2024
1 check passed
@QuentinGab
Copy link
Contributor

I took the time to add the progress indicator: https://github.com/ElegantEngineeringTech/laravel-translator/releases/tag/v2.1.1

@sajjadhossainshohag
Copy link
Contributor Author

@QuentinGab Thanks man.

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