Laravel-Lang/publisher

Add files from a custom plugin

forxer opened this issue ยท 8 comments

Environment

Note: this is not a "bug" but when I click on "Questions & Other" there is a 404 error

  • Laravel-Lang Publisher Version: 14.6.2
  • Laravel Version: 10.5.1
  • PHP Version: 8.2.4

Issue description

I've try to create a plugin for the common language terms i use in my applications "Generic term translations for Laravel"

But when I add the files through the publisher, they are well copied, but contain empty arrays.

I only used PHP files whether in the "source" and "locales" directories.

I wonder if it's the absence of a .json file that causes this or just an oversight on my part or a bad way of doing it.

Maybe there is a plugin development tool to generate the necessary, I know there is the plugin template but I want to start from scratch to better understand the mechanisms.

Steps to reproduce

Install the package:

composer require forxer/generic-term-translations-for-laravel --dev

Run:

 php artisan lang:update

Ps: I had already installed before laravel-lang/common

Note: this is not a "bug" but when I click on "Questions & Other" there is a 404 error

Thank you! The link has been fixed.


As for your problem, the path is incorrectly specified in the package.

Replace:

protected string $base_path = __DIR__ . '/../';

with

protected string $base_path = __DIR__;

https://github.com/forxer/generic-term-translations-for-laravel/blob/main/src/Plugin.php#L14

The problem is that this path points to a folder that contains the "source" and "locales" folders, and in your case they are located inside the "src" folder, while the link leads to the project root.

Everything else looks correct.

We also have a template for creating similar plugins. Just click the "Use template" button and edit it to suit your requirements.

image

Super fast! THANKS ๐Ÿ‘

Ah yes, I'm going to go up one level these two directories in order to follow the conventions of the other plugins.

Yes I saw the template, but as indicated in my initial message, I preferred to start from scratch in order to fully understand and improve it as I went.

I also noticed that the files in the src/locales folder are placed incorrectly.

A feature of our project is that it can simultaneously contain keys from different versions of the project and check for uniqueness. That is, by translating once, the translation will automatically be used wherever it is called.

What should be done:

  1. Run the console command vendor/bin/lang sync from a project folder.
  2. You will find the file src/locales/{locale}/php.json containing all keys for translations from all php files of the source folder
  3. Translate this file manually or call the vendor/bin/lang translate command to invoke the machine translation function.
  4. Remove PHP files from src/locale/ folders
  5. Commit and publish the release.

Ok i've moved the two folder, and it correctly publishe files and data.

However, I don't have a /vendor/bin/lang file.

This command is available if, in the forxer/generic-term-translations-for-laravel project, go to the console and execute composer update. It comes with the laravel-lang/status-generator package, which is listed in your dev dependencies.

You can also post a link to your project here.

I'll try to add some documentation and I'll do that. Thanks again.

You're welcome!