Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont load namespaced translations #27

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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