Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tanmuhittin\LaravelGoogleTranslate\Api\StichozaApiTranslate::translate(): Return value must be of type string, null returned #69

Open
cawecoy opened this issue Jan 4, 2024 · 2 comments

Comments

@cawecoy
Copy link

cawecoy commented Jan 4, 2024

HI, great package, thanks for the awesome work!

I am trying to translate whitecube/laravel-cookie-consent lang files, but I've got the error:

Tanmuhittin\LaravelGoogleTranslate\Api\StichozaApiTranslate::translate(): Return value must be of type string, null returned

I need these languages: pl,cs,de,en,fr,it,nl. The main language is pl (Polish).

The whitecube/laravel-cookie-consent package already have translations for de,en,fr,it,nl and I already have the pl translations. Also, I've added a few new lines to the package's Polish language file. Then I need to translate these new Polish lines to all the other languages, and I need to add cs and it to the whitecube/laravel-cookie-consent package language files.

lang\vendor\cookieConsent\pl\cookies.php:

<?php
return [
    'title' => 'Szanujemy Twoją prywatność',
    'intro' => 'Razem z naszymi partnerami przechowujemy na urządzeniu informacje, takie jak pliki cookie, i uzyskujemy do nich dostęp, a także przetwarzamy dane osobowe, takie jak niepowtarzalne identyfikatory i standardowe informacje wysyłane przez urządzenie, w celu zapewnienia statystyk, personalizacji i pomiaru treści oraz zbierania opinii, a także rozwijania i ulepszania produktów.',
    'link' => '<a href=":url">Polityka plików cookies</a>',
    
    'essentials' => 'Tylko niezbędne',
    'all' => 'Akceptuj wszystko',
    'customize' => 'Dostosuj',
    'manage' => 'Ustawienia',

    'details' => [
        'more' => 'Więcej szczegółów',
        'less' => 'Mniej szczegółów',
    ],
    'save' => 'Zapisz ustawienia',

    'categories' => [
        'essentials' => [
            'title' => 'Niezbędne ciasteczka i dane wewnętrzne',
            'description' => 'Są to dane i pliki cookies niezbędne do prawidłowego funkcjonowania strony oraz jej komponentów, bez których dostarczenie treści nie byłoby możliwe. Użycia tych danych i elementów nie można wyłaczyć.',
        ],
        'functional' => [
            'title' => 'Ciasteczka i dane funkcjonalne',
            'description' => 'Są to dane i pliki cookies, które pozwalają wygodniej korzystać z naszej strony internetowej lub umożliwiają korzystanie z niektórych funkcjonalności serwisu. Ich wyłączenie może spowodować niedostępność pewnych elementów strony.',
        ],
        'analytics' => [
            'title' => 'Ciasteczka i dane analityczne',
            'description' => '',
        ],
        'ads' => [
            'title' => 'Ciasteczka i dane reklamowe',
            'description' => '',
        ],
        'personalization' => [
            'title' => 'Ciasteczka i dane personalizacyjne',
            'description' => '',
        ],
    ],

    'defaults' => [
        'consent' => 'Używane do przechowywania preferencji użytkownika dotyczących zgody na pliki cookie.',
        'session' => 'Używany do identyfikacji sesji przeglądania użytkownika.',
        'csrf' => 'Używane do zabezpieczenia zarówno użytkownika, jak i naszej witryny internetowej przed atakami polegającymi na fałszowaniu żądań między witrynami.',
        '_ga' => 'Główny plik cookie używany przez Google Analytics, umożliwia usłudze odróżnienie jednego odwiedzającego od drugiego.',
        '_ga_ID' => 'Używany przez Google Analytics do utrzymywania stanu sesji.',
        '_gid' => 'Używany przez Google Analytics do identyfikacji użytkownika.',
        '_gat' => 'Używany przez Google Analytics do ograniczania liczby żądań.',
    ],

    // Custom lines added:
    'manage-title' => 'Ustawienia prywatności',
    'manage-intro' => 'Administrator może uzyskać dostęp do informacji i wykorzystywać je w celach wskazanych poniżej. Możesz zmienić ustawienia według swoich preferencji lub kontynuować korzystanie z naszej strony, jeżeli nie masz zastrzeżeń.',
    'always-active' => 'Zawsze aktywne',
    'save-and-close' => 'Zapisz ustawienia i zamknij',
];

All data from the terminal:

php artisan translate:files

 What is base locale? [pl]:
 >

 What are the target locales? Comma seperate each lang key [cs,de,en,fr,it,nl]:
 >

 Force overwrite existing translations? [No]:
  [0] No
  [1] Yes
 >

 Verbose each translation? [Yes]:
  [0] No
  [1] Yes
 >

 Use text exploration and json translation or php files? [php]:
  [0] json
  [1] php
 >

 Are there specific target files to translate only? ex: file1,file2 []:
 > cookieConsent::cookies

 Are there specific files to exclude? [auth,pagination,validation,passwords]:
 >

 0/6 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
