GithubHelp home page GithubHelp logo

Undefined offset: 1 about laravel-langman HOT 18 CLOSED

themsaid avatar themsaid commented on July 24, 2024
Undefined offset: 1

from laravel-langman.

Comments (18)

themsaid avatar themsaid commented on July 24, 2024

hmm maybe that's the reason, will look at it in 30 minutes and get back to you. Thanks for your feedback, it's quite useful :)

I'm trying to make the package cover all the cases and make language files management as easy as possible, because in the current large project I'm working on managing translations became a nightmare.

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

For instance, if I want to add a new language (italian for instance), I would basically create a new it subfolder, then run the sync command and that folder would be populated with the new translation files.

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

I just tested the case of having files existing in a language but not the other, running langman:missing actually creates a new file and asks you to fill the lines key by key.

Can you please share the structure of your language files? Or if possible can you do some debugging inside the MissingCommand and try to figure out where the problem is cause I can't replicate the issue here.

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

@vpratfr, still having the same troubles running the package?

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

Same problem after updating.

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

I really need to know the cause of the issue, cause I've used langman in 4 projects till now with complicated localisation structure and it seem to work. Can you please try to track the issue in Themsaid/Langman/Command/MissingCommand.php?

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

I'll try to, but I won't have time to do that until at least 1 or 2 weeks.

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

No worries, I'm going to close the issue for now then. Please feel free to open a ticket if the issue with more details by the time you check it out. Hopefully you catch the issue and open a PR :)

Thanks for your feedback.

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

Pretty strange way to proceed to close an issue which is still happening?!

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

It's just that we're unable to re-create the issue on different installation and you won't be able to provide further details so I thought to close it until somebody else reports. Anyway it's no opened again :)

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

Here is some more info about the Exception:

$ php artisan langman:sync -v
Reading translation keys from views...


  [ErrorException]
  Undefined offset: 1


Exception trace:
 () at vendor\themsaid\laravel-langman\src\Manager.php:64
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at vendor\themsaid\laravel-langman\src\Manager.php:64
 Themsaid\Langman\Manager->Themsaid\Langman\{closure}() at vendor\laravel\framework\src\Illuminate\Support\Collection.php:347
 Illuminate\Support\Collection->groupBy() at vendor\themsaid\laravel-langman\src\Manager.php:68
 Themsaid\Langman\Manager->files() at vendor\themsaid\laravel-langman\src\Commands\SyncCommand.php:53
 Themsaid\Langman\Commands\SyncCommand->handle() at n/a:n/a
 ...

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

This happens for a file within vendor. At line 63 I do a var_dump($file); and here is the output:

object(Symfony\Component\Finder\SplFileInfo)#873 (4) {
  ["relativePath":"Symfony\Component\Finder\SplFileInfo":private]=>
  string(20) "vendor\log-viewer\en"
  ["relativePathname":"Symfony\Component\Finder\SplFileInfo":private]=>
  string(32) "vendor\log-viewer\en\general.php"
  ["pathName":"SplFileInfo":private]=>
  string(69) "C:\Dev\sites\ikastola\resources\lang\vendor\log-viewer\en\general.php"
  ["fileName":"SplFileInfo":private]=>
  string(11) "general.php"
}

The exception is thrown because $matches is an empty array and you are trying to return $matches[1]

Here is what general.php looks like:

<?php

return [
    'all'  => 'All',
    'date' => 'Date',
];

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

A fix for that regex is to remove is and replace the if statement by that:

            if (Str::contains($file->getPath(), 'vendor')) {
                $fileName = basename($file->getRealPath());
                $vendorName = basename(dirname($file->getPath()));

                return "{$vendorName}::{$fileName}";
            } else {
                return $fileName;
            }

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

That last code seems to work (at least it runs, returns proper vendor::filename key), I did not check the messages which were output)

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

πŸ‘ can you open a PR for that fix?

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

I prefer to let you test it properly, I will not have time to do that before quite some time. I actually forced myself to spend a few minutes at least trying to find where the issue was to help you fix it.

I am running on Windows, that may be why your regex is not working.

The fix seems trivial, maybe mine is not proper as the function will return something like "log-viewer::general.php" (you may not want the .php ending in that return value)

from laravel-langman.

themsaid avatar themsaid commented on July 24, 2024

Alright no problem, I'll look into a fix and release a patch once I have a couple of minutes. Thank you :)

from laravel-langman.

vpratfr avatar vpratfr commented on July 24, 2024

No problem. Sorry I can't contribute more with code, I wish my days were 48 hours long.

from laravel-langman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.