GithubHelp home page GithubHelp logo

pimcore-i18n's People

Contributors

alexej-d avatar benwalch avatar blackbitdevs avatar davidhoeck avatar galcf avatar pascalmoser avatar scrummer avatar solverat avatar tomhatzer avatar zodiarc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pimcore-i18n's Issues

Add support for True-Client-IP Header

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes

I have a client which uses akamai cdn, which breaks getting the users ip. Akamai is using a different header 'True-Client-IP'.

Zone Settings: Use fallback for translations

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Use i18n.translations as fallback for i18n.zones.zonexy.config.translations in i18n.yaml

Mostly the translations should be the same in all zones. Therefore a fallback would be useful to avoid redundancies.

i18n_context twig helper for other than current document

Use case: Link to localized document in the current language. For example if you had documents /de/impressum and /en/imprint and want to link to the correct page from the start page /deor /en. /de/impressum and /en/imprint are linked with the Localization Tool

Currently there is the i18n_context twig helper but this can only fetch linked variants of current document (or am I missing something?).
Perhaps we could either add an option to call i18n_context with another document than the current one.
Or even better would be if we introduced a twig helper which you can provide a document object (or its full path) and a locale - and you automatically get the URL for the document in the desired language (based on linked languages of the given document).

Wrong Error Page in Static Route Context

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps to reproduce:

  1. create a static route for an object
  2. in the controller throw a not found exception (e.g. when the object is not published or not found)
  3. disable the debug mode
  4. now the 404 error page set in the Pimcore admin does not work. Exception: I18n context already has been resolved

Improve redirects when country code is not set in user languages

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

I18n is ignoring a user locale without country code (de), when the same locale ist set in Pimcore with country code (de_CH).

Example 1:

User locales: de_CH, en
Pimcore locales: de, en

Current and expected Behavior: i18n redirects to de (working with PR #63)

Example 2:

User locales: de, en
Pimcore locales: de_CH, en

Current behavior: i18n redirects to en (ignoring de_CH)
Expected behavior: Redirect to de_CH because user preferred language should have more priority.

Wrong locale in static routes

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Pimcore Translator has a wrong locale in static routes when country context is missing in language attribute.
Eg. Document locale: de_CH, static route: www.project.ch/de/my-static-route/object-xy

Fix in project:

<?php

namespace App\EventListener;

use I18nBundle\Helper\RequestValidatorHelper;
use I18nBundle\Resolver\PimcoreDocumentResolverInterface;
use Pimcore\Model\Document;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class StaticRouteLocaleListener implements EventSubscriberInterface
{
    protected PimcoreDocumentResolverInterface $pimcoreDocumentResolver;
    protected RequestValidatorHelper $requestValidatorHelper;

    public function __construct(
        PimcoreDocumentResolverInterface $pimcoreDocumentResolver,
        RequestValidatorHelper $requestValidatorHelper)
    {
        $this->pimcoreDocumentResolver = $pimcoreDocumentResolver;
        $this->requestValidatorHelper = $requestValidatorHelper;
    }

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::REQUEST   => [
                ['onKernelRequestLocale', 17],      // before symfony LocaleListener
            ]
        ];
    }

    public function onKernelRequestLocale(RequestEvent $event)
    {
        if ($event->isMainRequest() === false) {
            return;
        }

        $request = $event->getRequest();
        $document = $this->pimcoreDocumentResolver->getDocument($request);

        if (!$document instanceof Document) {
            return;
        }

        if (!$this->requestValidatorHelper->isValidForRedirect($request)) {
            return;
        }

        $documentLocale = $document->getProperty('language');
        $requestSource = $request->attributes->get('pimcore_request_source');

        if ($requestSource === 'staticroute' && !empty($documentLocale) && $request->attributes->get('_locale') !== $documentLocale) {
            $request->attributes->set('_locale', $documentLocale);
        }
    }
}

Dynamic Symfony Route Prefixes

Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? no

In the following case, how would you define a dynamic path prefix instead of matching_route_key? Would it even be possible?

