Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/Clients/Enums/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::BILLING => 'Billing',
self::SHIPPING => 'Shipping',
self::OFFICE => 'Office',
self::BILLING => trans('enums.address_type.billing'),
self::SHIPPING => trans('enums.address_type.shipping'),
self::OFFICE => trans('enums.address_type.office'),
};
}

Expand Down
12 changes: 6 additions & 6 deletions Modules/Clients/Enums/CommunicationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static function ccTypes(): array
public function label(): string
{
return match ($this) {
self::EMAIL => 'Email',
self::PHONE => 'Phone',
self::FAX => 'Fax',
self::MOBILE => 'Mobile',
self::WHATSAPP => 'Whatsapp',
self::INVOICE_CC => 'Invoice CC Email',
self::EMAIL => trans('enums.communication_type.email'),
self::PHONE => trans('enums.communication_type.phone'),
self::FAX => trans('enums.communication_type.fax'),
self::MOBILE => trans('enums.communication_type.mobile'),
self::WHATSAPP => trans('enums.communication_type.whatsapp'),
self::INVOICE_CC => trans('enums.communication_type.invoice_cc'),
};
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Clients/Enums/RelationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function label(): string
self::CUSTOMER => trans('ip.customer'),
self::VENDOR => trans('ip.vendor'),
self::PROSPECT => trans('ip.prospect'),
self::PARTNER => 'Partner',
self::LEAD => 'Lead',
self::PARTNER => trans('enums.relation_type.partner'),
self::LEAD => trans('enums.relation_type.lead'),
};
}

Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Enums/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::BILLING => 'Billing',
self::SHIPPING => 'Shipping',
self::OFFICE => 'Office',
self::BILLING => trans('enums.address_type.billing'),
self::SHIPPING => trans('enums.address_type.shipping'),
self::OFFICE => trans('enums.address_type.office'),
};
}

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Enums/CommunicationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::EMAIL => 'Email',
self::PHONE => 'Phone',
self::FAX => 'Fax',
self::MOBILE => 'Mobile',
self::WHATSAPP => 'Whatsapp',
self::EMAIL => trans('enums.communication_type.email'),
self::PHONE => trans('enums.communication_type.phone'),
self::FAX => trans('enums.communication_type.fax'),
self::MOBILE => trans('enums.communication_type.mobile'),
self::WHATSAPP => trans('enums.communication_type.whatsapp'),
};
}

Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Enums/CustomFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::TEXT => 'Single Line Text',
self::NUMBER => 'Multi Line Text',
self::DATE => 'Date Picker',
self::BOOLEAN => 'Boolean',
self::TEXT => trans('enums.custom_field_type.text'),
self::NUMBER => trans('enums.custom_field_type.number'),
self::DATE => trans('enums.custom_field_type.date'),
self::BOOLEAN => trans('enums.custom_field_type.boolean'),
};
}

Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Enums/EmailTemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::TEXT => 'Single Line Text',
self::NUMBER => 'Multi Line Text',
self::DATE => 'Date Picker',
self::BOOLEAN => 'Boolean',
self::TEXT => trans('enums.email_template_type.text'),
self::NUMBER => trans('enums.email_template_type.number'),
self::DATE => trans('enums.email_template_type.date'),
self::BOOLEAN => trans('enums.email_template_type.boolean'),
};
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Enums/MailType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::REMINDER => 'Reminder',
self::SENT => 'Sent',
self::REMINDER => trans('enums.mail_type.reminder'),
self::SENT => trans('enums.mail_type.sent'),
};
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Enums/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ enum Permission: string implements LabeledEnum

public function label(): string
{
return str($this->value)->replace('-', ' ')->title()->toString();
return trans('permissions.' . $this->value);
}

