Coder Social home page Coder Social logo

nova-translations-loader's Introduction

Nova Translations Loader

Latest Version on Packagist Total Downloads

This Laravel Nova package helps developers load translations into their packages.

Requirements

  • php: >=8.0
  • laravel/framework: ^9.0|^10.0
  • laravel/nova: ^4.0

Installation

Install the package in a Laravel Nova project via Composer:

composer require outl1ne/nova-translations-loader

Usage

Inside a Laravel's ServiceProvider, use the LoadsNovaTranslations trait and call $this->loadTranslations():

use Outl1ne\NovaTranslationsLoader\LoadsNovaTranslations;

class SomePackagesServiceProvider extends ServiceProvider
{
    use LoadsNovaTranslations;

    public function boot()
    {
        // ...

        /**
         * Loads translations into the Nova system.
         *
         * @param string $packageTranslationsDir The directory for the packages' translation files.
         * @param string $packageName The name of the current package (ie 'nova-menu-builder').
         * @param boolean $publishTranslations Whether to also automatically make translations publishable.
         * @return null
         **/

        $this->loadTranslations(__DIR__ . '/../resources/lang', 'nova-package', true);

        // ...
    }
}

Credits

License

Nova Translations Loader is open-sourced software licensed under the MIT license.

nova-translations-loader's People

Contributors

luigel avatar ramonfeleus avatar stefvanesch avatar tarpsvo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nova-translations-loader's Issues

Call to undefined method getFallbackLocale

Hi,
I've just run composer update and found an error like below:
Do you know what could happened ?

"class": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError" "message": "Call to undefined method Illuminate\\Foundation\\Application::getFallbackLocale()", "file": "vendor/optimistdigital/nova-translations-loader/src/LoadsNovaTranslations.php:70", "vendor/optimistdigital/nova-translations-loader/src/LoadsNovaTranslations.php:45"

I have Laravel v 6.20

Wrong requirements - getFallbackLocale() undefined

When installing the package on laravel 7.19 i got the following error:

Call to undefined method Illuminate\Foundation\Application::getFallbackLocale()
OptimistDigital\MultiselectField\FieldServiceProvider::loadLaravelTranslations

Possible fixes:

Make getFallbackLocale() call optional
Did not have time to implement concrete fix.

Fix requirements:
specify laravel version based on the release notes:
https://github.com/laravel/framework/releases/tag/v7.21.0

https://github.com/optimistdigital/nova-translations-loader/blob/e19fd466c7afa68aab6300f8b6f834a35ed1c7bc/composer.json#L13
=> ^7.21.x || ^8.x

Translations work fine for the translated package, but stop working for the rest of Nova

In gldrenthe89/nova-string-generator-field I've used load translations as follows:
$this->loadTranslations(__DIR__ . '/../resources/lang', 'nova-string-generator-field', true);
The translations are located in resources/lang/ of that package.
In the Vue files translations are working fine.
However the rest of my Nova backend that had working translations (in dutch, 'nl', fallback 'en') for menu items, buttons, fields stopped being translated.
I've traced it back to the translations function of LoadsNovaTranslations.php of this package.
When I disable the line $this->loadLaravelTranslations($pckgTransDir, $pckgName); all translations are working, both the nova-string-generator-field vue component and the rest of my nova backend.
It also works when I move it to the bottom of the Nova::serving(function (ServingNova $event) use ($pckgTransDir, $pckgName) { line. But when it's before the if ($this->loadNovaTranslations lines it stops working.
Could you please check if moving $this->loadLaravelTranslations($pckgTransDir, $pckgName); to the bottom is the correct fix for this issue?

ErrorException array_merge(): Expected parameter 2 to be an array, null given

Failing here
/optimistdigital/nova-translations-loader/src/LoadsNovaTranslations.php:61:

 private function loadNovaTranslations($locale, $from, $packageTranslationsDir, $packageName)
   {
       $translationsFile = $this->getTranslationsFile($locale, $from, $packageTranslationsDir, $packageName);
       if ($translationsFile) {
           Nova::translations($translationsFile);
           return true;
       }
       return false;
   }

load global extra translations into NovaServiceProvider?

Hi,

I would like to use this package to add specific global application translation files.
I want to achieve this to avoid to overwrite nova official translation.

I've created the following file

resources/lang/vendor/myapp/es.json
And I load it into NovaServiceProvider

$this->loadTranslations(__DIR__ . '/../resources/lang/vendor', 'myapp', true);

Language file is loaded but labels are not translated on my resource page
For example, I've got "Country" resource with the following method and strangely when I access to the resource only HTML title is translated. If I append a translation string into the main nova translation file, it works as expected.

   /**
    * Get the displayable label of the resource.
    *
    * @return string
    */ 
    public static function label()
    {
        return __('Countries');
    }

image

What I've missed?

Unnecessary drop of support for Laravel < 9

As far as I can see, the only code difference between 4.0.1 and 3.1.4 is changing the function call from resource_path('lang/...') to lang_path('...')

Is it really necessary to drop the support for (at least) Laravel 8?

My situation:
I'm upgrading Nova 3 -> 4. Upgrade of Laravel 8 -> 9 is planned for the near future, but does not fit my current schedule.
Your multiselect package depends on this one and it has hard Laravel >= 9 dependency.
Thus I'm not able to proceed with the upgrade (without any hacks at least).

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.