Skip to main content

PHP Laravel Import

Azbox supports Laravel PHP language files, the standard localization format for Laravel applications.

What are Laravel Language Files?

Laravel uses PHP arrays to store translations. Each file returns an array of key-value pairs:

lang/en/messages.php
<?php

return [
'welcome' => 'Welcome to our application!',
'goodbye' => 'Thanks for visiting!',
];

File Structure

Laravel organizes translations by language folder:

lang/
├── en/
│ ├── messages.php
│ ├── auth.php
│ └── validation.php
├── es/
│ ├── messages.php
│ ├── auth.php
│ └── validation.php
└── fr/
├── messages.php
├── auth.php
└── validation.php

Format Details

Simple Strings

messages.php
<?php

return [
'welcome' => 'Welcome!',
'goodbye' => 'Goodbye!',
'thanks' => 'Thank you!',
];

Nested Arrays

messages.php
<?php

return [
'user' => [
'greeting' => 'Hello, user!',
'farewell' => 'See you later!',
],
'system' => [
'error' => 'An error occurred',
'success' => 'Operation successful',
],
];

Azbox flattens these with dots:

  • user.greeting → "Hello, user!"
  • system.error → "An error occurred"

Placeholders

Laravel uses :placeholder syntax:

<?php

return [
'welcome' => 'Welcome, :name!',
'items' => 'You have :count items in your cart',
'order' => 'Order #:id has been :status',
];

Pluralization

Laravel uses | for plural forms:

<?php

return [
'apples' => 'There is one apple|There are many apples',
'items' => '{0} No items|{1} One item|[2,*] :count items',
];

Complete Example

English (lang/en/messages.php):

<?php

return [
'welcome' => 'Welcome to My App!',
'greeting' => 'Hello, :name!',

'auth' => [
'login' => 'Log In',
'logout' => 'Log Out',
'register' => 'Create Account',
'forgot' => 'Forgot Password?',
],

'nav' => [
'home' => 'Home',
'about' => 'About Us',
'contact' => 'Contact',
'settings' => 'Settings',
],

'actions' => [
'save' => 'Save',
'cancel' => 'Cancel',
'delete' => 'Delete',
'edit' => 'Edit',
],

'messages' => [
'success' => 'Operation completed successfully!',
'error' => 'Something went wrong. Please try again.',
'confirm' => 'Are you sure you want to continue?',
],

'items' => '{0} No items|{1} One item|[2,*] :count items',
];

Spanish (lang/es/messages.php):

<?php

return [
'welcome' => '¡Bienvenido a Mi App!',
'greeting' => '¡Hola, :name!',

'auth' => [
'login' => 'Iniciar Sesión',
'logout' => 'Cerrar Sesión',
'register' => 'Crear Cuenta',
'forgot' => '¿Olvidaste tu contraseña?',
],

'nav' => [
'home' => 'Inicio',
'about' => 'Nosotros',
'contact' => 'Contacto',
'settings' => 'Configuración',
],

'actions' => [
'save' => 'Guardar',
'cancel' => 'Cancelar',
'delete' => 'Eliminar',
'edit' => 'Editar',
],

'messages' => [
'success' => '¡Operación completada exitosamente!',
'error' => 'Algo salió mal. Por favor intenta de nuevo.',
'confirm' => '¿Estás seguro de que deseas continuar?',
],

'items' => '{0} Sin artículos|{1} Un artículo|[2,*] :count artículos',
];

How to Import in Azbox

Step 1: Open Import Dialog

Click Import in your project dashboard.

Step 2: Select Format

Choose PHP Laravel (.php) from the dropdown.

Step 3: Select Language

Pick the target language for the file.

Step 4: Import

Click Import and select your .php file.

Step 5: Review Results

Check the import summary.

What Gets Imported

ContentImportedNotes
Simple strings✅ YesDirect key-value
Nested arrays✅ YesFlattened with dots
Placeholders (:name)✅ YesPreserved as-is
Pluralization (|)✅ YesFull string preserved
PHP comments❌ NoIgnored
PHP logic/functions❌ NoNot supported

Key Flattening

Nested arrays become dot-notation keys:

// Input
return [
'user' => [
'profile' => [
'name' => 'Name',
],
],
];
// Result in Azbox
user.profile.name → "Name"

Usage in Laravel

In Blade Templates

{{-- Simple --}}
{{ __('messages.welcome') }}

{{-- With placeholder --}}
{{ __('messages.greeting', ['name' => $user->name]) }}

{{-- Pluralization --}}
{{ trans_choice('messages.items', $count, ['count' => $count]) }}

In PHP

// Simple
__('messages.welcome');

// With placeholder
__('messages.greeting', ['name' => $user->name]);

// From specific file
trans('auth.login');

In Controllers

return redirect()->back()->with('success', __('messages.success'));

Limitations

Azbox's PHP parser handles standard Laravel language files. Not supported:

  • PHP expressions or functions inside values
  • Concatenation in values
  • Variables in values
  • Double-quoted strings with variable interpolation
// ❌ Not supported
return [
'date' => now()->format('Y'), // Function call
'name' => $appName, // Variable
'full' => 'Hello ' . $name, // Concatenation
'greeting' => "Hello {$name}", // Double-quote interpolation
];

// ✅ Supported
return [
'date' => ':year', // Placeholder instead
'name' => 'My App', // Static string
'greeting' => 'Hello, :name!', // Laravel placeholder
];

Best Practices

  1. One file per domainauth.php, messages.php, validation.php
  2. Consistent structure — Same keys across all languages
  3. Use placeholders:name instead of hardcoded values
  4. Group logically — Use nested arrays for organization
  5. Single quotes — Use 'string' not "string" for consistency

Project Structure

lang/
├── en/
│ ├── auth.php ← Import as English
│ ├── messages.php
│ ├── pagination.php
│ └── validation.php
├── es/
│ ├── auth.php ← Import as Spanish
│ ├── messages.php
│ ├── pagination.php
│ └── validation.php
└── fr/
├── auth.php ← Import as French
├── messages.php
├── pagination.php
└── validation.php

JSON Alternative

Laravel 5.4+ also supports JSON language files:

lang/es.json
{
"Welcome!": "¡Bienvenido!",
"Log In": "Iniciar Sesión"
}

For JSON files, use JSON Import instead.