diff --git a/php-templates/translations.php b/php-templates/translations.php index a7e7e55c..f04d0191 100644 --- a/php-templates/translations.php +++ b/php-templates/translations.php @@ -328,17 +328,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(DIRECTORY_SEPARATOR); + + $lang = $relativePath->before(DIRECTORY_SEPARATOR)->toString(); + + $key = $relativePath + ->after(DIRECTORY_SEPARATOR) // 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); diff --git a/src/templates/translations.ts b/src/templates/translations.ts index afda3bbc..72255a92 100644 --- a/src/templates/translations.ts +++ b/src/templates/translations.ts @@ -328,17 +328,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(DIRECTORY_SEPARATOR); + + $lang = $relativePath->before(DIRECTORY_SEPARATOR)->toString(); + + $key = $relativePath + ->after(DIRECTORY_SEPARATOR) // 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);