[MULTISITE-120] Locale aware MultiSiteRegexpVirtualURIMapping Created: 30/Nov/17  Updated: 18/May/22

Status: Open
Project: Magnolia Multisite Module
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Samuel Zihlmann Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Cloners
relation
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Visible to:
Peter Mohn
Team: DeveloperX

 Description   

With MultiSiteRegexpVirtualURIMapping, the URI is always mapped to the default language, which ist not desirable in a multilingual environment and renders MultiSiteRegexpVirtualURIMapping effectively useless in many cases.

An example:

  • We used MultiSiteRegexpVirtualURIMapping to map /path/username/objectname to /path?username=username&objectname=objectname
  • The desired functionality would be that /fr/path/username/objectname is mapped to /fr/path?username=username&objectname=objectname, but this is not the case because the locale is removed from the URI before the mapping is performed

This seems like a very basic feature that should be provided by Magnolia itself. We built the following workaround for our project:

public class LocaleAwareMultiSiteRegexpVirtualURIMapping extends MultiSiteRegexpVirtualURIMapping {
    
    @Inject
    public LocaleAwareMultiSiteRegexpVirtualURIMapping(SiteProvider siteProvider) {
        super(siteProvider);
    }

    @Override
    public MappingResult mapURI(final String uri, String queryString) {
        MappingResult r = super.mapURI(uri, queryString);
        if (r != null) {
            String replaced = r.getToURI().replace("{locale}", getLocale());
            r.setToURI(replaced);
        }
        return r;
    }
    
    private String getLocale() {
        I18nContentSupport i18nSupport = Components.getComponent(I18nContentSupport.class);
        return i18nSupport.getLocale().getLanguage();
    }

}

This works fine for now, but it would be great if such a feature could be incorporated into Magnolia in a future version.


Generated at Mon Feb 12 06:06:35 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.