public function color(): string
Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Enums/ReportBand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ enum ReportBand: string
public function getLabel(): string
{
return match ($this) {
self::HEADER => 'Header',
self::GROUP_HEADER => 'Group Header',
self::DETAILS => 'Details',
self::GROUP_FOOTER => 'Group Footer',
self::FOOTER => 'Footer',
self::HEADER => trans('enums.report_band.header'),
self::GROUP_HEADER => trans('enums.report_band.group_header'),
self::DETAILS => trans('enums.report_band.details'),
self::GROUP_FOOTER => trans('enums.report_band.group_footer'),
self::FOOTER => trans('enums.report_band.footer'),
};
}

Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Enums/TaxRateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::EXCLUSIVE => 'Exclusive',
self::INCLUSIVE => 'Inclusive',
self::ZERO => 'Zero',
self::EXEMPT => 'Exempt',
self::EXCLUSIVE => trans('enums.tax_rate_type.exclusive'),
self::INCLUSIVE => trans('enums.tax_rate_type.inclusive'),
self::ZERO => trans('enums.tax_rate_type.zero'),
self::EXEMPT => trans('enums.tax_rate_type.exempt'),
};
}

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Enums/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static function nonAdmin(): array
public function label(): string
{
return match ($this) {
self::SUPER_ADMIN => 'Super Admin',
self::ADMIN => 'admin',
self::ASSIST => 'assist',
self::CUSTOMER_ADMIN => 'Client Admin',
self::CUSTOMER => 'client',
self::SUPER_ADMIN => trans('enums.user_role.super_admin'),
self::ADMIN => trans('enums.user_role.admin'),
self::ASSIST => trans('enums.user_role.assist'),
self::CUSTOMER_ADMIN => trans('enums.user_role.customer_admin'),
self::CUSTOMER => trans('enums.user_role.customer'),
};
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Enums/UserType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ enum UserType: int
public function getLabel(): string
{
return match($this) {
self::ADMIN => 'ip.administrator',
self::CLIENT => 'ip.client',
self::ADMIN => trans('enums.user_type.admin'),
self::CLIENT => trans('enums.user_type.client'),
};
}

Expand Down
58 changes: 58 additions & 0 deletions Modules/Core/Tests/Feature/EnumLocalizationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Modules\Core\Tests\Feature;

use Modules\Core\Enums\Permission;
use Modules\Core\Enums\ReportBand;
use Modules\Core\Tests\AbstractTestCase;
use Modules\Expenses\Enums\ExpenseStatus;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;

#[Group('smoke')]
class EnumLocalizationTest extends AbstractTestCase
{
#[Test]
public function it_resolves_enum_labels_in_the_current_locale_without_changing_storage_values(): void
{
/* Arrange */
app('translator')->addLines(['enums.expense_status.draft' => 'Entwurf Test', 'enums.report_band.header' => 'Kopf Test'], 'de');
app()->setLocale('en');
$value = ExpenseStatus::DRAFT->value;

/* Act */
$englishLabel = ExpenseStatus::DRAFT->label();
app()->setLocale('de');
$germanLabel = ExpenseStatus::DRAFT->label();
$headerLabel = ReportBand::HEADER->getLabel();
$germanValue = ExpenseStatus::DRAFT->value;
app()->setLocale('en');
$restoredEnglishLabel = ExpenseStatus::DRAFT->label();

/* Assert */
$this->assertSame('Draft', $englishLabel);
$this->assertSame('Entwurf Test', $germanLabel);
$this->assertSame('Kopf Test', $headerLabel);
$this->assertSame($value, $germanValue);
$this->assertSame('Draft', $restoredEnglishLabel);
}

#[Test]
public function it_translates_permissions_without_changing_the_permission_identifiers(): void
{
/* Arrange */
app('translator')->addLines(['permissions.view-invoices' => 'Rechnungen anzeigen Test'], 'de');
app()->setLocale('en');

/* Act */
$englishLabel = Permission::VIEW_INVOICES->label();
app()->setLocale('de');
$germanLabel = Permission::VIEW_INVOICES->label();
$permissionIdentifier = Permission::VIEW_INVOICES->value;

/* Assert */
$this->assertSame('View Invoices', $englishLabel);
$this->assertSame('Rechnungen anzeigen Test', $germanLabel);
$this->assertSame('view-invoices', $permissionIdentifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<th class="text-left p-2 w-64">{{ trans('ip.permission') }}</th>
@foreach ($roles as $role)
<th class="text-center p-2 capitalize">
{{ str($role->name)->replace('_', ' ')->title() }}
{{ \Modules\Core\Enums\UserRole::tryFrom($role->name)?->label() ?? str($role->name)->replace('_', ' ')->title() }}
</th>
@endforeach
</tr>
Expand Down
12 changes: 6 additions & 6 deletions Modules/Expenses/Enums/ExpenseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ enum ExpenseStatus: string implements LabeledEnum
public function label(): string
{
return match ($this) {
self::DRAFT => 'Draft',
self::SUBMITTED => 'Submitted',
self::APPROVED => 'Approved',
self::REIMBURSED => 'Reimbursed',
self::BILLED => 'Billed',
self::PAID => 'Paid',
self::DRAFT => trans('enums.expense_status.draft'),
self::SUBMITTED => trans('enums.expense_status.submitted'),
self::APPROVED => trans('enums.expense_status.approved'),
self::REIMBURSED => trans('enums.expense_status.reimbursed'),
self::BILLED => trans('enums.expense_status.billed'),
self::PAID => trans('enums.expense_status.paid'),
};
}

Expand Down
12 changes: 6 additions & 6 deletions Modules/Expenses/Enums/ExpenseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::ONE_TIME => 'One Time',
self::RECURRING => 'Recurring',
self::TRAVEL => 'Travel',
self::UTILITY => 'Utility',
self::MAINTENANCE => 'Maintenance',
self::FIXED => 'Fixed',
self::ONE_TIME => trans('enums.expense_type.one_time'),
self::RECURRING => trans('enums.expense_type.recurring'),
self::TRAVEL => trans('enums.expense_type.travel'),
self::UTILITY => trans('enums.expense_type.utility'),
self::MAINTENANCE => trans('enums.expense_type.maintenance'),
self::FIXED => trans('enums.expense_type.fixed'),
};
}

Expand Down
10 changes: 5 additions & 5 deletions Modules/Invoices/Enums/RecurringFrequency.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::DAILY => 'Daily',
self::WEEKLY => 'Weekly',
self::MONTHLY => 'Monthly',
self::YEARLY => 'Yearly',
self::QUARTERLY => 'Quarterly',
self::DAILY => trans('enums.recurring_frequency.daily'),
self::WEEKLY => trans('enums.recurring_frequency.weekly'),
self::MONTHLY => trans('enums.recurring_frequency.monthly'),
self::YEARLY => trans('enums.recurring_frequency.yearly'),
self::QUARTERLY => trans('enums.recurring_frequency.quarterly'),
};
}

