Laravel-Lang / lang

List of 126 languages for Laravel Framework, Laravel Jetstream, Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova, Laravel Spark and Laravel UI.

Home Page:https://laravel-lang.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser deletes some existing tags for Laravel Jetstream

luisprmat opened this issue · comments

  • Laravel-Lang Version: 10.1.6
  • PHP Version: 8.0.3

Description:

In previous pull requests we add translations for all tags of laravel jetstream up to that moment. Among them (PR #1393 and #1394) were the following that correspond to the file JetstreamWithTeamsServiceProvider

  • Administrator
  • Administrator users can perform any action.
  • Editor
  • Editor users have the ability to read, create, and update.

When installing a new project these tags remain untranslated although within Jetstream they still have translation support.

Bug-llang

But if I add these keys to the es.json they get translated automatically without doing anything else.

The main reasons for this behavior are:

  • This parser looks for matches in the packages (breeze, fortify and jetstream) with strings '__(', 'trans(', '@lang(', 'Lang::get(' for select keys to translate and apply regular expressions deleting keys that do not match any package.
  • These tags wasn't ignored because they were wrapped in the operator __( ), but recently in laravel jetstream these keys was taken out of this operator (PR #837) in favour of a new method jsonSerialize() so they were removed from json files with their translations.
  • Even so the translations are supported within the Role class so they work perfectly if the translations are added.
    public function jsonSerialize()
    {
        return [
            'key' => $this->key,
            'name' => __($this->name),
            'description' => __($this->description),
            'permissions' => $this->permissions,
        ];
    }

I would like to find a way that these tags are not excluded from the file source/packages/jetstream.json

Steps To Reproduce:

  • Install a fresh Laravel application with Jetstream + Teams
laravel new my-app --jet
  • Choose livewire stack with teams.
  • Configure .env file (database, etc) and run migrations, install and run node dependencies
php artisan migrate
npm install && npm run dev
  • Register an user
  • Install and set a new language using translations of this package.
  • Go to Teams dropdown, and Team Settings

This is problem. Dynamic keys can be absolutely anything, so the 100% regex will not work correctly.

I suggest a solution: add a new file, for example, jetstream-ext.json and save such keys to it.

Or modify the parser for not deleting the existing keys but merge with new found keys! More difficult? is there any disadvantage?

This is easy, but unnecessary.

We made automatic deletion on purpose to get rid of old keys.

The important issue is to provide a solution that allows adding and keeping those keys that do not match to any regular expression and that they can be merged with all [locale].json to be translated.

If I understand you correctly, then I propose to save the current structure with the addition of new files:

image

It seems perfect, and leave open the possibility of whether in the future there are extras also for other packages to be able to add them.
Remember that for the base files of the framework (although I think we are not doing automatic searches for it) there are also keys that do not match regular expressions such as those corresponding to the new password rule.

@luisprmat, see my #1859 PR 😎

Reviewed and approved!