<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simonecerruti / laravel-translation-audit example snippets
'translation_calls' => [
't', // t('messages.welcome')
'App\Support\t', // a namespaced function
App\Support\Translator::class.'::translate', // Translator::translate('messages.welcome')
'Illuminate\Support\Facades\Lang::customTranslate', // a macro on the Lang facade
'trans_for' => 1, // trans_for($locale, 'messages.welcome')
],
'dynamic_keys' => [
'payments.*' => PaymentMethod::class, // the values of the enum cases
'status.*.label' => ['active', 'suspended'],
],
trait HasLabel
{
public function label(): string
{
return __('orders.status.'.str($this->value)->replace('_', '-'));
}
}
use TranslationAudit\Contracts\TranslationKeyResolver;
class OrderStatusLabelKeys implements TranslationKeyResolver
{
public function resolve(): iterable
{
foreach (OrderStatus::cases() as $case) {
yield 'orders.status.'.str($case->value)->replace('_', '-');
}
}
public function covers(): array
{
return ['app/Enums/Concerns/HasLabel.php' => 'orders.status.*'];
}
}
use TranslationAudit\Console\Commands\AuditCommand;
use TranslationAudit\Results\Contracts\Result;
class NotifyTeam
{
public function before(AuditCommand $command): void
{
// ...
}
public function after(Result $result, Slack $slack): void
{
if (! $result->isClean()) {
$slack->send('Some translations need attention.');
}
}
}
use TranslationAudit\Console\Commands\AuditTranslations;
use TranslationAudit\Console\Commands\PurgeUnusedTranslations;
'hooks' => [
App\Translations\PullTranslations::class, // every command
App\Translations\NotifyTeam::class => AuditTranslations::class, // only translation:audit
App\Translations\CommitLangFiles::class => [PurgeUnusedTranslations::class],
],
'additional_keys' => [
'messages.welcome',
'payments.*', // audited as a dynamic key
],
'ignore_keys' => [
'Hello', // ignored for every locale
'Hi' => ['en'], // ignored only for English
'payments.*', // a dynamic key, like __("payments.{$method}"), ignored by its pattern
],
text
app/Http/Controllers/Auth/LoginController.php
IT auth.failed
EN, IT Welcome back! Please sign in to continue with your
account.
resources/views/welcome.blade.php
IT messages.welcome
Found 3 keys with missing translations in 2 files.