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

Localization does not work in some places #2515

Closed
steveooo1 opened this issue Apr 15, 2020 · 17 comments
Closed

Localization does not work in some places #2515

steveooo1 opened this issue Apr 15, 2020 · 17 comments

Comments

@steveooo1
Copy link

  • Laravel Version: 7
  • Nova Version: 3.3.2
  • PHP Version: 7.4.4

Description:

When trying to localize things like the Resource label()or singularLabel(), by using return __('Users'), it won't translate. Also in the sidebar: "Resources" and "Dashboard" does not translate... I have a correct de.json in resources/lang/vendor/nova/de.json and I load it via this:

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Nova::serving(function (ServingNova $event) {
            Nova::translations(
                resource_path('lang/vendor/nova/'.app()->getLocale().'.json')
            );
        });
    }

app()->getLocale() return de (correct!).

The translations for the primary blue buttons like "Create :resource" does work fine!

@jbrooksuk
Copy link
Member

Nova::translations is used to load translations into the Javascript payload. __() is a Laravel method which will be looking for translations in: resources/lang/de.json.

@steveooo1
Copy link
Author

Well, then the docs about this are wrong. There it shows return __('ResourceNameFoo') and it says:

Your application will contain a resources/lang/vendor/nova translation directory. Within this directory, you may customize the en.json file or create a new JSON translation file for your language.

So when do I have to write my translations into resources/lang/de.json and when into resources/lang/vendor/nova/de.json?

I am using the coderello/laravel-nova-lang package and the generated file get's put into resources/lang/vendor/nova/de.json. This works partially. E.g. it works with the blue primary button in the UI that says "Create :resource". This text snippets is used inside Vue but also inside PHP, so I don't get the difference.

@elasti-co
Copy link

I have the same problem. Some standard labels like Search btn or Action btns are translated from my ru.json.
But Resources names — don't. No idea of how to fix the issue.

@martio
Copy link

martio commented Nov 9, 2020

I have the same problem.

@bastihilger
Copy link

I am commenting to say I have the same problem in Nova v3.16.3.

de.json is in resources/lang/vendor/nova/de.json.

But only parts get translated:

image

@bastihilger
Copy link

Follow-up: it seems the JS translations are at the moment read from resources/lang/de.json. When you put something there, that will be used. This seems wrong, though, doesn't it? Because that is where the general Laravel de.json belongs.

This seems like a but to me. I will try to find out if I can PR a solution.

@bastihilger
Copy link

As I am digging deeper ist seems it is the other way around - the JS translations are read correctly, but those wrong translations are NOT generated by Vue files but before in PHP Classes.

@bastihilger
Copy link

Sorry to those following this issue - the problem was actually happening when I included one of my own composer packages that was also dealing with some Nova stuff. Everything works fine using a vanilla Nova installation.

@monaye
Copy link

monaye commented Jan 23, 2021

@manogi Did you find out why your composer package is causing this issue. I am seeing the same issue and I also have a custom nova composer package but can't think of anything causing this...

@bastihilger
Copy link

@monaye This is now some time ago, so I'm not sure. I do think one of the problem was that the Vue components did not pick up on the translations from the json files. The thing is that I switched to using php translation files and use them like it is described here in the Laravel docs, because this way seems to work nicely out of the box.

@monaye
Copy link

monaye commented Jan 25, 2021

@martio thank you. I saw same issue and workaround is reported here as well #2505. Looks like someone needs to dig deeper to find out why this is happening... The issue just appeared to me after the upgrade, so should be related to some code changes.

@crynobone
Copy link
Member

crynobone commented Jan 26, 2021

If anyone still having problem with this please create a new issue instead of an old one as I just tested this today and seem fine.

A full reproducing code example such the one under https://github.com/nova-issues would be great to understand the issue on your use case.

@aliwesome
Copy link

I have same issue.

@yammycode
Copy link

I have same issue too. Quick fix: just copy your nova lang file into /resources/lang folder.

@afshiney
Copy link

afshiney commented Aug 7, 2021

As mentioned above a simple workaround could be to just create a symlink between desired json lang file into
/resources/lang directory

ln -s /<project-root-directory>/resources/lang/vendor/nova/fa.json ./resources/lang/fa.json

@mostafaznv
Copy link

As mentioned above a simple workaround could be to just create a symlink between desired json lang file into
/resources/lang directory

ln -s /<project-root-directory>/resources/lang/vendor/nova/fa.json ./resources/lang/fa.json

You can do this with php artisan storage:link

filesystems.php

'links' => [
        public_path('storage')        => storage_path('app/public'),
        resource_path('lang/fa.json') => resource_path('lang/vendor/nova/fa.json'),
],

@bogusbd
Copy link

bogusbd commented May 10, 2023

I have same "issue" :

  • Laravel: 9-10
  • Nova: 4

Translate file path : resources/lang/vendor/nova/**/admin.php

With the following content:

<?php

return [
    'Some label'=> 'Translated text',
];

Can be used as follows:

//  please pay attention to the symbols :: and spaces
Text::make(__('nova::admin.Some label'), 'name')

It would be great to add the solutions from this thread to the official Nova documentation.

@laravel laravel locked and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests