aimeos / ai-client-jsonapi

Aimeos frontend JSON API
GNU Lesser General Public License v3.0
28 stars 6 forks source link

Product not found translation text not working #12

Closed amiraghyan99 closed 3 years ago

amiraghyan99 commented 3 years ago

Hi

could you help me for this issue

I need to change "Item with ID \"44\" in \"product.id\" not found" text to Product not found. for this api https://example.loc/test/jsonapi/product?id=44

but I can't find it from where coming this text I tired add this translation in my ext/example/lib/custom/i18n/en.po file and run gettext command but was not changed

msgid "Item with ID \"%2$s\" in \"%1$s\" not found"
msgstr "You will need to upgrade the application to view this product \"%2$s\" in \"%1$s\""
{
"meta": {
"total": 0,
"prefix": null,
"content-baseurl": "http://example.loc"
, "csrf": {
"name": "_token",
"value": "M3bMz4dsfEfvCekaYhUulpxkBnFUiV37rMj"
}
},
"links": {
"self": "https://example.loc/test/jsonapi/product?id=44&page%5Boffset%5D=0"
}
,"errors": [{"title":"Item with ID \"44\" in \"product.id\" not found"}]

}

and for others translations working good

amiraghyan99 commented 3 years ago

I don't know which parameters use for product in msgid maybe for that I can't change this text

aimeos commented 3 years ago

If you use Laravel, use

'i18n' => [
    'en' => [
        'mshop' => [
                'Item with ID \"%2$s\" in \"%1$s\" not found' => ['You will need to upgrade the application to view this product \"%2$s\" in \"%1$s\"']
        ]
    ]
]

The translation domain is "mshop", see also: https://aimeos.org/docs/latest/laravel/customize/#overwrite-translations

amiraghyan99 commented 3 years ago

I tired this way too, but don't help me and I use other domains too , again some yes I am using Laravel

aimeos commented 3 years ago

Did you try to remove the backslashes ()?

amiraghyan99 commented 3 years ago

yes not help again throw new \Aimeos\MShop\Exception( sprintf( 'Item with ID "%2$s" in "%1$s" not found', $key, $id ) );

amiraghyan99 commented 3 years ago

this is my en.po


msgid "Item with ID \"%2$s\" in \"%1$s\" not found"
msgstr "You will need to upgrade the application to view this product"

and my shop.php

'i18n' => [
        'en' => [
            'mshop' => [
                'Item with ID "%2$s" in "%1$s" not found' => ['You will need to upgrade the application to view this product']
            ],
        ]
    ],
amiraghyan99 commented 3 years ago

I run msgfmt --statistics -c -o en en.po command and clear all cache

amiraghyan99 commented 3 years ago

when I change sprintf( 'Item with ID "%2$s" in "%1$s" not found', $key, $id ) this text from Base.php and translate in en.po it work but we can't change Base.php file because it in vendor folder


throw new \Aimeos\MShop\Exception( sprintf( 'example', $key, $id ) );


msgid "example"
msgstr "123456"
{
"meta": {
"total": 0,
"prefix": null,
"content-baseurl": "example.loc"
, "csrf": {
"name": "_token",
"value": "HirneBi5h6Eo4DOVysVRUhFezOOcLYlrLiarchpQ"
}
},
"links": {
"self": "https://example.loc/syaanh/jsonapi/product?id=1&page%5Boffset%5D=0"
}
,"errors": [{"title":"123456"}]

}
amiraghyan99 commented 3 years ago

issue in "%2$s" and "%1$s" because it is dynamic value when I use for ID 1 value and for key product.id values it work

aimeos commented 3 years ago

Guess it's either the % or $ character that makes problems during translation lookup. Maybe you have to escape one or both by \

amiraghyan99 commented 3 years ago

@aimeos

could you change this text to your demo version and share with us if it is work, I tried many options but didn't work

aimeos commented 3 years ago

It didn't work because the values have been replaced in the string before it was translated. We've changed that now so it works if you install:

composer req aimeos/aimeos-core:2021.07.x-dev