amiranagram / localizator

Scan your Laravel project and generate language files ready to translate in language(s) of choosing.
Other
229 stars 29 forks source link

Quotes Being Stripped From "Integer" Keys in PHP Arrays #36

Closed falconsmilie closed 2 years ago

falconsmilie commented 2 years ago

Hi @musmanikram . Thanks for the great localization package.

For key based translations, when i have this;

'401' => [
        'title' => '401 - Unauthorized',
        'message' => 'Sorry, you are not authorized to view this page.',
    ],

and then run localize it is being converted to this;

401 => [
        'title' => '401 - Unauthorized',
        'message' => 'Sorry, you are not authorized to view this page.',
    ],

Changing string keys into integers causes issues for me with BabelEdit because it requires all keys be strings.

Not sure if it's just a side effect of the key conversion, but the indentation also gets messed up;

    'default' => [
        'title' => 'Error Response',
        'message' => 'Sorry, something went wrong. Please go to the start page.',
    ],
  404 => [
        'title' => '404 - Not Found',
        'message' => 'The requested page could not be found. Please go to the start page.',
    ],
  500 => [
        'title' => '500 - Internal Server Error',
        'message' => 'Please try again later.',
    ],
amiranagram commented 2 years ago

Hey, I'm the creator of this package, but @musmanikram is a contributor and I'm grateful for him 😅.

You're right the keys should not be integers in any case, I'll mark this as a bug.

Regarding the indentation I'm not sure, maybe the regex I'm using is messing it up. Are you using tabs or spaces? And how many?

falconsmilie commented 2 years ago

Sorry @amiranagram , my mistake. Thank you also for the package! :D

I am using 4 spaces for indentation.

falconsmilie commented 2 years ago

Sorry i should also mention i haven't noticed any other formatting errors when running localize. In fact your package cleans up a lot of rubbish introduced from BabelEdit.

amiranagram commented 2 years ago

You're welcome.

Sorry i should also mention i haven't noticed any other formatting errors when running localize. In fact your package cleans up a lot of rubbish introduced from BabelEdit.

That's great, thanks for info.

amiranagram commented 2 years ago

Hey @falconsmilie I gave it a look during the weekend and I didn't find a "clean" solution to keep the number strings as PHP evaluates them automatically as integers. Might have to do a regex after all 😬

In any case I'll have a patch ASAP

amiranagram commented 2 years ago

https://github.com/amiranagram/localizator/releases/tag/v0.9.1-alpha 🥳