PHP code example of beliven-it / laravel-i18n
1. Go to this page and download the library: Download beliven-it/laravel-i18n library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beliven-it / laravel-i18n example snippets
__('messages.welcome') // → lang/en/messages.php
__('clinic/detail.title') // → lang/en/clinic/detail.php
__('Welcome') // → lang/en.json
__('My Translation') // → lang/en.json
use Beliven\I18n\Services\TranslationScanner;
use Beliven\I18n\Services\TranslationFileManager;
$scanner = app(TranslationScanner::class);
$fileManager = app(TranslationFileManager::class);
// Scan for translation keys
$foundKeys = $scanner->scan(['app', 'resources']);
// Parse a key to determine its type
$parsed = $scanner->parseKey('messages.welcome');
// Returns: ['type' => 'php', 'file' => 'messages', 'key' => 'welcome']
$parsed = $scanner->parseKey('Welcome');
// Returns: ['type' => 'json', 'file' => null, 'key' => 'Welcome']
use Beliven\I18n\Services\TranslationFileManager;
$manager = app(TranslationFileManager::class);
// PHP files
$manager->addKey('en', 'messages', 'welcome', 'Welcome!');
$translations = $manager->loadFile('en', 'messages');
// JSON files
$manager->addJsonKey('en', 'Welcome', 'Welcome!');
$jsonTranslations = $manager->loadJsonFile('en');
use Beliven\I18n\Services\TranslationExporter;
$exporter = app(TranslationExporter::class);
$result = $exporter->export('/path/to/output.xlsx');
// Returns:
// [
// 'locales' => 3,
// 'rows' => 150,
// 'file' => '/path/to/output.xlsx'
// ]
use Beliven\I18n\Services\TranslationImporter;
$importer = app(TranslationImporter::class);
// Merge mode
$stats = $importer->import('/path/to/input.xlsx', false);
// Overwrite mode
$stats = $importer->import('/path/to/input.xlsx', true);
// Returns:
// [
// 'files_created' => 2,
// 'keys_added' => 25,
// 'keys_updated' => 10
// ]
echo __('Welcome'); // Simple string
echo __('messages.greeting', ['name' => $user->name]); // Structured
Scanning for translation keys...
✓ Created en/messages.php -> welcome
+ Added en/clinic.php -> detail.title
Scan complete!
┌────────────────────────┬───────┐
│ Metric │ Count │
├────────────────────────┼───────┤
│ Total keys found │ 45 │
│ Files created │ 2 │
│ Keys added │ 12 │
│ Keys already existing │ 33 │
└────────────────────────┴───────┘
bash
php artisan i18n:manage scan
bash
php artisan i18n:manage export --output=translations.xlsx