Automatic Locale Labels
Hewcode automatically resolves column labels from your application's translation files when no explicit label is provided. This enables consistent labeling, reduces repetition, and makes internationalization effortless.
By default, the package looks for the app.php translation file in your locale directories.
Setup
Without automatic labels, you repeat yourself constantly:
TextColumn::make('id')->label('Post ID'),
TextColumn::make('title')->label('Article Title'),
TextColumn::make('content')->label('Article Content'),
TextColumn::make('status')->label('Publication Status'),
TextColumn::make('category.name')->label('Category Name'),With automatic labels, you set up translations once and they apply everywhere:
// Translation file (lang/en/app.php)
'posts' => [
'columns' => [
'id' => 'Post ID',
'title' => 'Article Title',
'content' => 'Article Content',
'status' => 'Publication Status',
],
],
// In your listings - labels are automatic!
TextColumn::make('id'),
TextColumn::make('title'),
TextColumn::make('content'),
TextColumn::make('status'),Benefits:
- Consistency across all listings using the same column
- Easy internationalization—just add more language files
- Less code repetition
- Centralized label management
Translation Key Patterns
Regular Columns
For standard model columns, the translation key follows this pattern:
app.{plural_model_name}.columns.{column_name}Examples:
Postmodel,titlecolumn →app.posts.columns.titleUsermodel,emailcolumn →app.users.columns.emailCategorymodel,descriptioncolumn →app.categories.columns.description
Relationship Columns
For relationship columns (containing dot notation), the system intelligently resolves to the related model:
app.{related_model_plural}.columns.{column_name}Examples:
category.name→app.categories.columns.nameuser.email→app.users.columns.emailpost.category.parent.name→app.categories.columns.name
Setting Up Translation Files
Directory Structure
Place your translation files in the standard Laravel locations:
lang/
├── en/
│ └── app.php
├── es/
│ └── app.php
└── fr/
└── app.phpTranslation File Format
Create an app.php file for each locale:
<?php
// lang/en/app.php
return [
'posts' => [
'columns' => [
'id' => 'Post ID',
'title' => 'Article Title',
'content' => 'Article Content',
'status' => 'Publication Status',
'published_at' => 'Publication Date',
'created_at' => 'Creation Date',
'updated_at' => 'Last Modified',
],
],
'categories' => [
'columns' => [
'id' => 'Category ID',
'name' => 'Category Name',
'slug' => 'URL Slug',
'description' => 'Category Description',
'color' => 'Display Color',
'created_at' => 'Creation Date',
],
],
'users' => [
'columns' => [
'id' => 'User ID',
'name' => 'Full Name',
'email' => 'Email Address',
'email_verified_at' => 'Email Verified',
'created_at' => 'Registration Date',
],
],
];Examples in Practice
Before (Manual Labels)
TextColumn::make('id')->label('Post ID'),
TextColumn::make('title')->label('Article Title'),
TextColumn::make('content')->label('Article Content'),
TextColumn::make('status')->label('Publication Status'),
TextColumn::make('category.name')->label('Category Name'),
TextColumn::make('user.name')->label('Author Name'),After (Automatic Labels)
// These will automatically resolve from locale files
TextColumn::make('id'), // → 'Post ID'
TextColumn::make('title'), // → 'Article Title'
TextColumn::make('content'), // → 'Article Content'
TextColumn::make('status'), // → 'Publication Status'
TextColumn::make('category.name'), // → 'Category Name' (from categories translations)
TextColumn::make('user.name'), // → 'Full Name' (from users translations)
// Explicit labels still override automatic ones
TextColumn::make('published_at')->label('Custom Published Date'),Fallback Behavior
If no translation is found, the system falls back to the original behavior—creating a readable label from the column name:
Examples:
- Dot notation columns:
category.name→"Category Name" - Regular columns:
created_at→"Created At" - Snake case:
user_email→"User Email"
This means automatic labels are completely non-breaking. Your existing columns will work exactly as before, but now you have the option to centralize and internationalize them.