pl -> cs translating...
/var/www/html/lang/cs/cookieConsent::cookies.php is preparing
File already exists
Existing translations collected
Source text collected
Exists Skipping -> Szanujemy Twoją prywatność : We use cookies
Exists Skipping -> Razem z naszymi partnerami przechowujemy na urządzeniu informacje, takie jak pliki cookie, i uzyskujemy do nich dostęp, a także przetwarzamy dane osobowe, takie jak niepowtarzalne identyfikatory i standardowe informacje wysyłane przez urządzenie, w celu zapewnienia statystyk, personalizacji i pomiaru treści oraz zbierania opinii, a także rozwijania i ulepszania produktów. : This website uses cookies in order to enhance the overall user experience.
Exists Skipping -> <a href=":url">Polityka plików cookies</a> : Take a look at our <a href=":url">Cookies Policy</a> for more information.
Exists Skipping -> Tylko niezbędne : Only essentials
Exists Skipping -> Akceptuj wszystko : Accept all
Exists Skipping -> Dostosuj : Customize
Exists Skipping -> Ustawienia : Manage cookies
Ustawienia prywatności : Nastavení ochrany osobních údajů
Administrator może uzyskać dostęp do informacji i wykorzystywać je w celach wskazanych poniżej. Możesz zmienić ustawienia według swoich preferencji lub kontynuować korzystanie z naszej strony, jeżeli nie masz zastrzeżeń. : Správce může přistupovat k informacím a používat je pro účely uvedené níže. Můžete změnit nastavení podle svých preferencí nebo pokračovat v používání našich webových stránek, pokud nemáte žádné námitky.
Zawsze aktywne : Vždy aktivní
Zapisz ustawienia i zamknij : Uložte nastavení a zavřete
Exists Skipping -> Więcej szczegółów : More details
Exists Skipping -> Mniej szczegółów : Less details
Exists Skipping -> Zapisz ustawienia : Save settings
Exists Skipping -> Niezbędne ciasteczka i dane wewnętrzne : Essential cookies
Exists Skipping -> Są to dane i pliki cookies niezbędne do prawidłowego funkcjonowania strony oraz jej komponentów, bez których dostarczenie treści nie byłoby możliwe. Użycia tych danych i elementów nie można wyłaczyć. : There are some cookies that we have to include in order for certain web pages to function. For this reason, they do not require your consent.
Ciasteczka i dane funkcjonalne : Soubory cookie a funkční data
Są to dane i pliki cookies, które pozwalają wygodniej korzystać z naszej strony internetowej lub umożliwiają korzystanie z niektórych funkcjonalności serwisu. Ich wyłączenie może spowodować niedostępność pewnych elementów strony. : Jedná se o údaje a soubory cookie, které vám umožňují pohodlnější používání našich webových stránek nebo vám umožňují využívat některé funkce webových stránek. Jejich deaktivace může mít za následek nedostupnost určitých prvků webových stránek.
Exists Skipping -> Ciasteczka i dane analityczne : Analytics cookies
Exists Skipping ->  : We use these for internal research on how we can improve the service we provide for all our users. These cookies assess how you interact with our website.
Ciasteczka i dane reklamowe : Soubory cookie a reklamní údaje

   TypeError

  Tanmuhittin\LaravelGoogleTranslate\Api\StichozaApiTranslate::translate(): Return value must be of type string, null returned

  at vendor/tanmuhittin/laravel-google-translate/src/Api/StichozaApiTranslate.php:30
     26▕         else
     27▕             $this->handle->setSource($base_locale);
     28▕         $this->handle->setTarget($locale);
     29▕         try {
  ➜  30▕             return $this->handle->translate($text);
     31▕         } catch (\ErrorException $e) {
     32▕             return false;
     33▕         }
     34▕     }

      +20 vendor frames

  21  artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

How can I solve this issue?

@cawecoy
Copy link
Author

cawecoy commented Jan 4, 2024

It actually translated the files, but it added the translations to lang\cs\cookieConsentcookies.php, lang\de\cookieConsentcookies.php, and so on.

It should've added translations to lang\vendor\cookieConsent\cs\cookies.php, lang\vendor\cookieConsent\de\cookies.php and so on.

So the real issue is that the outupt file is saved on the wrong directory and has a buggy filename when translating vendor package's language files.

@pekka
Copy link

pekka commented Mar 24, 2024

I can't comment on the location of the translation files, but re your first problem - I had the same issue and it seems to happen when translation strings in the original file are empty! It doesn't check for that. Just remove those translations or give them a value.

eg

"heading_disclaimer" => "", <--- throws error

make it

"heading_disclaimer" => "This is a disclaimer!",

or remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants