Some better activity translations

This commit is contained in:
DaneEveritt 2022-06-18 16:36:19 -04:00
parent cf01490883
commit 76472411e3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 34 additions and 13 deletions

View file

@ -57,7 +57,16 @@ class LocaleController extends Controller
if (is_array($value)) {
$data[$key] = $this->i18n($value);
} else {
$data[$key] = preg_replace('/:([\w-]+)(\W?|$)/m', '{{$1}}$2', $value);
// Find a Laravel style translation replacement in the string and replace it with
// one that the front-end is able to use. This won't always be present, especially
// for complex strings or things where we'd never have a backend component anyways.
//
// For example:
// "Hello :name, the :notifications.0.title notification needs :count actions :foo.0.bar."
//
// Becomes:
// "Hello {{name}}, the {{notifications.0.title}} notification needs {{count}} actions {{foo.0.bar}}."
$data[$key] = preg_replace('/:([\w.-]+\w)([^\w:]?|$)/m', '{{$1}}$2', $value);
}
}

View file

@ -81,7 +81,7 @@ class ActivityLogTransformer extends BaseClientTransformer
}
$str = trans('activity.' . str_replace(':', '.', $model->event));
preg_match_all('/:(?<key>[\w-]+)(?:\W?|$)/', $str, $matches);
preg_match_all('/:(?<key>[\w.-]+\w)(?:[^\w:]?|$)/', $str, $matches);
$exclude = array_merge($matches['key'], ['ip', 'useragent']);
foreach ($model->properties->keys() as $key) {