Skip to content

Commit

Permalink
Merge pull request #27 from Laravel-Backpack/dont-load-namespaced-tra…
Browse files Browse the repository at this point in the history
…nslations

dont load namespaced translations
  • Loading branch information
pxpm authored Dec 2, 2024
2 parents 5388082 + 58e6b76 commit 65484c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 0 additions & 4 deletions config/translation-manager.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

return [
// This will automatically load all translation paths registered by packages
// If you want to set the file paths manually, set this to false
'load_all_registered_translation_paths' => true,

// Paths from where the language files are loaded
// You can restrict the paths to a specific set
// It's only applied if load_all_registered_translation_paths is set to false
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Translation Manager provides a simple user interface to help you deal with translations in your Backpack application.
At a quick glance, some of the most relevant features are:

- View a list of all translations present in your application's language files (including vendor translations).
- View a list of all translations present in your application's language files.
- Edit translations directly from the interface.
- Search and filter translations for easy management.

Expand Down Expand Up @@ -71,7 +71,7 @@ php artisan vendor:publish --provider="Backpack\TranslationManager\AddonServiceP

![lm_list_view2](https://github.com/Laravel-Backpack/language-manager/assets/1032474/f65a24ea-473d-4fec-8ffc-b8137bcb1b9f)

The list view displays a comprehensive list of all translations within your application. By default, all translations including vendor translations are displayed in the list view. If you don't want to see vendor translations, you can set the config option `load_all_registered_translation_paths` to `false` in `config/backpack/translation-manager.php`.
The list view displays a comprehensive list of all translations within your application translation folder (usually `lang/`). Please do note that translations in `lang/vendor/xxx` folders are not possible to translate using this package.

Additionally, if you have [Backpack Pro](https://backpackforlaravel.com/products/pro-for-unlimited-projects) installed, your admin can also see and use the filters, to quickly narrow down translations.

Expand Down
13 changes: 7 additions & 6 deletions src/Models/TranslationLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ public function getRows(): array

$filePaths = config('backpack.translation-manager.file_paths', []);

if (config('backpack.translation-manager.load_all_registered_translation_paths', true)) {
$reflectionClass = new ReflectionClass(TranslationLoaderManager::class);
$hints = $reflectionClass->getProperty('hints')->getValue(app()['translation.loader']);
$filePaths = array_merge($filePaths, array_values($hints));
}

// file entries
collect($filePaths)
->flatMap(fn (string $path) => File::allFiles($path))
->filter(fn (SplFileInfo $file) => $file->getExtension() === 'php')
->each(function (SplFileInfo $file) use (&$entries) {

// per Laravel convention, namespaced translation files are located
// in `vendor/{$namespace}` directory do not load them
if(str_starts_with($file->getRelativePath(), 'vendor')) {
return;
}

$group = Str::beforeLast($file->getFilename(), '.php');
$locale = Str::of($file->getPath())->afterLast('/')->afterLast('\\')->value();

Expand Down

0 comments on commit 65484c8

Please sign in to comment.