Code Monkey home page Code Monkey logo

Comments (6)

milewski avatar milewski commented on May 30, 2024

First, you need to enable it in the configuration 'translate_title' => true,

and then every title will be auto-translated,

'navigation' => [
        [
            'title' => 'Resource Title', // this will auto transform into __('Resource Title')
             .....
            'groups' => [
                [
                    'title' => 'Assets',  /// and __('Assets')
                     ....                  
                ]
            ]
        ]
    ]

however you resource class still needs to be translated through the static label method:

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

The reason why you can't just call __('Title') directly inside the config file is that laravel will cache the files, and it will permanently be cached in a single language... so switching language does not work without always cleaning your config cache

from collapsible-resource-manager.

shazibrazzaq avatar shazibrazzaq commented on May 30, 2024

yes i am doing exactly like you suggested.

I meant on this function in your file CollapsibleResourceManager.php

private function translateKey(?string $key): string
    {

        if ($key && config('collapsible-resource-manager.translate_title', false)) {

            return trans($key);

        }

        return $key;

    }

If i replace trans with __() it works, otherwise it doesn't translate. I think we need to replace this function in the function so it works for nova. If there anything else i am missing please let me know.

from collapsible-resource-manager.

milewski avatar milewski commented on May 30, 2024

I'm not sure what's going on, if you see the __() function it is just calling trans() behind the scenes

if (! function_exists('__')) {
    /**
     * Translate the given message.
     *
     * @param  string|null  $key
     * @param  array  $replace
     * @param  string|null  $locale
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
     */
    function __($key = null, $replace = [], $locale = null)
    {
        if (is_null($key)) {
            return $key;
        }

        return trans($key, $replace, $locale);
    }
}

And just to confirm are you updating the right file?

image

from collapsible-resource-manager.

shazibrazzaq avatar shazibrazzaq commented on May 30, 2024

image

i tried all three paths issue is still there.. but as soon i replace trans function with __() it works.

In nova docs they have mentioned to use __() function here is the reference.

https://nova.laravel.com/docs/2.0/customization/localization.html#overview

My suggestion is we can change to __() instead of trans() if it's ok with you. And i can update from code otherwise i think i can extend class and override the function. But it will help others if we change in the package class itself.

from collapsible-resource-manager.

milewski avatar milewski commented on May 30, 2024

I just pushed a new version v0.1.7 that uses __() instead of trans see if works for you.

This issue is very odd because I'm personally using this package and having multi-language in Chinese/English and it works fine with trans(), perhaps it's your nova version? currently im 2.4.0 and laravel 6

from collapsible-resource-manager.

shazibrazzaq avatar shazibrazzaq commented on May 30, 2024

Thanks a lot, it worked for me.

Yes i also find it strange i have nova 2.4.0 too only difference is laravel 5.8.* but still it should be working it's for you.

Anyway thanks it worked for me now.

from collapsible-resource-manager.

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.