/**
     * @Route("{path}/{title}~pr{object}", name="project-detail", defaults={"path"=""}, requirements={"path"=".*?", "title"="[\w-]+", "object"="\d+"})
     * @Template()
     *
     * @param Request $request
     *
     * @return array
     */
    public function detailAction(Request $request)

Single domain setup with multiple locales

In Pimcore projects we often have a setup similar like this, just like in the pimcore demo:

  • Only one domain, specified in pimcore system settings (no site is used)
  • One specific default language (de in this example), that will be the base for translations
  • The link de points at the root document (id 1) wich will make it the main page for the default language
  • Other languages get their own main pages

image

If we install the bundle in such a projects we run into errors like this. The language is setup properly and defintion of zones are not possible, since we use no sites.
image
image

I've read all the documentation but either I don't understand it or I'm lacking some other important part.


The goal in this setup also is to strip the locale fragment of the url in the default language (domain.com/de/seite1 should be domain.com/seite1).

It seems that this could be possible with i18n:

## Optional Locale in Url
The I18nBundle allows you to have domains without a locale fragment in url. For Example:
- `domain.com/about-us`
- `domain.com/news`
To achieve that you just set the language property to the `domain.com` document which is also a pimcore site.

But at another point we have the following conflicting convention in the docs:

For multi-language sites (e.g. example.org/de and example.org/en): Please ensure that the site document (domain, e.g. example.org) does not have a defined language (Document => Tab "Navigation & Settings" => "Language" Dropdown: Select `None` and save).


Can you please confirm if such setup is possible with i18n or not?

Thanks in advance! 😊

Redirect on object preview

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

I defined a link generator to view the object preview in the Pimcore admin.
The object preview works fine without the i18n bundle but doesn't with it.

That's what I expected:

[302] http://localhost/admin/object/preview?id=4525&time=1632231904801
[200] http://localhost/en/product/funky-pj4525?pimcore_object_preview=4525&_dc=1632231904

That's what I get:

[302] http://localhost/admin/object/preview?id=4525&time=1632231904801
[302] http://localhost/en/product/funky-pj4525?pimcore_object_preview=4525&_dc=1632231904
[200] http://localhost/en/product/funky-pj4525

In this scenario, Pimcore shows an object preview from the database instead of from the session. I suppose that the i18n ignores the pimcore_object_preview parameter.
I'll investigate, I promise!

My i18n_dev.yml

i18n:
    mode: country
    locale_adapter: system
    default_locale: 'en'
    translations: ~
    zones:
        zone1:
            id: 1
            domains:
                - docker
                    - it
                        - error
                    - en
                        - error
            config:
                mode: country
                default_locale: 'en'
                locale_adapter: system
                translations: ~

Respect LinkGenerator

The alternate link generator should check against an available link generator before firing the i18n.path.static_route.alternate event.

Make i18n_redirect cookie security configurable

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Hey there! 👋

Currently the i18n_redirect cookie is stored without secure flag, but with HttpOnly using the Symfony Cookie class. Would it be possible to make this configurable so setting the SameSite flag and the secure flag by a config value?

If so, would you be ok with accepting a PR that adds this functionality? I'd create 2 PRs then, one for 3.x and one for 4.x.

Thank you very much!

Best wishes
Tom

Allow i18n Detection in Pimcore Redirects

Q A
Bug report? yno
Feature request? yes
BC Break report? no
RFC? no

image

Example

Given Structure

Domain: mydomain.com
Document Tree:

  • de
    • kollektion
  • en
    • collection

Example A:

  • Enter host my-old-collection-domain
  • i18n should redirect to mydomain.com/de/kollektion if user is german
  • i18n should redirect to mydomain.com/en/collection if user is english

Example B:

  • Enter host mydomain.com/landingpage
  • i18n should redirect to mydomain.com/de/landingpage if user is german
  • i18n should redirect to mydomain.com/en/landingpage if user is english

Solution

  • Use {i18n_localized_target_page=4} as placeholder target row.
  • Page ID is mandatory
  • Using the document by reference, it's possible to determinate all available linked documents and also providing a proper localized redirect

geoCountry not in decision when no user laguage matched

Q A
Bug report? no
Feature request? yes
BC Break report? yes
RFC? yes

Let's assume the following example scenario

  1. I18n Mode is set to country
  2. Valid Pimcore languages: de-DE, de-CH
  3. Default Pimcore language: de-CH
  4. User is located in DE (IP location) but HTTP_ACCEPT_LANGUAGE is en

Current I18n decision
Decision is invalid because no language matches.
No country detection because of the return in this block: https://github.com/dachcom-digital/pimcore-i18n/blame/820030747632599eb2cde06ceea7d3d8d96575a8/src/I18nBundle/Adapter/Redirector/GeoRedirector.php#L29
I18n redirects to de-CH (Default language fallback)

Possible better decision
I18n redirects to de-DE because the countries match

Allow Zone Configuration

i18n:

    # set mode (~|language|country)
    mode: country

    # define a country adapter (flat|coreshop|custom)
    country_adapter: i18n.country.adapter.flat

    # static route translations
    translations:
        -   url-news:
                de: 'news'
                en: 'neuigkeiten'
                it: 'notizia'
                fr: 'nouveaute'

    # zones are optional
    # if no zones are defined the global configuration applies to all pages
    zones:

        # example 1: complex country / language i81n
        -   id: 1
            name: 'zone 1'
            # domains must be the main domain of page
            domains: ['your-page.eu', 'your-page.cz', 'your-page.de', 'your-page.pl']
            config:
                mode: country
                country_adapter: i18n.country.adapter.coreshop
                translations: ~

        # example 2: only language based i18n
        -   id: 2
            name: 'zone 2'
            domains: ['special-page.com', 'other-domain.jp']
            config:
                mode: language
                country_adapter: ~
                translations: ~
        # example 3: No i18n since the webpage is just a simple page
        -   id: 3
            name: 'zone 3'
            domains: ['boring-page.com']
            config:
                mode: ~
                country_adapter: ~
                translations: ~

Tests

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

nofollow tags

In documents, we're able to add meta elements like this:

 <meta name="robots" content="nofollow" />

Should we implement a setting node to define no follow tags to static routes or even symfony routes?

i18n:
    meta:
        nofollow:
            - 'static_route_name'
            - 'symfony_route_name'

[XLIFF-BUG]Export failed

While exporting XLIFF got this error prompts

{"success":false,"message":"An exception has been thrown during the rendering of a template (\u0022context is not defined\u0022)."}

Timestamp: Tue Mar 26 2019 10:13:58 GMT+0100 (Mitteleuropäische Normalzeit)
Status: 500 | Internal Server Error
URL: /admin/translation/xliff-export
Method: POST
Message: An exception has been thrown during the rendering of a template ("context is not defined").

PLZ fix it as discussed solverat

Support Symfony Routes

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes

Is this something planned or even possible at all? Would be awesome to have nice looking locales for Symfony Routes as well. :)

Session causes non working full page cache

Q A
Bug report? yes

In Pimcore v5, I want to use the full page cache but I need a PHPSESSID cookie. This disables the cache with a message
“X-Pimcore-Output-Cache-Disable-Reason: Session in use”. (Repsonse Header)

If the i18n manager bundle is disables, the cache works properly and no "PHPSESSID" is available.

Is there a possibility to run the cache with this cookie?

Refactor Country / Language Context: Introduce Locale Context, add Redirector Adapter

Locale Adapter

  • remove language_adapter and country_adapter context, introduce locale_adapter
  • remove default_language and default_country setting, introduce default_locale

Redirector Adapter

Implement redirector_adapter which allows to define redirect decisions in a more granular way.
Redirector can be enabled (default) or disabled.

i18n
    registry:
        redirector:
            cookie:
                enabled: false

Available Redirectors

  • cookie redirector (prio 300): If enabled user gets redirected to selected language.
  • geo redirector (prio 200): If enabled user gets redirected based on IP and browser language
  • fallback redirector (prio 100): If enabled user gets redirected based on i18n default_locale setting (per zone) or default locale defined in pimcore settings.

