ryanmitchell / statamic-translation-manager

MIT License
8 stars 6 forks source link

Strange mix of translated and non-translated CP items #16

Closed jensolafkoch closed 8 months ago

jensolafkoch commented 8 months ago

Expected behavior: Statamic CP should show intended locale for labels and nav as in config/app.php defined.

Actual behavior: Mixture of localized and non-localized entries.

Reproduce steps: Just install statamic-translation-manager into a working multi-site app.

Version: Latest. 1.2

Additional Information:

I thought it was a Statamic issue and opened and closed a discussion there which shows the CP and my locale config:

https://github.com/statamic/cms/discussions/9305

ryanmitchell commented 8 months ago

Im not sure I understand the issue - this plugin simply gives you a way of managing your lang files. Its not changing anything until you tell it to.

Any language strings in Statamic are translated by default to the locale of the logged in user.

jensolafkoch commented 8 months ago

Well, the effect of the language mixture is shown in the screenshot here: https://github.com/statamic/cms/discussions/9305

That effect happens only when the manager is installed. A soon as I remove it, everything is okay. I change nothing else!

So when your addon is installed, the usual locale definitions seem to be strangely overridden or broken. That might be a Statamic problem, but it depends (in a boolean way) just on whether your add-on is installed or not.

Sorry, I don't know how to better explain it than in the linked discussion - the effect itself is quite visible.

ryanmitchell commented 8 months ago

Is your user locale in the CP the same - also DE? I've double checked the code here and nothing actually changes the locale.

Is it a vanilla statamic install or are there any other add-ons?

jensolafkoch commented 8 months ago

The CP settings had no overrides, neither for default, admin, editor or user, so only the values from app.php and sites.php apply.

I have these packages, nothing unusual here, I guess.

"jensolafkoch/ukie": "dev-dev" is a private add-on I'm working on, but the behaviour is the same when it is removed completely.

    "require": {
        "php": "^8.2",
        "guzzlehttp/guzzle": "^7.0.1",
        "jensolafkoch/ukie": "dev-dev",
        "laravel/framework": "^10.0",
        "laravel/tinker": "^2.5",
        "spatie/laravel-ray": "^1.29",
        "statamic/cms": "^4.43"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.5",
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ignition": "^2.0"
    },

Well, the problem is not a changed locale per se. The problem, as afar as I understand it, is that the locale is correctly detected as being "de", but that the string from the lang file "de.json" in the Statamic vendor directory are not loaded anymore, only the strings from the PHP files in the de lang directory.

And this only happens when the translation manager is installed. Could it be one of your dependencies then breaking the Statamic core behaviour?

ryanmitchell commented 8 months ago

So we're loading translations here, but under our own namespace: https://github.com/ryanmitchell/statamic-translation-manager/blob/b1bbc2899895980c2581db42c8f4362b6e139185/src/ServiceProvider.php#L26

Does commenting out that line do anything for you?

jensolafkoch commented 8 months ago

Same behavior after commenting that out ... :-(

ryanmitchell commented 8 months ago

I'm at a loss to explain it then - thats the only part of this add-on that touches laravel's loading of languages (and it touches it in the expected ways).

One of the dependencies loads in https://github.com/illuminate/translation - maybe something in it is causing this. But i'm guessing a bit.

jensolafkoch commented 8 months ago

Thanks, maybe at some point the problem just disappears. :-) And of course I can live with mixed languages in my own apps' CP. I'm going to install it just as a dev dependency.

I also tried to dive a bit deeper in the loading of the translations but to no avail ...

I checked the jsonPath array which showed

[
    0 => 'D:\\dev\\apps\\stat-ukie\\vendor\\ryanmitchell\\statamic-translation-manager\\src/../resources/lang',
    1 => 'D:\\dev\\apps\\stat-ukie\\vendor\\statamic\\cms\\src\\Providers/../../resources/lang',
]

I reversed the loading order too just to check, but nothing changes.

Weird ... :-)

ryanmitchell commented 8 months ago

Yeah but the one from this package should disappear if you comment out the line i referenced.