Skip to content

Conversation

@jbboehr
Copy link

@jbboehr jbboehr commented May 20, 2025

Contains:

  • Add an artisan test via orchestra/testbench
  • Also load translations from lang/*.json in findInArray
  • Do not error out if only lang/*.json exists in findInArray
  • Use Arr::dot() instead of Collection::dot() for Laravel 9 compatibility

Let me know if that all makes sense, I will test it a bit more on my codebase soon hopefully.

The commits should make sense individually, so could use the macro instead if that's preferable.

Closes #5

@jbboehr jbboehr changed the title Add artisan test, Laravel 9 compat for Collection::dot(), JSON file support Add artisan test, Laravel 9 compat for Collection::dot() May 20, 2025
->dot()
->keys()

$data = Collection::make($this->translator->get('*'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you let me know what this part does?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. $this->translator->get('*') loads the global (non-namespaced) translations in lang/{$baseLocale}.json.

I wonder if it might be better to use the found translations via scanning to build a list of groups/namespaces to load, that would support non-standard loaders.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the point of the lang/{lang}.json, that the key is already in the base language?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think there's anything technically preventing you from using a json file for the base locale, but it doesn't seem like it is very common.

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 this pull request may close these issues.

Collection::dot() missing in Laravel 9.x

2 participants