-
I am into Laravel for some time and still keep learning. One of my recent projects is a german page for local COVID information https://www.tioranat.info For these and other projects I had a lot of troubles checking the translations strings for the
During the development I face the following situations:
As I did not found a smart way of listening to the Illuminate/Translation/Translator.php
//
// the static storage of all translations per request
public static $log = [];
//
public function get( ....)
//
$translation = $this->makeReplacements($line ?: $key, $replace);
self::$log[] = [$translation, $line, $key, $replace];
return $translation; To use this data you just need this code in middleware, Artisan Commands or tests: foreach(app('translator')::$log as $entry){
[$translation, $line, $key, $replace] = $entry;
//
if($key === $translation){
// translation has not worked out
}
}
A test could be done like that: function testTranslationOK(){
$response = $this->get('/');
$response = $this->get('/legal');
$response = $this->get('/contact');
$response = $this->get('/blog');
$response = $this->get('/news');
foreach(app('translator')::$log as $entry){
[$translation, $line, $key, $replace] = $entry;
$this->assertNotEqual($translation, $key);
}
}
// with some more lines the static $log could be wrapped in a method
app('translator')::getLog(); What do you think, is this a feature Laravel developers would love? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Replying here because you pinged me with an email about Debugbar, but have you seen https://github.com/barryvdh/laravel-translation-manager#detect-missing-translations ? That replaces the Translator and logs them; https://github.com/barryvdh/laravel-translation-manager/blob/master/src/Translator.php |
Beta Was this translation helpful? Give feedback.
Replying here because you pinged me with an email about Debugbar, but have you seen https://github.com/barryvdh/laravel-translation-manager#detect-missing-translations ? That replaces the Translator and logs them; https://github.com/barryvdh/laravel-translation-manager/blob/master/src/Translator.php