Expand Down
10 changes: 5 additions & 5 deletions Modules/Payments/Enums/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::COMPLETED => 'Completed',
self::FAILED => 'ip.failed',
self::PENDING => 'Pending',
self::REFUNDED => 'Refunded',
self::REFUNDED_PARTIALLY => 'ip.partially_refunded',
self::COMPLETED => trans('enums.payment_status.completed'),
self::FAILED => trans('enums.payment_status.failed'),
self::PENDING => trans('enums.payment_status.pending'),
self::REFUNDED => trans('enums.payment_status.refunded'),
self::REFUNDED_PARTIALLY => trans('enums.payment_status.refunded_partially'),
};
}

Expand Down
10 changes: 5 additions & 5 deletions Modules/Projects/Enums/ProjectStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public static function values(): array
public function label(): string
{
return match ($this) {
self::ON_HOLD => 'On Hold',
self::COMPLETED => 'Completed',
self::PLANNED => 'Planned',
self::ACTIVE => 'Active',
self::CANCELLED => 'Cancelled',
self::ON_HOLD => trans('enums.project_status.on_hold'),
self::COMPLETED => trans('enums.project_status.completed'),
self::PLANNED => trans('enums.project_status.planned'),
self::ACTIVE => trans('enums.project_status.active'),
self::CANCELLED => trans('enums.project_status.cancelled'),
};
}

Expand Down
Loading
Loading