Use Attributes as Keys in Zone Configuration

Currently zones are configured as simple arrays:

zones:
        -
            id: 1
            name: 'zone 1'
            domains:
        -
            id: 2
            name: 'zone 2'
            domains:

when using multiple environments the subconfig gets append instead of merged. Change it to key values:

zones:
       zone1:
            id: 1
            name: 'zone 1'
            domains:
       zone2:
            id: 2
            name: 'zone 2'
            domains:

product-price-rule accepts no decimal places as discount value

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

coreshop 2.2.2, with pimcore 6.6.7

When defining a product-price-rule in admin, (coreshop | price rules | product price rules) no decimals are possible as value. Trying to define 13,51% as discount for products in Action (Discount Percent).
Entered 13,51. After saving/leaving focus of field - it is rounded and written to 14. When entering 13,4 it is rounded to 13
Trying to enter with dot '.' is not possible.

Should be possible to enter value 13,51 without being rounded

Missing site when generating alternate links

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Site is missing by generating alternate links in AlternateDynamicRouteEvent
Exception: No zone site for locale "de_DE" found. Available zone (Id 1) site locales:

Example code to fix the issue (without regards to performance):
I18nBundle\Adapter\PathGenerator\DynamicRoute::buildAlternateRoutesStack()
Bildschirmfoto 2022-10-25 um 10 04 23

Double Domain in hreflang

Q A
Bug report? ?
Feature request? no
BC Break report? no
RFC? no

Hey,

not really sure if this is a bug or a wrong configuration, but i search de documentation and didn't really find a solution.

I got multiple domains, configured as sites in Pimcore.
image

Hreflangs for the homepages are ok:
image

But for subpages the "main domain" is always added:
image

And i have no idea why.

Improve Redirect Document Rendering

In Backend i18n throws a document xy does not have a valid language property! if no valid language property has been found. Redirect documents (like site documents) are not allowed to have a language property otherwise the redirect to the locale context won't work. So instead of an exception we should display a proper message:

bildschirmfoto 2018-04-15 um 17 27 44

Allow parameters for translation config

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Allow yaml parameters for i18n.translations and i18n.zones.zonexy.config.translations.

Example yaml config:

parameters:
    i18n_translations:
        -   key: 'event'
            values:
                de: 'veranstaltung'
                fr: 'evenement'
                en: 'event'

i18n:
    translations: '%i18n_translations%'
    zones:
        zonexy:
            config:
                translations: '%i18n_translations%'

Current Exception:
Invalid type for path "i18n.translations". Expected "array", but got "string"

exception rendering error page

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Site attribute is missing in error page.
Exception in error page: An exception has been thrown during the rendering of a template ("To generate a zone object, you need to assign a valid site if zones are configured. No site assignment found. Maybe there is a typo in your i18n.zones.domains mapping?").

Zones based on language documents

Assume you have only 1 domain and a document structure like /example.org/de/123 and /example.org/en/123. As zones are currently based on domains of sites how is it possible to get a language switch which contains DE and EN? Currently I only can create zone for domain example.org and so the getActiveLanguages() only gets the 1 language - the one which is set for /example.org site.

Allow locale adjustment also on other requests than the master request

Q A
Bug report? yes/no
Feature request? yes
BC Break report? no
RFC? yes

When rendering for example the add to cart partial via {{ render(path('coreshop_cart_add')) }} it is not working because the locale does not get adjusted on child requests. Maybe we could implement a check if it is a frontend request instead of checking if it's a master request.

[bug?] Indonesian language (`hreflang="id"`) not showing

First of all thank you for creating this extension! 👍

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

This is my page:

image

image

image

Setting:

image

However, on both page variants (en and id) the only hreflang links I get is:

<link href="https://pim.lovia.life/en/edu/preschool/in/indonesia" rel="alternate" type="" title="" hreflang="en">

hreflang="id" is never showing, neither is x-default.

(seems like the id document knows about the en one, but the en one is not aware that id exists?)

Pimcore v6.2.0. I18nBundle 3.1.1.

