martinlindhe / laravel-vue-i18n-generator

Generates a vue-i18n compatible include file from your Laravel translations
MIT License
306 stars 207 forks source link

Unexpected data while processing vue-i18n:generate #97

Open SDJeff opened 5 years ago

SDJeff commented 5 years ago

I have a Laravel 6 Porject with very easy Models. But the generation stops because of a model with:


   Exception  : Unexpected data while processing /home/vagrant/code/lukaeu-elearning/app/Question.php

  at /home/vagrant/code/lukaeu-elearning/vendor/martinlindhe/laravel-vue-i18n-generator/src/Generator.php:212
    208|
    209|                 $tmp = include($fileName);
    210|
    211|                 if (gettype($tmp) !== "array") {
  > 212|                     throw new Exception('Unexpected data while processing ' . $fileName);
    213|                     continue;
    214|                 }
    215|                 if ($lastLocale !== false) {
    216|                     $root = realpath(base_path() . $this->config['langPath'] . DIRECTORY_SEPARATOR . $lastLocale);

  Exception trace:

  1   MartinLindhe\VueInternationalizationGenerator\Generator::allocateLocaleArray("/home/vagrant/code/lukaeu-elearning/app")
      /home/vagrant/code/lukaeu-elearning/vendor/martinlindhe/laravel-vue-i18n-generator/src/Generator.php:80

  2   MartinLindhe\VueInternationalizationGenerator\Generator::generateFromPath("/home/vagrant/code/lukaeu-elearning", "es6")
      /home/vagrant/code/lukaeu-elearning/vendor/martinlindhe/laravel-vue-i18n-generator/src/Commands/GenerateInclude.php:67

  Please use the argument -v to see more details.``` 

Here is the model:

```<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{

    public function answers()
    {
        return $this->hasMany(Answer::class, 'question_id', 'id');
    }

    public function video()
    {
        return $this->belongsTo(Video::class, 'video_id', 'id');
    }
}

Why is stoping at a model when it points to 'resources/lang' folder?

martinlindhe commented 5 years ago

How does your vue-i18n:generate config look? Seems to me that you try to run it pointing to your app source folder rather than the language files from the backtrace you posted.

vue-i18n:generate should not be processing your models.

sidvanvliet commented 4 years ago

I am having the same issue and I am using the default configuration file (only switched vue-i18n to vuex-i18n), the config file contains:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Laravel translations path
    |--------------------------------------------------------------------------
    |
    | The default path where the translations are stored by Laravel.
    | Note: the path will be prepended to point to the App directory.
    |
    */

    'langPath' => '/resources/lang',

    /*
    |--------------------------------------------------------------------------
    | Laravel translation files
    |--------------------------------------------------------------------------
    |
    | You can choose which translation files to be generated.
    | Note: leave this empty for all the translation files to be generated.
    |
    */

    'langFiles' => [
        /*
        'pagination',
        'passwords'
        */
    ],

    /*
    |--------------------------------------------------------------------------
    | Excluded files & folders
    |--------------------------------------------------------------------------
    |
    | Exclude translation files, generic files or folders you don't need.
    |
    */
    'excludes' => [
        /*
        'validation',
        'example.file',
        'example-folder',
        */
    ],

    /*
    |--------------------------------------------------------------------------
    | Output file
    |--------------------------------------------------------------------------
    |
    | The javascript path where I will place the generated file.
    | Note: the path will be prepended to point to the App directory.
    |
    */
    'jsPath' => '/resources/js/langs/',
    'jsFile' => '/resources/js/vue-i18n-locales.generated.js',

    /*
    |--------------------------------------------------------------------------
    | i18n library
    |--------------------------------------------------------------------------
    |
    | Specify the library you use for localization.
    | Options are vue-i18n or vuex-i18n.
    |
    */
    'i18nLib' => 'vuex-i18n',

    /*
    |--------------------------------------------------------------------------
    | Output messages
    |--------------------------------------------------------------------------
    |
    | Specify if the library should show "written to" messages
    | after generating json files.
    |
    */
    'showOutputMessages' => false,

    /*
   |--------------------------------------------------------------------------
   | Escape character
   |--------------------------------------------------------------------------
   |
   | Allows to escape translations strings that should not be treated as a
   | variable
   |
   */
    'escape_char' => '!',
];
hungnd commented 4 years ago

I got the same issue, and I figured it out. This is NOT a bug. Btw, thank Martin for the plugin.

Root cause: config was not loaded into cache, thus, the Generator look up into the App folder.

Solution: just run php artisan config:cache then try again.