Comments (4)
Hi @MartinP7r, what you've described is exactly how the default implementation of the getDescription method works.
Take a look at:
https://github.com/BenSampo/laravel-enum/blob/master/src/Enum.php#L220-L225
from laravel-enum.
Sorry @BenSampo, I don't think I expressed my question clear enough (wasn't even a question, sorry for that. Not much sleep 😅)
https://github.com/BenSampo/laravel-enum#overriding-the-getdescription-method
When I implement customized getDescription
strings like in the example above, the method returns early, won't go to parent::getDescription()
where the implementation you referenced lies. Hence, when overriding the description strings, localization values for all overriden strings have to be supplied for all available languages (no fallback possible since parent::getDescription()
is not called).
Thinking about it, that's probably hard to work around, without implementing a different method for overriding getDescription
. So, I'll just supply all the string. Just thought this might be a problem in scenarios where there's a bunch of languages supported by the application and falling back on overridden description values would be preferrable.
from laravel-enum.
Ah in that case, apologies for being hasty in closing the issue, will re-open it.
I'm not 100% on the problem still. Can you let me know what you're trying to achieve? Any code examples would be useful.
The way I see it is that you either:
- Want to override the description for a specific enum value for all languages which you can do using this method: https://github.com/BenSampo/laravel-enum#overriding-the-getdescription-method
Any enum values not explicitly defined here will fallback to the default implementation of checking localisation files or subsequently generating a friendly name.
- Want to override the description for each language. Can be done using localisation: https://github.com/BenSampo/laravel-enum#localization
from laravel-enum.
Sorry for my late response.
And sorry for not being able to explain myself properly.
Going over all of it, leaving the implementation as-is would is probably best, since it's probably a minor thing but I try to give an explanation of what I was having problems with, below.
Essentially, you can only use localization if there is no overridden implementation of getDescription
.
BUT, if you have an application with e.g. 10 different languages, where the fallback is English
and the enum in question needs a customized description value that would use the fallback across all languages (e.g. your example "Super admin" instead of the enum-case SuperAdministrator
), then you would have to supply "Super admin" in every localization file for all 10 languages regardless.
This might be a strange way of looking at it. So I really don't mind closing this issue again if you feel like it makes little sense.
let me know if it's still unclear. Then I'll supply a concrete example.
from laravel-enum.
Related Issues (20)
- phpcs error with "enum" reserved keyword HOT 5
- Optional enum validaiton. HOT 1
- classDeclarationOffset unavailable when content removed with existing docblock HOT 6
- Support Laravel 10 HOT 1
- asSelectArray no return description localization HOT 2
- `enum:annotate` command breaks existing docblock descriptions
- add extra attributes HOT 2
- Adding extra Attributes HOT 4
- localization path HOT 1
- Calling translator in boot breaks translation loading HOT 3
- validateEnumValue does not exist HOT 9
- Add `$hidden` property to Enums HOT 1
- I am stepping down from feature development
- Enum returns incomparable instances HOT 1
- EnumServiceProvider breaks nova translations HOT 3
- Can't install on php8.3.1 HOT 4
- Installation problem HOT 2
- Dump phpunit/phpunit to v11 HOT 1
- Error when converting enums using the rector command HOT 1
- False positive when converting to native enums HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-enum.