No redirect with Safari browser

I have a site document with the domain www.staging.example.org and the following configuration in my app/config/config.yml:

i18n:
    zones:
        zone_xyz:
            id: 1
            # domains must be the main domain of page
            domains: 
                - "www.staging.example.org"
            config:
                mode: language
                locale_adapter: system
                translations: ~

(Actually I have some more zones for the other site documents but I think this does not matter here)

The site document www.staging.example.org has no set language. Below this document there are documents en and de with the correct languages set.
When I access https://www.staging.example.org in Firefox or Chrome I get redirected to https://www.staging.example.org/de (or /en depending on Accept-Language header) but in Safari I do not get redirected but stay on https://www.staging.example.org. Can you think of a cause for that?

I updated to Pimcore 6.6.9 and i18n dev-master but still no success.

Canonical Links with HrefLang Tags

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Given Scenario

  • Page: https://domain.com/my-page
  • Available Locales: de and en
  • Default Locale: en

Current Result

Default Request

GET https://domain.com/my-page/en
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="x-default">
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="en">
<link href="https://domain.com/my-page/de" rel="alternate" hreflang="de">

Query Request

GET https://domain.com/my-page/en?page=2
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="x-default">
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="en">
<link href="https://domain.com/my-page/de" rel="alternate" hreflang="de">

Desired Result

Default Request

GET https://domain.com/my-page/en
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="x-default">
<link href="https://domain.com/my-page/en" rel="alternate" hreflang="en">
<link href="https://domain.com/my-page/de" rel="alternate" hreflang="de">

Query Request

GET https://domain.com/my-page/en?page=2
<link rel="canonical" href="https://domain.com/my-page/en">

To Define

  • Make this option configurable (i18n.canonical_query_urls: true)
  • What about pretty Urls (e.g. https://domain.com/mypage/en/page/1)?

Should x-default and alternate links be pushed via HTTP2?

Q A
Bug report? yes?
Feature request? no
BC Break report? no
RFC? no

It looks like the generated x-default and alternate links are pushed as weblinks when weblinks and HTTP2 are activated. I do not think this is on purpose. These two lines src/I18nBundle/EventListener/Frontend/HeadLinkListener.php#L72 and src/I18nBundle/EventListener/Frontend/HeadLinkListener.php#L76 should add 'webLink' => false to the extra param.

Would you like me to open a PR?

HeadLink listener and Href-lang

Hi,
Why hreflang tags are added only in country mode?

I have only 1 zone and my language strategy is maindomain.com/en maindomain.com/it etc..
in language mode.

my zone config:

i18n:

# set mode (language|country)
mode: language

# define a language adapter (system|custom)
language_adapter: i18n.adapter.language.system

# define a country adapter (system|coreshop|custom)
country_adapter: i18n.adapter.country.system

# define a global prefix (like de-global or de-int)
global_prefix: ~

# static route translations
translations: ~

zones:

    # zone 1: language and country
    -
        id: 1
        name: 'zone 1'
        domains:
            - 'www.marcolin.vag'
        config:
            mode: language
            language_adapter: i18n.adapter.language.system
            country_adapter: ~
            global_prefix: ~
            translations: ~

HeadLinkListener.php

public function onKernelRequest(GetResponseEvent $event)
    {
        ......

        if ($this->zoneManager->getCurrentZoneInfo('mode') !== 'country') {
            return;
        }

        $document = $this->documentResolverService->getDocument($request);
        $hrefLinks = $this->pathGeneratorManager->getPathGenerator()->getUrls($document);

        //add x-default to main page!
        $xDefaultUrl = $this->getXDefaultLink($hrefLinks);

        if (!is_null($xDefaultUrl)) {
            $this->headLink->appendAlternate($this->generateHrefLink($xDefaultUrl), FALSE, FALSE, ['hreflang' => 'x-default']);
        }

        foreach ($hrefLinks as $route) {
            $this->headLink->appendAlternate($this->generateHrefLink($route['url']), FALSE, FALSE, ['hreflang' => $route['hrefLang']]);
        }
    }

Regards,

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.