Skip to content

Support for translations in files in subfolders #314

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 10 additions & 6 deletions php-templates/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,21 @@ protected function fromJsonFile($file, $path, $namespace)

protected function fromPhpFile($file, $path, $namespace)
{
$key = pathinfo($file, PATHINFO_FILENAME);
$relativePath = str(realpath($file))
->after(realpath($path)) // Firstly remove the path to the /lang folder
->ltrim('/');

$lang = $relativePath->before('/')->toString();

$key = $relativePath
->after('/') // Remove the language folder for example /en, /pl etc.
->replace('.php', '') // Then remove the .php extension
->toString();

if ($namespace) {
$key = "{$namespace}::{$key}";
}

$lang = collect(explode(DIRECTORY_SEPARATOR, str_replace($path, "", $file)))
->filter()
->slice(-2, 1)
->first();

$relativePath = $this->getPathIndex($file);
$lines = $this->linesFromPhpFile($file);

Expand Down
16 changes: 10 additions & 6 deletions src/templates/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,21 @@ $translator = new class

protected function fromPhpFile($file, $path, $namespace)
{
$key = pathinfo($file, PATHINFO_FILENAME);
$relativePath = str(realpath($file))
->after(realpath($path)) // Firstly remove the path to the /lang folder
->ltrim('/');

$lang = $relativePath->before('/')->toString();

$key = $relativePath
->after('/') // Remove the language folder for example /en, /pl etc.
->replace('.php', '') // Then remove the .php extension
->toString();

if ($namespace) {
$key = "{$namespace}::{$key}";
}

$lang = collect(explode(DIRECTORY_SEPARATOR, str_replace($path, "", $file)))
->filter()
->slice(-2, 1)
->first();

$relativePath = $this->getPathIndex($file);
$lines = $this->linesFromPhpFile($file);

Expand Down