unable to use class constants as translation keys
See original GitHub issueHi,
I’d like to use this loader to prepare language strings for vue, but I’m using BenSampo/laravel-enum package, and my translation arrays for enums looks like this:
<?php
use App\Enums\OfferStatus;
return [
OfferStatus::class => [
OfferStatus::New => 'new',
OfferStatus::Closed => 'closed',
],
];
laravel-translation-loader is unfortunately unable to parse such php file. I get the following error:
error in ./node_modules/@kirschbaum-development/laravel-translations-loader/all.js
Module build failed: Error: Unexpected PHP key: "staticlookup", details: {"kind":"staticlookup","loc":{"source":null,"start":{"line":3,"column":28,"offset":32},"end":{"line":3,"column":35,"offset":39}},"what":{"kind":"identifier","loc":{"source":null,"start":{"line":3,"column":4,"offset":8},"end":{"line":3,"column":28,"offset":32}},"resolution":"uqn","name":"OfferStatus"},"offset":{"kind":"constref","loc":{"source":null,"start":{"line":3,"column":30,"offset":34},"end":{"line":3,"column":35,"offset":39}},"name":"class"}}
...
would it be possible to implement lookup for class constants?
A workaround was to rewrite translation array like this:
<?php
return [
'App\Enums\OfferStatus' => [
1 => 'new',
2 => 'closed',
],
];
but that’s not very elegant…
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Developers - unable to use class constants as translation keys -
Hi,. I'd like to use this loader to prepare language strings for vue, but I'm using BenSampo/laravel-enum package, and my translation arrays for...
Read more >Translations for constants files in react - Stack Overflow
If you have translation file with key - value translation format you can use it. So you have constants file like this:
Read more >Using Enums for Translations keys : r/PHP - Reddit
Since Enums cannot be used as array keys, the same ideea could be done with a regular class with string constants
Read more >How to translate words in the component(.ts) file?? · Issue #835
At present I am using the translation in ".html" file. But, now I have to use the translation in "Component(.ts)" file as well....
Read more >Everything You Need to Know About Ruby Constants
Notice that you can't define constants inside a method. ... You can then access these constants inside the class methods or outside the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess a major functionality would have to be implemented into php-array-parser, I’ll just keep using a workaround for now, it gets the job done.
Yes, this is still a thing. To make this work we basically would have to run
php file.php
and process the result. It may not be so bad, but definitely introduces a few potential problems. I may look into this when I have some time, but feel free to send PRs for this. This would not need any updates on the php-array-parser side, it would be work done before that.