LarsWiegers / laravel-translations-checker

Never worry about missing translations again! Use the translations checker.
MIT License
231 stars 16 forks source link

Does not work with JSON (not in my case atleast) #27

Closed mariusberget92 closed 1 year ago

mariusberget92 commented 1 year ago

Location of translation file: lang/en.json Contents: 500+ lines. Small portion of the file:

{
  "Account|Accounts": "Account|Accounts",
  "Action|Actions": "Action|Actions",
  "Activity :activity": "Activity :activity",
  "Activity ID": "Activity ID",
  "Activity log": "Activity log",
  ...
}

Error:

The language en.json (E:\Laragon\www\lambda\lang/en.json) is missing the file ( en.json )
Missing the translation with key: en.json.en.Account|Accounts
Missing the translation with key: en.json.en.Action|Actions
Missing the translation with key: en.json.en.Activity :activity
Missing the translation with key: en.json.en.Activity ID
Missing the translation with key: en.json.en.Activity log

Translations for the application works fine though. Just wanted to check if I missed some translations anywhere.

jhm-ciberman commented 1 year ago

Same here. Laravel 9. Directory lang in root folder. All strings are present but the command shows as ALL strings were missing.

bgurney commented 1 year ago

+1: I am also experiencing the same issue on Laravel 9 inside a Docker container.

mariusberget92 commented 1 year ago

I am using Laravel 10 if that helps the dev.

LarsWiegers commented 1 year ago

Hey guys looking into this now!

LarsWiegers commented 1 year ago

So I have tried running the artisan command on a new laravel 10 project with the .json files as you can see in this repository: https://github.com/LarsWiegers/laravel-translation-checker-testing

Which works fine.

Can you guys compare your repository against this one and share the difference?

mariusberget92 commented 1 year ago

So I have tried running the artisan command on a new laravel 10 project with the .json files as you can see in this repository: https://github.com/LarsWiegers/laravel-translation-checker-testing

Which works fine.

Can you guys compare your repository against this one and share the difference?

I am using single .json file, not directory languages. Example: lang/en.json Not: lang/en/xxx.json

bgurney commented 1 year ago

Our lang directory (in the root of the project) looks like this. There are multiple .php files inside each folder and we use a non-standard en-gb locale name too.

da/ de/ en-gb/ es/ export/ fr/ import/ it/ ni/ no/ pl/ da.ison de.ison en-gb.json es.ison fr.ison it.ison nl.ison no.json pl.json README.md

bgurney commented 1 year ago

This is a screenshot of the errors I get when running translations:check

Errors
LarsWiegers commented 1 year ago

Thanks guys, this will help a ton! working on it now 😄

LarsWiegers commented 1 year ago

Our lang directory (in the root of the project) looks like this. There are multiple .php files inside each folder and we use a non-standard en-gb locale name too.

da/ de/ en-gb/ es/ export/ fr/ import/ it/ ni/ no/ pl/ da.ison de.ison en-gb.json es.ison fr.ison it.ison nl.ison no.json pl.json README.md

@bgurney do you know if laravel actively supports the combination of the use of subdirectories with PHP / json files and top level json files?

Also I saw this in the documentation, maybe something to think about: https://laravel.com/docs/10.x/localization#defining-translation-strings:~:text=For%20languages%20that%20differ%20by%20territory%2C%20you%20should%20name%20the%20language%20directories%20according%20to%20the%20ISO%2015897.%20For%20example%2C%20%22en_GB%22%20should%20be%20used%20for%20British%20English%20rather%20than%20%22en%2Dgb%22.

LarsWiegers commented 1 year ago

I have added a pr for testing purposes. Can you pull this in your projects and see if it works composer require larswiegers/laravel-translations-checker:dev-json-files-instead-of-dirs

bgurney commented 1 year ago

@bgurney do you know if laravel actively supports the combination of the use of subdirectories with PHP / json files and top level json files?

Yeah Laravel and it's various starter packs use a combination of PHP and JSON styles.

Laravel Breeze, for example: PHP style JSON style

I've never seen JSON files being used in the sub-folders though and can't see any mention of this in the docs.

We also use the Laravel-Lang project, which provides boilerplate translations for a whole load of these things in both styles. So useful!

bgurney commented 1 year ago

I get the following error when I run translations:check now:

translations-check-error
mariusberget92 commented 1 year ago

Just tried it, and it kind of works I guess. Somewhat. I get this: Missing the translation with key: en.update the super admin.

Just did a recursive search to see where this is used and it's not used anywhere. I do use this line though: __('You cannot edit/update the super admin.')

So it looks like it fails with the slash. You're close though.

LarsWiegers commented 1 year ago

@mariusberget92 i have pushed new code that should fix your issue. @bgurney can you create a new issue as your situation is a little different.

Thanks guys!

mariusberget92 commented 1 year ago

Thanks!

dietergeerts commented 1 year ago

Hi, thanks for working on this! However, we are using a combination of both PHP and JSON files, as the PHP ones are those we manage, and the JSON are from external services we just import. When used together, I get that translations are missing like this:

Missing the translation with key: dev.uuid

While it's not missing. It seems that the following is happening:

So it seems that the first level of keys are like ignored, or something else is going on when looping all keys, maybe with recursive looping over them and sub-objects? Or maybe it's the combination of having PHP and JSON?