Bottelet / translation-checker

find translations you forgot to add to your language files, check, and maintain translations in yor Laravel application
MIT License
101 stars 6 forks source link

An issue accured when no {lang}.json file provided #11

Open WatheqAlshowaiter opened 1 month ago

WatheqAlshowaiter commented 1 month ago

when no en.json file provided, the package will create en.php file translation which is not working.

the php language files not working until they are inside language folders.

the fix simply to create language json file if not exists.

// the place of the issue
    protected function getTargetLanguagePath(string $targetLanguage): string
    {
        $file = config('translator.language_folder') . "/{$targetLanguage}.json";
        if (!file_exists($file)) {
            $file = config('translator.language_folder') . "/{$targetLanguage}.php";
        }

        return $file;
    }

Secondly, I hope the package be able to add php files from config like msg.php which we can use php files for translation using this package, because we can use language ui like https://github.com/MohmmedAshraf/laravel-translations package, and the flexibility of nesting keys, etc

Bottelet commented 1 month ago

I definitely think just adding the en.php is wrong. I didn't realize it did that. I will look into it.

I shorty looked into making the package work with other file structures the main problem with it was the freedom to basically do anything, meaning I had to figure out the file structure / php structure.

__ ('some.deep.nested.text')

/ en 
   /some.php
   [
      'deep' => [
          'nested' => [
                 'text' => 'translation'
               ]
          ]
    ]
/ en 
   /some/deep/nested.php
   [
      'text' => 'translation'
   ]

Take the example above, both are valid, and there was a lot to keep track of so I stopped it, in search of a better solution.

I didn't know about @MohmmedAshraf laravel-translations. and definitely agree a good goal is that it's compatible.