KnpLabs / DoctrineBehaviors

Doctrine2 behavior traits that help handling Blameable, Loggable, Sluggable, SoftDeletable, Uuidable, Timestampable, Translatable, Tree behavior
http://knplabs.com
MIT License
911 stars 287 forks source link

How to switch locale on request? #685

Closed Kerrialn closed 2 years ago

Kerrialn commented 2 years ago

is it possible to switch locale on request?

I have tried sending it in the request as a parameter to no effect, I also added a SearchFilter to the entity, didn’t work either. I tested it like so, with multiple parameter variations (translations.currentLocale, currentLocale): /api/tags.json?locale=cz all requests, returns all results, seemingly ignoring the locale filter.

example of the request results:

[
    {
        "id": "0d998499-4910-4011-8cbb-23a527a063a8",
        "isMain": false,
        "processes": [
            "/api/processes/8e07d9df-67ba-4c42-a66e-0adbbdf644b6"
        ],
        "translations": {
            "cz": {
                "id": 8,
                "title": "plech",
                "translatable": "/api/tags/0d998499-4910-4011-8cbb-23a527a063a8",
                "locale": "cz",
                "empty": false
            },
            "en": {
                "id": 7,
                "title": "metal sheet",
                "translatable": "/api/tags/0d998499-4910-4011-8cbb-23a527a063a8",
                "locale": "en",
                "empty": false
            }
        },
        "newTranslations": [],
        "currentLocale": "en",
        "defaultLocale": "en",
        "title": "metal sheet",
        "translationEntityClass": "App\\Entity\\TagTranslation"
    },
    {
        "id": "12abd447-f57a-40ba-b4ac-1e9a12776c7b",
        "isMain": false,
        "processes": [
            "/api/processes/8e07d9df-67ba-4c42-a66e-0adbbdf644b6"
        ],
        "translations": {
            "cz": {
                "id": 6,
                "title": "šrouby",
                "translatable": "/api/tags/12abd447-f57a-40ba-b4ac-1e9a12776c7b",
                "locale": "cz",
                "empty": false
            },
            "en": {
                "id": 5,
                "title": "screws",
                "translatable": "/api/tags/12abd447-f57a-40ba-b4ac-1e9a12776c7b",
                "locale": "en",
                "empty": false
            }
        },
        "newTranslations": [],
        "currentLocale": "en",
        "defaultLocale": "en",
        "title": "screws",
        "translationEntityClass": "App\\Entity\\TagTranslation"
    },
    {
        "id": "339af7d5-2dac-493b-b392-1d0510b2b300",
        "isMain": true,
        "processes": [
            "/api/processes/8e07d9df-67ba-4c42-a66e-0adbbdf644b6"
        ],
        "translations": {
            "cz": {
                "id": 2,
                "title": "kladivo",
                "translatable": "/api/tags/339af7d5-2dac-493b-b392-1d0510b2b300",
                "locale": "cz",
                "empty": false
            },
            "en": {
                "id": 1,
                "title": "hammer",
                "translatable": "/api/tags/339af7d5-2dac-493b-b392-1d0510b2b300",
                "locale": "en",
                "empty": false
            }
        },
        "newTranslations": [],
        "currentLocale": "en",
        "defaultLocale": "en",
        "title": "hammer",
        "translationEntityClass": "App\\Entity\\TagTranslation"
    }
]