barryvdh / laravel-translation-manager

Manage Laravel translation files
MIT License
1.64k stars 419 forks source link

Cannot import all files to database #431

Open ronrun opened 2 years ago

ronrun commented 2 years ago

I have lang files:

\lang
  en\
    ocadmin\
      common\
        column_left.php
      setting\
        setting.php
    auth.php
    pagination.php
    password.php
    validation.php
  zh-Hant\
    ocadmin\
      common\
        column_left.php
      setting\
        setting.php
    auth.php
    pagination.php
    password.php
    validation.php

php artisan translations:import

en language:
the root four files of language folder are in database, but none of all other files

zh-Hant:
Only "ocadmin/common/column_left" in database. The original four files auth.php... are missing, and setting/abc.php is missing.

So strange...

vendor\barryvdh\laravel-translation-manager\src\Manager.php

                if (! $vendor) { // line 96
                    $translations = \Lang::getLoader()->load($locale, $group);
                } else {
                    $translations = include $file;
                    $group = 'vendor/'.$vendorName;
                }

                if ($translations && is_array($translations)) { // line 103
                    foreach (Arr::dot($translations) as $key => $value) {
                        $importedTranslation = $this->importTranslation($key, $value, $locale, $group, $replace);
                        $counter += $importedTranslation ? 1 : 0;
                    }
                }
                // I add 3 lines. Why do I get emtpy $translations?
                else{ 
                    echo "<pre>", print_r($group, 1), "</pre>\r\n"; exit;
                }

Why do I get emtpy $translations?


I fixed.

vendor\barryvdh\laravel-translation-manager\src\Manager.php

    public function importTranslations($replace = false, $base = null, $import_group = false)
    {
        ...
                if ($subLangPath != $langPath) {
                    //$group = $subLangPath.'/'.$group;
                    $group = str_replace($langPath.'/', '', $subLangPath) . '/' . $group;
                }

langPath D:/Codes/PHP/laravel.test/httpdocs/lang/en

subLangPath D:/Codes/PHP/laravel.test/httpdocs/lang/en/lang/en/ocadmin/common

group (before $group = $subLangPath.'/'.$group;) column_left

group (after that line) D:/Codes/PHP/backgarden.chinabing.test/httpdocs/lang/en/ocadmin/common/column_left

What it need is 'ocadmin/commoncolumn_left'

So I write another line to handle it. It seems works!

For export

    public function exportTranslations($group = null, $json = false)
    {
        // $group = basename($group);
        // $basePath = $this->app['path.lang'];
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.