#Translating Enum values

5 messages · Page 1 of 1 (latest)

alpine briar
#

I am using enum in my laravel project like so:
<?php

namespace App\Enums;

enum ApplStatus: string
{
case NOT_SEND = 'Not Send'; // Antrag noch nicht eingereicht
case PENDING = 'Pending'; // Antrag liegt bei Eilinger zur Bearbeitung
case WAITING = 'Waiting'; //Antrag liegt wieder beim Benutzer zur Beantwortung der Fragen
case COMPLETE = 'Complete'; //Angaben im Antrag vollständig. Wartet auf nächste Stiftungsratssitzung
case APPROVED = 'Approved';
case BLOCKED = 'Blocked';
case FINISHED = 'Finished';
}

Can anybody tell me how I can translate them? Searched for hours and didn't found anything.

Thanks a lot

night rain
#

Not automatically, you'd have to write something yourself. Could be as simple as;

enum ApplStatus: string
{
  // cases

  public function translation()
  {
    return __($this->value);
  }
}
#

Translating Enum values

alpine briar
#

Thanks for your answer, but I still don't see how to use it exactly. So I then write something like APPSTATUS::Approved = 'Genehmigt' in the file, but how to distinguised between the languages. Sry if this is a stupid question but I don't get the dots together

night rain
#

That's not really how you'd use enums. Enums are set values, they do mapping. You're looking at them as regular strings, but they aren't really.
So instead of using actual text, you'd just use case PENDING = 'pending';, which is just used to check if something is that value
You can then use that value to derive it to something else, like you'd do $obj->status->translation(), which will return the translation of that enum value.