Installation Add the bundle to your Symfony project via Composer:
composer require bcc/extra-tools-bundle
Register the bundle in config/bundles.php:
return [
// ...
MichelSalib\BCCExtraToolsBundle\BCCExtraToolsBundle::class => ['all' => true],
];
First Use Case: Translation Extraction Run the translation extractor to scan your project for missing translations:
php bin/console extra-tools:extract-translations
var/extra-tools/translations/.config/packages/bcc_extra_tools.yaml:
bcc_extra_tools:
extractor:
paths: ['%kernel.project_dir%/src', '%kernel.project_dir%/templates']
Locale-Specific Date Handling
Use the LocaleDateParser and LocaleDateFormatter services:
use MichelSalib\BCCExtraToolsBundle\Service\LocaleDateParser;
use MichelSalib\BCCExtraToolsBundle\Service\LocaleDateFormatter;
// Parse a date string (e.g., "12/03/2023" for fr_FR)
$parser = $this->container->get(LocaleDateParser::class);
$date = $parser->parse('12/03/2023', 'fr_FR');
// Format a date (e.g., for en_US)
$formatter = $this->container->get(LocaleDateFormatter::class);
$formatted = $formatter->format($date, 'en_US', 'Y-m-d');
Extract Missing Keys Integrate extraction into your CI/CD pipeline:
php bin/console extra-tools:extract-translations --env=prod
--format=json for API-friendly output.Merge with Existing Translations
Automate merging extracted keys into your translation files (e.g., .po/.xliff):
php bin/console extra-tools:merge-translations
Dynamic Translation Fallbacks
Use the TranslationExtractor service to validate keys at runtime:
$extractor = $this->container->get('bcc_extra_tools.extractor');
if (!$extractor->hasTranslation('domain', 'key')) {
// Log or handle missing translation
}
Contextual Date Parsing Parse user-uploaded dates dynamically:
$locale = $request->getLocale(); // e.g., 'de_DE'
$date = $parser->parse($request->get('date'), $locale);
Consistent Formatting Standardize date outputs across locales:
$formatted = $formatter->format($date, $locale, 'MMMM d, Y'); // e.g., "March 12, 2023"
Twig Integration Extend Twig with custom filters:
{{ date|format_date('fr_FR', 'd/m/Y') }}
Register in twig.config.yaml:
twig:
filters:
format_date: MichelSalib\BCCExtraToolsBundle\Twig\LocaleDateExtension
Currency/Measurement Conversions
Use the UnitConverter service:
$converter = $this->container->get('bcc_extra_tools.converter');
$converted = $converter->convert(100, 'USD', 'EUR'); // Uses current exchange rates
Custom Units Extend the converter for domain-specific units (e.g., "points" to "euros"):
# config/packages/bcc_extra_tools.yaml
bcc_extra_tools:
converter:
custom_units:
points_to_eur: 0.01
Pitfalls:
bcc_extra_tools:
extractor:
exclude_paths: ['%kernel.project_dir%/migrations']
--limit to scan specific files.Tips:
ExtractorInterface and overriding the service:
services:
app.extractor:
class: App\Service\CustomExtractor
decorates: 'bcc_extra_tools.extractor'
--dry-run to preview changes before merging.Pitfalls:
en_US vs. en_GB) parse MM/dd/yyyy differently. Specify formats explicitly:
$parser->parse('01/02/2023', 'en_US', 'm/d/Y'); // Avoid auto-detection
DateTimeZone for consistency:
$date->setTimezone(new DateTimeZone('Europe/Paris'));
Tips:
$cache = $this->container->get('cache.app');
$key = 'date_'.$locale.$format.serialize($date);
return $cache->get($key, fn() => $formatter->format($date, $locale, $format));
config/packages/bcc_extra_tools.yaml:
bcc_extra_tools:
locale:
default: 'en_US'
fallback: 'en'
Pitfalls:
php bin/console bcc_extra_tools:update-converter-data
points_to_eur) may introduce rounding errors. Use bcmath for financial data:
$converted = bcmul($value, '0.01', 2); // 2 decimal places
Tips:
services:
bcc_extra_tools.converter.data_provider:
class: App\Service\CustomDataProvider
arguments:
- '@http_client'
$converter->convertBatch([100, 200, 300], 'USD', 'EUR');
bcc_extra_tools.yaml after updates.php bin/console extra-tools:extract-translations -v
autoconfigure: true option in bundles.php for auto-wiring:
BCCExtraToolsBundle::class => ['all' => true, 'autoconfigure' => true],
How can I help you explore Laravel packages today?