# Russian Language Translation Setup

This guide explains the translation system now set up in your OrderBuddy Portal application.

## What's Been Configured

1. **Language Files**: English (`en`) and Russian (`ru`) translation files
   - Located in: `resources/lang/en/messages.php` and `resources/lang/ru/messages.php`
   - Contains 50+ common UI strings and labels

2. **Language Switcher Component**: 
   - Located in: `resources/views/components/language-switcher.blade.php`
   - Integrated into the sidebar for easy access
   - Displays current language and allows switching between English and Russian

3. **Language Controller**:
   - Located in: `app/Http/Controllers/LanguageController.php`
   - Handles language switching and persistence

4. **SetLocale Middleware**:
   - Located in: `app/Http/Middleware/SetLocale.php`
   - Reads the language preference from session
   - Automatically applied to all web requests

## How to Use Translations

### In Blade Templates

Use the `__()` helper function:

```blade
<!-- Simple usage -->
<label>{{ __('messages.branch') }}</label>

<!-- Shorthand with @lang() -->
@lang('messages.branch')
```

### In PHP Code (Controllers, Models)

```php
use Illuminate\Support\Facades\Lang;

$label = __('messages.dashboard');
// or
$label = Lang::get('messages.dashboard');
```

## Adding New Translations

1. Edit `resources/lang/en/messages.php` to add the English version
2. Edit `resources/lang/ru/messages.php` to add the Russian translation
3. Use the new key in your templates: `{{ __('messages.your_new_key') }}`

Example:
```php
// In resources/lang/en/messages.php
'user_profile' => 'User Profile',

// In resources/lang/ru/messages.php
'user_profile' => 'Профиль пользователя',

// In your blade template
<h1>{{ __('messages.user_profile') }}</h1>
```

## Current Translations

### Navigation
- dashboard, reports, x_report, z_report, sales_report
- stock, profile, settings, customers, staff
- loyalty, cardmachine, live_orders

### Form Fields
- branch, from, to, all_branches
- email, password, remember_me

### Time Periods
- today, week, month, year, custom

### Buttons
- save, delete, edit, add, submit, cancel
- logout, login, register, forgot_password

### Messages
- welcome, success, error, warning, info, loading

### Misc
- analytics, scope, language, english, russian

## Setting Default Language

In `.env`:
```env
APP_LOCALE=ru
```

Or programmatically in a controller:
```php
app()->setLocale('ru');
session(['locale' => 'ru']);
```

## How It Works

1. **Initial Visit**: Uses `APP_LOCALE` from `.env` (defaults to 'en')
2. **Language Switcher**: Stores selected language in session
3. **Middleware**: Checks session on every request and applies saved locale
4. **Persistence**: Language choice persists until session expires or user clears cookies

## Tips

- Always use translation keys instead of hardcoding strings
- This makes the application easier to maintain
- You can easily add more languages by creating new directories:
  - `resources/lang/es/messages.php` for Spanish
  - `resources/lang/de/messages.php` for German
  - etc.

## Testing

To test translations:
1. Click the language icon in the sidebar (bottom-left)
2. Select your preferred language
3. The page should reload with translations applied
4. Language preference persists across pages

## File Locations

- Translation files: `resources/lang/{locale}/messages.php`
- Language switcher component: `resources/views/components/language-switcher.blade.php`
- Language controller: `app/Http/Controllers/LanguageController.php`
- SetLocale middleware: `app/Http/Middleware/SetLocale.php`
- Routes: `routes/web.php` (language.switch route)
- Bootstrap config: `bootstrap/app.php` (middleware registration)
