-
Improvement
-
Resolution: Unresolved
-
Neutral
-
None
-
None
-
None
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.
Acceptance criteria