Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mariusberget92 opened this issue Mar 11, 2023 · 17 comments · Fixed by #29
Closed

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

mariusberget92 opened this issue Mar 11, 2023 · 17 comments · Fixed by #29
Assignees

Comments

@mariusberget92
Copy link

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
Copy link

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

@bgurney
Copy link

bgurney commented Mar 16, 2023

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

@mariusberget92
Copy link
Author

I am using Laravel 10 if that helps the dev.

@LarsWiegers
Copy link
Owner

Hey guys looking into this now!

@LarsWiegers LarsWiegers self-assigned this Mar 23, 2023
@LarsWiegers
Copy link
Owner

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
Copy link
Author

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
Copy link

bgurney commented Mar 23, 2023

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
Copy link

bgurney commented Mar 23, 2023

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

Errors

@LarsWiegers
Copy link
Owner

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

@LarsWiegers
Copy link
Owner

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 LarsWiegers linked a pull request Mar 23, 2023 that will close this issue
@LarsWiegers
Copy link
Owner

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
Copy link

bgurney commented Mar 23, 2023

@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
Copy link

bgurney commented Mar 23, 2023

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

translations-check-error

@mariusberget92
Copy link
Author

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
Copy link
Owner

@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
Copy link
Author

Thanks!

@dietergeerts
Copy link

dietergeerts commented Jun 2, 2023

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:

  • lang/dev/validation.php contains uuid key
  • lang/en.json contains validation.uuid key (as sub-key, as we use sub-objects for better key management)

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?

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 a pull request may close this issue.

5 participants