Skip to content

Commit

Permalink
Merge pull request #14981 from uberbrady/fix_backup_translations
Browse files Browse the repository at this point in the history
Fixed #14976, #14975, #14973 - Translation strings aren't always working
  • Loading branch information
snipe authored Jun 27, 2024
2 parents b6e8d28 + 6df9742 commit 7dbceda
Show file tree
Hide file tree
Showing 32 changed files with 122 additions and 1,306 deletions.
29 changes: 29 additions & 0 deletions app/Services/SnipeTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services;

use App\Helpers\Helper;
use Illuminate\Translation\Translator;

/***************************************************************
Expand All @@ -17,6 +18,10 @@
***************************************************************/
class SnipeTranslator extends Translator {

static $legacy_translation_namespaces = [
"backup::" //Spatie backup uses 'legacy' locale names
];

//This is copied-and-pasted (almost) verbatim from Illuminate\Translation\Translator
public function choice($key, $number, array $replace = [], $locale = null)
{
Expand All @@ -39,4 +44,28 @@ public function choice($key, $number, array $replace = [], $locale = null)
);
}

public function get($key, array $replace = [], $locale = null, $fallback = true)
{
$modified_locale = $locale;
$changed_fallback = false;
$previous_fallback = $this->fallback;
// 'legacy' translation directories tend to be two-char ('en'), not 5-char ('en-US').
// Here we try our best to handle that.
foreach (self::$legacy_translation_namespaces as $namespace) {
if (preg_match("/^$namespace/", $key)) {
$modified_locale = Helper::mapBackToLegacyLocale($locale);
$changed_fallback = true;
$this->fallback = 'en'; //TODO - should this be 'env-able'? Or do we just put our foot down and say 'en'?
break;
}
}

$result = parent::get($key, $replace, $modified_locale, $fallback);
if ($changed_fallback) {
$this->fallback = $previous_fallback;
}
return $result;
}


}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
|
*/

'fallback_locale' => env('FALLBACK_APP_LOCALE', 'en'),
'fallback_locale' => env('FALLBACK_APP_LOCALE', 'en-US'),

/*
|--------------------------------------------------------------------------
Expand Down
45 changes: 0 additions & 45 deletions resources/lang/vendor/backup/ar/notifications.php

This file was deleted.

45 changes: 0 additions & 45 deletions resources/lang/vendor/backup/bg/notifications.php

This file was deleted.

45 changes: 0 additions & 45 deletions resources/lang/vendor/backup/bn/notifications.php

This file was deleted.

45 changes: 0 additions & 45 deletions resources/lang/vendor/backup/cs/notifications.php

This file was deleted.

45 changes: 0 additions & 45 deletions resources/lang/vendor/backup/da/notifications.php

This file was deleted.

Loading

0 comments on commit 7dbceda

Please sign in to comment.