Code Monkey home page Code Monkey logo

Comments (4)

BenSampo avatar BenSampo commented on May 20, 2024

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.

MartinP7r avatar MartinP7r commented on May 20, 2024

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.

BenSampo avatar BenSampo commented on May 20, 2024

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:

  1. 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.

  1. Want to override the description for each language. Can be done using localisation: https://github.com/BenSampo/laravel-enum#localization

from laravel-enum.

MartinP7r avatar MartinP7r commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.